Skip to content

Commit

Permalink
explicitly call update_hyper_parameters (#2663)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #2663

Due to various wrappers classes, the hyperparameters are not properly updated within the underlying optimizer, especially the ones that are not saved in `param_groups`. Therefore, we'd need to explicitly call the `update_hyper_parameters` method in order to channel the schedule and change the actual values used within the optimizer.

Reviewed By: xinzhang-nac

Differential Revision: D67804589

fbshipit-source-id: 4b4023b5187dd4783012747059a50fa70b0bda7a
  • Loading branch information
Wang Zhou authored and facebook-github-bot committed Jan 6, 2025
1 parent 00d8ed2 commit 5255984
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions torchrec/optim/keyed.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,12 @@ def set_optimizer_step(self, step: int) -> None:
# pyre-ignore [16]: Undefined attribute [16]: `KeyedOptimizer` has no attribute `set_optimizer_step`.
opt.set_optimizer_step(step)

def update_hyper_parameters(self, params_dict: Dict[str, Any]) -> None:
for _, opt in self._optims:
if hasattr(opt, "update_hyper_parameters"):
# pyre-ignore [16].
opt.update_hyper_parameters(params_dict)


class KeyedOptimizerWrapper(KeyedOptimizer):
"""
Expand Down Expand Up @@ -441,6 +447,11 @@ def set_optimizer_step(self, step: int) -> None:
# pyre-ignore [16].
self._optimizer.set_optimizer_step(step)

def update_hyper_parameters(self, params_dict: Dict[str, Any]) -> None:
if hasattr(self._optimizer, "update_hyper_parameters"):
# pyre-ignore [16].
self._optimizer.update_hyper_parameters(params_dict)


class OptimizerWrapper(KeyedOptimizer):
"""
Expand Down Expand Up @@ -493,3 +504,8 @@ def set_optimizer_step(self, step: int) -> None:
if hasattr(self._optimizer, "set_optimizer_step"):
# pyre-ignore [16].
self._optimizer.set_optimizer_step(step)

def update_hyper_parameters(self, params_dict: Dict[str, Any]) -> None:
if hasattr(self._optimizer, "update_hyper_parameters"):
# pyre-ignore [16].
self._optimizer.update_hyper_parameters(params_dict)

0 comments on commit 5255984

Please sign in to comment.