"app/git@developer.sourcefind.cn:OpenDAS/ollama.git" did not exist on "2aaf29acb5caf3f1fdc50cd48542c94df801752f"
Commit b0d7d60d authored by Michael Carilli's avatar Michael Carilli
Browse files

Changing promotion of FP16_optimizer.optimizer attributes to use properties

parent 5709cfb5
...@@ -532,26 +532,22 @@ class FP16_Optimizer(object): ...@@ -532,26 +532,22 @@ class FP16_Optimizer(object):
loss_scale = property(_get_loss_scale, _set_loss_scale) loss_scale = property(_get_loss_scale, _set_loss_scale)
# Promote optimizer.state, and optimizer.param_groups, to accommodate user code that # Promote state so it can be retrieved or set via "fp16_optimizer_instance.state"
# directly manipulates "optimizer.param_groups" (for example, to adjust the learning rate). def _get_state(self):
def __getattribute__(self, name): return self.optimizer.state
# I could condense the two cases by saying
# if name in ['state', 'param_groups']: def _set_state(self, value):
# return self.optimizer.__dict__[name], self.optimizer.state = value
# but this would bypass self.optimizer's custom getters and setters, if it chose to define any.
# I could also use properties, as for loss_scale, but I don't know if properties bypass state = property(_get_state, _set_state)
# self.optimizer's custom getters and setters.
if name == 'state': # Promote param_groups so it can be retrieved or set via "fp16_optimizer_instance.param_groups"
return self.optimizer.state # (for example, to adjust the learning rate)
elif name == 'param_groups': def _get_param_groups(self):
return self.optimizer.param_groups return self.optimizer.param_groups
else:
return object.__getattribute__(self, name) def _set_param_groups(self, value):
self.optimizer.param_groups = value
param_groups = property(_get_param_groups, _set_param_groups)
def __setattr__(self, name, value):
if name == 'state':
self.optimizer.state = value
elif name == 'param_groups':
self.optimizer.param_groups = value
else:
object.__setattr__(self, name, value)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment