🚀 The feature, motivation and pitch
I propose that we implement .state_dict() and .load_state_dict() in OptimizedModule in such a way that they bypass the wrapper and return/load the state from the inner _orig_mod module.
Motivation:
- User might accidentally save the state dict of a compiled model into their checkpoint, only to find out later they can't load because the keys don't match
- The torch-compiled module may be wrapped by FSDP, DDP, etc. This would make it cumbersome for the user to save a checkpoint while also removing these keys or unwrapping the model.
The sketch of the implementation:
class OptimizedModule(torch.nn.Module):
...
def state_dict(self, *args, **kwargs):
return self._orig_mod.state_dict(*args, **kwargs)
def load_state_dict(self, *args, **kwargs):
# TODO: add some backward-compatibility code here
return self._orig_mod.load_state_dict(*args, **kwargs)
With this implementation, we can effortlessly load the state-dict of a regular nn.Module into a torch-compiled module and vice versa!
Alternatives
Keep as is.
Additional context
This would probably also close/fix #94575
I am happy to send a PR for this.
cc @mruberry @mikaylagawarecki @ezyang @msaroufim @wconstab @bdhirsh @anijain2305 @zou3519
🚀 The feature, motivation and pitch
I propose that we implement
.state_dict()and.load_state_dict()in OptimizedModule in such a way that they bypass the wrapper and return/load the state from the inner_orig_modmodule.Motivation:
The sketch of the implementation:
With this implementation, we can effortlessly load the state-dict of a regular nn.Module into a torch-compiled module and vice versa!
Alternatives
Keep as is.
Additional context
This would probably also close/fix #94575
I am happy to send a PR for this.
cc @mruberry @mikaylagawarecki @ezyang @msaroufim @wconstab @bdhirsh @anijain2305 @zou3519