# ==========================================
# CELL 10: OPTIONAL - MERGE LORA INTO BASE MODEL
# ==========================================
# Only run if you have enough VRAM (needs ~12GB for 5B, ~24GB for 12B)
# If this fails, skip it. You can still use the adapter for inference.

try:
    merged_path = os.path.join(OUTPUT_DIR, "merged_16bit")
    model.save_pretrained_merged(merged_path, tokenizer, save_method="merged_16bit")
    print(f"Merged model saved to: {merged_path}")
    print("This is a standalone model. No adapter needed for inference.")
except RuntimeError as e:
    print(f"Merge skipped (likely OOM): {e}")
    print("You can still use the adapter + base model for inference.")
    print("Most users don't need to merge. The adapter is fully functional.")

print("\nCell 10 complete. Run cell_11_test.py to test your model!")
