Description
If training runs fewer steps than `logging_steps` (e.g. `max_steps=1, logging_steps=10`), `trainer.state.log_history` contains no entries with a `"loss"` key. The resulting `loss_history` is an empty list.
Multiple places crash on empty `loss_history`:
- Notebook cells: `result.loss_history[-1]` -> IndexError
- CLI (cli.py:41): `result.metrics.get('train_loss', 'N/A')` is fine, but notebook cell 15 does `result.loss_history[0]` and `result.loss_history[-1]`
- train_result.json: Contains `"loss_history": []` which makes `plt.plot([])` produce a blank chart with no warning
Fix
Guard all `loss_history` accesses with empty-list checks. Provide a fallback when no loss entries exist.
Description
If training runs fewer steps than `logging_steps` (e.g. `max_steps=1, logging_steps=10`), `trainer.state.log_history` contains no entries with a `"loss"` key. The resulting `loss_history` is an empty list.
Multiple places crash on empty `loss_history`:
Fix
Guard all `loss_history` accesses with empty-list checks. Provide a fallback when no loss entries exist.