Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default value for max_steps in _is_epoch_done util #497

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/framework/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ def test_is_epoch_done(self) -> None:
)

self.assertTrue(_is_epoch_done(p, max_steps_per_epoch=5, max_steps=200))
self.assertTrue(_is_epoch_done(p, max_steps_per_epoch=5, max_steps=None))
self.assertTrue(_is_epoch_done(p, max_steps_per_epoch=5))
self.assertTrue(_is_epoch_done(p, max_steps_per_epoch=100, max_steps=100))
self.assertTrue(_is_epoch_done(p, max_steps_per_epoch=None, max_steps=100))

self.assertFalse(_is_epoch_done(p, max_steps_per_epoch=6, max_steps=200))
self.assertFalse(_is_epoch_done(p, max_steps_per_epoch=None, max_steps=200))
self.assertFalse(_is_epoch_done(p, max_steps_per_epoch=6, max_steps=None))
self.assertFalse(_is_epoch_done(p, max_steps_per_epoch=None, max_steps=None))
self.assertFalse(_is_epoch_done(p, max_steps_per_epoch=6))
self.assertFalse(_is_epoch_done(p, max_steps_per_epoch=None))

@patch("torchtnt.framework.utils.record_function")
def test_get_timing_context(self, mock_record_function) -> None:
Expand Down
1 change: 0 additions & 1 deletion torchtnt/framework/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ def _evaluate_impl(
or _is_epoch_done(
eval_unit.eval_progress,
eval_state.max_steps_per_epoch,
eval_state.max_steps,
)
):
try:
Expand Down
1 change: 0 additions & 1 deletion torchtnt/framework/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ def _predict_impl(
or _is_epoch_done(
predict_unit.predict_progress,
predict_state.max_steps_per_epoch,
predict_state.max_steps,
)
):
try:
Expand Down
4 changes: 3 additions & 1 deletion torchtnt/framework/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def _is_done(


def _is_epoch_done(
progress: Progress, max_steps_per_epoch: Optional[int], max_steps: Optional[int]
progress: Progress,
max_steps_per_epoch: Optional[int],
max_steps: Optional[int] = None,
) -> bool:
return (max_steps is not None and progress.num_steps_completed >= max_steps) or (
max_steps_per_epoch is not None
Expand Down