pytorch/torch/_export
Avik Chaudhuri 8d921eb97f export method (#147573)
The `export` API takes a `nn.Module` and traces its `forward` method. However sometimes it is useful to export different methods of a `nn.Module`, either as a one-off for debugging or as a set of methods that are called in some sequence outside `export` (e.g., `encode` / `decode`). When multiple methods of the same module instance are exported, they should share the same of the common module instance.

This PR adds a couple of utils in `torch._export.utils` for this workflow.

The `wrap_method` util wraps a method as a `nn.Module` that can then be exported. See included test. We recommend using the same module instance to export multiple methods on that instance, in which case they are guaranteed to share  state. On serde, this state sharing is lost, so we provide another util, `sync_state`, to re-sync the state.

These utils are meant to be eventually replaced by API-level changes, but for now this can unblock users who need this workflow. In particular, in the future we can accept one or multiple method entrypoints, with their own args / kwargs / dynamic shape specifications, which can create a variant of `ExportedProgram` with multiple graphs that share state; then we can automatically ensure that the state sharing is preserved through serde.

Differential Revision: [D69960801](https://our.internmc.facebook.com/intern/diff/D69960801/)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/147573
Approved by: https://github.com/tugsbayasgalan
2025-02-25 20:58:54 +00:00
..
db PEP585 update - torch/_export (#145138) 2025-01-19 18:48:35 +00:00
pass_infra PEP585 update - torch/_export (#145138) 2025-01-19 18:48:35 +00:00
passes patch for block-wise quantization + pt2e (#146946) 2025-02-18 01:15:26 +00:00
serde [export] Loosen symint input serialization (#147237) 2025-02-18 13:03:47 +00:00
__init__.py PEP585: More UP006 fixes (#146392) 2025-02-20 06:18:13 +00:00
converter.py PEP585 update - torch/_export (#145138) 2025-01-19 18:48:35 +00:00
error.py Fix global flake8 issues (#124771) 2024-04-26 15:35:53 +00:00
non_strict_utils.py better error message (#147532) 2025-02-21 17:08:47 +00:00
pass_base.py PEP585 update - torch/_export (#145138) 2025-01-19 18:48:35 +00:00
tools.py PEP585 update - torch/_export (#145138) 2025-01-19 18:48:35 +00:00
utils.py export method (#147573) 2025-02-25 20:58:54 +00:00
verifier.py Implement serializable getattr support for tensor subclasses (#145772) 2025-02-11 19:05:14 +00:00
wrappers.py graph module retracing without preserving MCS (#143676) 2024-12-21 07:57:43 +00:00