# %% Cell 8: START TRAINING
print(f"{'='*60}")
print("STARTING TRAINING")
print(f"{'='*60}")
print(f"  Conversations : {len(dataset):,}")
print(f"  Epochs        : {EPOCHS}")
print(f"  Batch         : {BATCH_SIZE} (eff: {BATCH_SIZE * GRAD_ACCUM})")
print(f"  Context       : {MAX_SEQ_LENGTH}")
print(f"  LoRA          : r={LORA_R}")
print(f"  LR            : {LR}")
print(f"  Expected time : ~{total_steps / 8 / 3600:.1f} hours")
print(f"{'='*60}")

trainer.train()

print("\n✅ Training complete!")
final_loss = trainer.state.log_history[-1].get('loss', 'N/A')
print(f"Final loss: {final_loss}")
print("\n→ Run Cell 9 to save the adapter.")
