Skip to content

Critical: val_metrics unbound when checkpoint_frequency != validation_frequency — UnboundLocalError in training loop #50

Description

@bradsmithmba

Summary

val_metrics is only assigned inside if epoch % self.config.validation_frequency == 0. The periodic checkpoint branch references val_metrics in a ternary. When checkpoint_frequency < validation_frequency, the first checkpoint epoch will raise UnboundLocalError: local variable 'val_metrics' referenced before assignment, crashing training.

Evidence

src/training/trainer.py line 356: val_metrics = self.validate(...) — only assigned on validation epochs.
src/training/trainer.py line 398:

self.save_checkpoint(f'checkpoint_epoch_{epoch}.pth', epoch,
    val_metrics if epoch % self.config.validation_frequency == 0 else None)

val_metrics in the ternary condition is unbound on any epoch that is a checkpoint epoch but not a validation epoch.

Fix

Initialize val_metrics = None before the training loop, or inline the condition: always pass None as metrics unless this epoch also ran validation.

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