Skip to content

Commit

Permalink
Add str method to ActivePhase (#975)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #975

Differential Revision: D70127457
  • Loading branch information
diego-urgell authored and facebook-github-bot committed Feb 24, 2025
1 parent 2e6cd59 commit b8756a4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/framework/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ def test_active_phase_into_phase(self) -> None:
predict_phase = ActivePhase.PREDICT
self.assertEqual(predict_phase.into_phase(), Phase.PREDICT)

def test_actiive_phase_str(self) -> None:
active_phase = ActivePhase.TRAIN
self.assertEqual(str(active_phase), "train")

eval_phase = ActivePhase.EVALUATE
self.assertEqual(str(eval_phase), "eval")

predict_phase = ActivePhase.PREDICT
self.assertEqual(str(predict_phase), "predict")

def test_set_evaluate_every_n_steps_or_epochs(self) -> None:
state = PhaseState(dataloader=[], evaluate_every_n_steps=2)
state.evaluate_every_n_steps = None
Expand Down
10 changes: 10 additions & 0 deletions torchtnt/framework/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ def into_phase(self) -> Phase:
else:
raise AssertionError("Should match an ActivePhase")

def __str__(self) -> str:
if self == ActivePhase.TRAIN:
return "train"
elif self == ActivePhase.EVALUATE:
return "eval"
elif self == ActivePhase.PREDICT:
return "predict"
else:
raise AssertionError("Should match an ActivePhase")


class PhaseState(Generic[TData, TStepOutput]):
"""State for each phase (train, eval, predict).
Expand Down

0 comments on commit b8756a4

Please sign in to comment.