Spaces:
Running
Running
Commit Β·
28e7cd7
1
Parent(s): 2c70945
Update for Colab T4 and fix plotting logic
Browse files245 unmodified lines246247248249250251252253254255256257258259260261249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327245 unmodified lines
trainer.train()
# ββ Step 7.5: Persist logs + auto-generate plots βββββββββββfrom training_logging import save_trl_training_artifacts
run_id = datetime.utcnow().strftime("%Y%m%d_%H%M%S")artifact_paths = save_trl_training_artifacts( log_history=trainer.state.log_history, output_dir="./results/training_logs", run_name=f"grpo_fleet_{run_id}",)print("\nSaved training artifacts:")for key, value in artifact_paths.items(): if value: print(f" - {key}: {value}")# ββ Step 7.5: Auto-generate plots from log history ββββββββββimport matplotlib.pyplot as pltimport jsonimport osfrom datetime import datetime
os.makedirs("./results", exist_ok=True)history = trainer.state.log_history
steps = []rewards = []losses = []
for log in history: if "step" in log: s = log["step"] if "reward" in log: steps.append(s) rewards.append(log["reward"]) if "loss" in log: # Match step for loss if s not in steps: steps.append(s) # Find the index of this step idx = steps.index(s) # Extend lists if necessary while len(losses) <= idx: losses.append(None) losses[idx] = log["loss"]
# Clean up lists to be same length for plottingplot_steps = []plot_rewards = []plot_losses = []for i in range(len(steps)): if i < len(rewards) and i < len(losses) and rewards[i] is not None and losses[i] is not None: plot_steps.append(steps[i]) plot_rewards.append(rewards[i]) plot_losses.append(losses[i])
if plot_steps: # 1. Plot Reward Curve plt.figure(figsize=(10, 5)) plt.plot(plot_steps, plot_rewards, label="Mean Reward", color="#00e676", linewidth=2) plt.axhline(y=0.90, color="r", linestyle="--", label="Target (>0.90)") plt.title("Libratio Fleet: GRPO Reward Curve (500 steps)") plt.xlabel("Training Steps") plt.ylabel("Reward Score") plt.grid(True, alpha=0.3) plt.legend() reward_path = "./results/reward_curve_final.png" plt.savefig(reward_path, dpi=300, bbox_inches="tight") plt.close()
# 2. Plot Loss Curve plt.figure(figsize=(10, 5)) plt.plot(plot_steps, plot_losses, label="Training Loss", color="#ff1744", linewidth=2) plt.title("Libratio Fleet: GRPO Loss Curve (500 steps)") plt.xlabel("Training Steps") plt.ylabel("Loss") plt.grid(True, alpha=0.3) plt.legend() loss_path = "./results/loss_curve_final.png" plt.savefig(loss_path, dpi=300, bbox_inches="tight") plt.close()
# 3. Save raw JSON data with open("./results/training_logs.json", "w") as f: json.dump(history, f, indent=2)
print(f"\nSaved training artifacts:") print(f" - Reward Curve: {reward_path}") print(f" - Loss Curve: {loss_path}") print(f" - Raw Logs: ./results/training_logs.json")else: print("\n[WARNING] Not enough logging data to generate plots. Check 'logging_steps' in GRPOConfig.")
# ββ Step 8: Save results βββββββββββββββββββββββββββββββββββtrainer.save_model(OUT_DIR)colab_qlora_grpo_fleet.py+76-13