Skip to content

Commit

Permalink
Add setter for epoch in iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
b-chu committed Jun 17, 2024
1 parent 3859366 commit d68664e
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions composer/core/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,13 +525,8 @@ def __init__(
raise ValueError(f'The `token` argument has units of {token.unit}; not {TimeUnit.TOKEN}.')
self._token = token

epoch_in_iteration = Time.from_input(epoch_in_iteration, TimeUnit.EPOCH)
if epoch_in_iteration.unit != TimeUnit.EPOCH:
raise ValueError((
f'The `epoch_in_iteration` argument has units of {epoch_in_iteration.unit}; '
f'not {TimeUnit.EPOCH}.'
))
self._epoch_in_iteration = epoch_in_iteration
self._epoch_in_iteration = None
self.epoch_in_iteration = epoch_in_iteration

token_in_iteration = Time.from_input(token_in_iteration, TimeUnit.TOKEN)
if token_in_iteration.unit != TimeUnit.TOKEN:
Expand Down Expand Up @@ -619,7 +614,7 @@ def load_state_dict(self, state: dict[str, Any]) -> None:
if 'iteration' in state:
self._iteration = Time(state['iteration'], TimeUnit.ITERATION)
if 'epoch_in_iteration' in state:
self._epoch_in_iteration = Time(state['epoch_in_iteration'], TimeUnit.EPOCH)
self.epoch_in_iteration = Time(state['epoch_in_iteration'], TimeUnit.EPOCH)
if 'token_in_iteration' in state:
self._token_in_iteration = Time(state['token_in_iteration'], TimeUnit.TOKEN)
if 'iteration_wct' in state:
Expand Down Expand Up @@ -655,6 +650,20 @@ def epoch_in_iteration(self) -> Time[int]:
"""The epoch count in the current iteration (resets at 0 at the beginning of every iteration)."""
return self._epoch_in_iteration

@epoch_in_iteration.setter
def epoch_in_iteration(
self,
epoch_in_iteration: Union[int, Time[int]] # pyright: ignore[reportPropertyTypeMismatch]
):
"""Sets epoch count in the current iteration."""
epoch_in_iteration = Time.from_input(epoch_in_iteration, TimeUnit.EPOCH)
if epoch_in_iteration.unit != TimeUnit.EPOCH:
raise ValueError((
f'The `epoch_in_iteration` argument has units of {epoch_in_iteration.unit}; '
f'not {TimeUnit.EPOCH}.'
))
self._epoch_in_iteration = epoch_in_iteration

@property
def token_in_iteration(self) -> Time[int]:
"""The token count in the current iteration (resets at 0 at the beginning of every iteration)."""
Expand Down

0 comments on commit d68664e

Please sign in to comment.