Skip to content

Make iter persistent for AdagradW #4147

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,7 @@ def __init__( # noqa C901
self._max_counter_update_freq: int = -1
# Extract parameters from CounterBasedRegularizationDefinition or CowClipDefinition
# which are passed as entries for OptimizerArgs
self._used_rowwise_adagrad_with_adagradw: bool = False
if self._used_rowwise_adagrad_with_counter:
if self.weight_decay_mode == WeightDecayMode.COUNTER:
self._max_counter_update_freq = (
Expand All @@ -1131,6 +1132,9 @@ def __init__( # noqa C901
counter_based_regularization.counter_weight_decay_mode
)
counter_halflife = counter_based_regularization.counter_halflife
self._used_rowwise_adagrad_with_adagradw = (
opt_arg_weight_decay_mode == CounterWeightDecayMode.ADAGRADW
)
else:
opt_arg_weight_decay_mode = (
cowclip_regularization.counter_weight_decay_mode
Expand Down Expand Up @@ -1359,6 +1363,7 @@ def __init__( # noqa C901
OptimType.EMAINPLACE_ROWWISE_ADAGRAD,
)
or self._used_rowwise_adagrad_with_global_weight_decay
or self._used_rowwise_adagrad_with_adagradw
):
self.register_buffer(
"iter",
Expand Down Expand Up @@ -2766,10 +2771,7 @@ def get_optimizer_state(self) -> List[Dict[str, torch.Tensor]]:
"row_counter": states[2],
"iter": self.iter,
}
if self.optimizer_args.regularization_mode
== WeightDecayMode.COUNTER.value
and self.optimizer_args.weight_decay_mode
== CounterWeightDecayMode.ADAGRADW.value
if self._used_rowwise_adagrad_with_adagradw
else {
"sum": states[0],
"prev_iter": states[1],
Expand Down
Loading