Skip to content

Bug: empty loss_history crashes CLI and notebooks with IndexError #35

@sacredvoid

Description

@sacredvoid

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`:

  1. Notebook cells: `result.loss_history[-1]` -> IndexError
  2. 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]`
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions