pytorch/torch/onnx/_internal
Thiago Crepaldi 7e941a932b Store user model to simplify ONNXProgram.{adapt_torch_*,__call__} APIs (#115281)
Currently (after https://github.com/pytorch/pytorch/pull/114407), the user has must pass the original user ``model`` to APIs such as ``ONNXProgram.__call__``, ``ONNXProgram.adapt_torch_inputs_to_onnx`` and ``ONNXProgram.adapt_torch_outputs_to_onnx`` APIs.

This was needed because when the model is fakefied, a version of the non-fakefied model is needed so that the Initializers, buffers and constants can be extracted from a real model (and used as input to the ONNX model).
That approach brings an unnecessary usability burden to the user when the model is not fakefied, because the model that was already passed to ``torch.onnx.dynamo_export`` could be used to extract ``state_dict``.

This PR adds ``ONNXProgram._model_torch`` attribute to store the user model and demote ``model`` argument of the aforementioned APIs to optional, only (as opposed to required).

As a result, for the fakefied model scenario, the user still need to pass the required model, but for non fakefied models, the persisted model is implicitly used to extract the model state_dict, making it easier to use.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/115281
Approved by: https://github.com/BowenBao
ghstack dependencies: #114407
2023-12-09 07:46:12 +00:00
..
diagnostics Refactor torch.onnx documentation (#108379) 2023-09-08 18:23:48 +00:00
fx Store user model to simplify ONNXProgram.{adapt_torch_*,__call__} APIs (#115281) 2023-12-09 07:46:12 +00:00
__init__.py
_beartype.py Ignore beartype if its version is 0.16.0 (#111859) 2023-10-24 02:11:26 +00:00
exporter.py Store user model to simplify ONNXProgram.{adapt_torch_*,__call__} APIs (#115281) 2023-12-09 07:46:12 +00:00
io_adapter.py Store user model to simplify ONNXProgram.{adapt_torch_*,__call__} APIs (#115281) 2023-12-09 07:46:12 +00:00
jit_utils.py
onnx_proto_utils.py [BE]: Attach cause to some exceptions and enable RUFF TRY200 (#111496) 2023-10-19 21:56:36 +00:00
onnxruntime.py Fix typo under torch/onnx directory (#110697) 2023-10-06 18:21:00 +00:00
registration.py