torch.optim.Optimizer.register_load_state_dict_post_hook — PyTorch 2.7 documentation (original) (raw)

Optimizer.register_load_state_dict_post_hook(hook, prepend=False)[source][source]

Register a load_state_dict post-hook which will be called afterload_state_dict() is called. It should have the following signature:

The optimizer argument is the optimizer instance being used.

The hook will be called with argument self after callingload_state_dict on self. The registered hook can be used to perform post-processing after load_state_dict has loaded thestate_dict.

Parameters

Returns

a handle that can be used to remove the added hook by callinghandle.remove()

Return type

torch.utils.hooks.RemoveableHandle