Hands-on Quiz: Fine-Tuning & RLHF
Test your practical skills in fine-tuning datasets, LoRA hyperparameter configuration, and loss evaluation.
Challenge 1: LoRA Parameter Calculator
Given an input layer dimension $d=4096$, output layer dimension $k=4096$, and rank $r=16$, calculate:
- The total trainable parameters in the LoRA adapter ($B \cdot A$).
- The percentage parameter reduction compared to full fine-tuning of this layer.
def calculate_lora_efficiency(d: int, k: int, r: int):
# Your calculation here
pass
View Solution
def calculate_lora_efficiency(d: int, k: int, r: int):
full_params = d * k
lora_params = (d * r) + (r * k)
reduction_pct = (1.0 - (lora_params / full_params)) * 100.0
return {
"lora_params": lora_params,
"full_params": full_params,
"reduction_percentage": round(reduction_pct, 2)
}
# Test:
res = calculate_lora_efficiency(4096, 4096, 16)
print(res)
# {'lora params': 131072, 'full params': 16777216, 'reduction percentage': 99.22}
Challenge 2: ChatML Message Validator
Write a Python function that verifies whether an individual conversation dictionary contains valid roles in chronological alternating order (system -> user -> assistant).
View Solution
def is_valid_chatml(conversation: list[dict]) -> bool:
if not conversation:
return False
expected_next = ["system", "user"]
for msg in conversation:
role = msg.get("role")
if role not in expected_next:
return False
if role == "system":
expected_next = ["user"]
elif role == "user":
expected_next = ["assistant"]
elif role == "assistant":
expected_next = ["user"]
# Conversation must end with assistant response
return conversation[-1].get("role") == "assistant"