pytorch/torch
Thiago Crepaldi a76bb5d84d Add support for models with mutated buffer on torch.onnx.dynamo_export (#112272)
This PR adds a unit test that leverages `torch.export.ExportedProgram` models that mutates registered buffers. Although the exporter already works out of the box in such scenario, the GraphModule and the exported ONNX model have extra outputs containing the mutated buffers. On future runs of the ONNX model, the mutated buffers are used as input to the model.

The aforementioned extra inputs and outputs are by design and the `ONNXProgram.model_signature` can be used to fetch detailed input/output schema for the exported model.

However, when we want to compare pytorch output to ONNX's, there is a mismatch between the schema because pytorch output does not include the mutated buffers present on the ONNX output.

This PR extends `onnx_program.adapt_torch_outputs_to_onnx(torch_outputs)` so that the mutated buffers are prepended to the Pytorch output, matching the ONNX schema.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/112272
Approved by: https://github.com/titaiwangms, https://github.com/BowenBao
2023-11-23 09:59:02 +00:00
..
_awaits
_C Add support for torch.Generator type in TorchScript (#110413) 2023-11-21 23:07:21 +00:00
_C_flatbuffer
_custom_op [BE]: Remove useless lambdas (#113602) 2023-11-14 20:06:48 +00:00
_decomp Add support for torch.Generator type in TorchScript (#110413) 2023-11-21 23:07:21 +00:00
_dispatch
_dynamo Revert "Add Stateful/Stateless symbolic contexts, use fresh fake mode for dynamo backends (#113926)" 2023-11-22 12:52:33 +00:00
_export Forward fix D51468211 (#114381) 2023-11-23 02:58:52 +00:00
_functorch Revert "Add Stateful/Stateless symbolic contexts, use fresh fake mode for dynamo backends (#113926)" 2023-11-22 12:52:33 +00:00
_higher_order_ops [reland][HigherOrderOp] remove _deprecated_global_ns (#113813) 2023-11-20 23:16:18 +00:00
_inductor limit fused kernel num args. (#113131) 2023-11-22 18:05:33 +00:00
_lazy
_library torch.library: Create helper function is_functional_schema (#111660) 2023-10-27 15:20:25 +00:00
_logging [dynamo] re-add option to log all guard check fails (#113585) 2023-11-16 21:20:29 +00:00
_numpy BUG: fix np.ndarray.resize under dynamo (#113931) 2023-11-17 18:12:17 +00:00
_prims Add support for torch.Generator type in TorchScript (#110413) 2023-11-21 23:07:21 +00:00
_prims_common Run sympy expressions with Python values / FX tracing (#113978) 2023-11-20 21:25:11 +00:00
_refs Fix compiling add with torch.int32 and scalars (#113965) 2023-11-22 07:32:19 +00:00
_subclasses Revert "Add Stateful/Stateless symbolic contexts, use fresh fake mode for dynamo backends (#113926)" 2023-11-22 12:52:33 +00:00
_vendor vendor packaging.version (#114108) 2023-11-21 11:51:23 +00:00
amp Add Half support for CPU autocast on eager mode (#112484) 2023-11-21 20:08:28 +00:00
ao [quant][pt2e] Refactor some internal code for observer insertion (#113500) 2023-11-22 17:44:46 +00:00
autograd [BE]: ruff FURB136: replace ternary with min/max (preview) (#114382) 2023-11-22 22:10:01 +00:00
backends Resolve docstring errors in throughput_benchmark.py, weak.py, _traceback.py, file_baton.py, _contextlib.py, _device.py, cpp_backtrace.py, bundled_inputs.py, run_cpu.py, hooks.py, mobile_optimizer.py, _freeze.py, __init__.py, mkldnn.py, dlpack.py (#113311) 2023-11-15 17:40:04 +00:00
compiler Fix torch.compiler.cudagraph_mark_step_begin example (#112807) 2023-11-07 04:15:31 +00:00
contrib Fixed docstring errors in _fuser.py, _state.py, __init__.py, _freeze.py, _async.py, _recursive.py, _tensorboard_vis.py, _trace.py, _await.py, _check.py, _serialization.py, _script.py, annotations.py, _monkeytype_config.py (#113371) 2023-11-12 03:19:02 +00:00
cpu [Dist] Enable FSDP on CPU (#112145) 2023-11-07 01:37:02 +00:00
csrc Retry #112889 (Opportunistically use ncclCommSplit when creating new NCCL groups) (#114385) 2023-11-23 07:00:00 +00:00
cuda [BE]: ruff apply rule PLW1510 to find silent subprocess errors (#113644) 2023-11-14 20:59:40 +00:00
distributed Retry #112889 (Opportunistically use ncclCommSplit when creating new NCCL groups) (#114385) 2023-11-23 07:00:00 +00:00
distributions [doc] two diff meanings of rv generated by torch.tensor.geometric_ and torch.distributions.geometric.Geometric (#113183) 2023-11-15 03:49:04 +00:00
export [export][retry] Move lifted tensors out of state_dict (#113689) 2023-11-15 09:24:49 +00:00
fft
func
futures
fx Revert "Add Stateful/Stateless symbolic contexts, use fresh fake mode for dynamo backends (#113926)" 2023-11-22 12:52:33 +00:00
jit Add support for torch.Generator type in TorchScript (#110413) 2023-11-21 23:07:21 +00:00
legacy
lib
linalg [Docs] fix typo in example of torch.linalg.solve_triangular (#112361) 2023-10-30 10:33:14 +00:00
masked make_fx can now SymIntify int inputs (#113452) 2023-11-18 06:39:09 +00:00
monitor
mps
multiprocessing Add sparse tensors support to dataloader. (#112842) 2023-11-19 16:05:27 +00:00
nested Fix to wrap jagged dims for split() / split_with_sizes() (#113591) 2023-11-14 19:36:08 +00:00
nn [BE]: ruff FURB136: replace ternary with min/max (preview) (#114382) 2023-11-22 22:10:01 +00:00
onnx Add support for models with mutated buffer on torch.onnx.dynamo_export (#112272) 2023-11-23 09:59:02 +00:00
optim Solving pickle error when saving CyclicLR state_dict (#110931) 2023-11-22 11:38:35 +00:00
package Add file name and size to the serialization metadata logging (#113077) 2023-11-09 11:14:24 +00:00
profiler [Profiler][Easy] Make timestamps in memory timelines be in microseconds (us) (#112772) 2023-11-03 00:41:41 +00:00
quantization
signal
sparse Eliminate unnecessary multiplications by 1 in addmm with sparse compressed tensor operand (#114026) 2023-11-19 12:13:54 +00:00
special
testing [FSDP] Passed TORCH_NCCL_DESYNC_DEBUG instead of NCCL_DESYNC_DEBUG (#114432) 2023-11-23 04:53:12 +00:00
utils [BE]: ruff FURB136: replace ternary with min/max (preview) (#114382) 2023-11-22 22:10:01 +00:00
__config__.py
__future__.py
__init__.py Run sympy expressions with Python values / FX tracing (#113978) 2023-11-20 21:25:11 +00:00
_appdirs.py
_classes.py
_compile.py
_custom_ops.py
_deploy.py
_guards.py Revert "Add Stateful/Stateless symbolic contexts, use fresh fake mode for dynamo backends (#113926)" 2023-11-22 12:52:33 +00:00
_jit_internal.py
_linalg_utils.py
_lobpcg.py
_lowrank.py
_meta_registrations.py Revert "Require less alignment for masking (#114173)" 2023-11-22 21:49:31 +00:00
_namedtensor_internals.py
_ops.py [reland][HigherOrderOp] remove _deprecated_global_ns (#113813) 2023-11-20 23:16:18 +00:00
_python_dispatcher.py
_sources.py
_storage_docs.py
_streambase.py
_tensor_docs.py [doc] two diff meanings of rv generated by torch.tensor.geometric_ and torch.distributions.geometric.Geometric (#113183) 2023-11-15 03:49:04 +00:00
_tensor_str.py Do not error when printing view created in no-grad modified in-place in no-grad (#113716) 2023-11-16 18:57:56 +00:00
_tensor.py Drop dynamo-specific type hints on Tensor in favor of type-ignores (#113720) 2023-11-16 01:54:00 +00:00
_torch_docs.py [doc] caution torch.multinomial usage (#112892) 2023-11-15 18:20:48 +00:00
_utils_internal.py Update impl_abstract_pystub to be less boilerplatey (#113182) 2023-11-08 00:39:00 +00:00
_utils.py Fix torch.load(..., weights_only=True) for NT (#112516) 2023-11-02 14:41:04 +00:00
_VF.py
_vmap_internals.py
_weights_only_unpickler.py [BE] Do not warn when safely loading legacy dicts (#113614) 2023-11-14 22:09:10 +00:00
abi-check.cpp
CMakeLists.txt Revert "[BE] [cuDNN] Always build assuming cuDNN >= 8.0 (#95722)" 2023-11-10 17:26:36 +00:00
custom_class_detail.h
custom_class.h Revert "[1/N] Fixes clang-tidy warnings in header files (#113608)" 2023-11-16 22:38:41 +00:00
extension.h
functional.py make_fx can now SymIntify int inputs (#113452) 2023-11-18 06:39:09 +00:00
hub.py
library.h [fbgemm_gpu] add pt2_compliant tag to some ops (#113201) 2023-11-10 00:32:30 +00:00
library.py Update impl_abstract_pystub to be less boilerplatey (#113182) 2023-11-08 00:39:00 +00:00
overrides.py Add support for torch.Generator type in TorchScript (#110413) 2023-11-21 23:07:21 +00:00
py.typed
quasirandom.py
random.py
README.txt
return_types.py [pytree] register pytree node type in both C++ pytree and Python pytree (#112111) 2023-11-21 19:53:13 +00:00
script.h
serialization.py [BE] Do not warn when safely loading legacy dicts (#113614) 2023-11-14 22:09:10 +00:00
storage.py Fix pydocstyle errors listed in issue 112589 (#113227) 2023-11-13 22:05:45 +00:00
torch_version.py vendor packaging.version (#114108) 2023-11-21 11:51:23 +00:00
types.py improve annotation device parameters where a device ordinal is allowed (#113647) 2023-11-17 14:41:22 +00:00
version.py.tpl

Note [TH abstraction violation]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

TH/THC provide some hpp headers, which are proper C++ headers rather than
C headers.  These headers serve double duty as *internal implementation
detail* headers, whose contents should largely not be used by external
clients.

Ideally, we would not install these headers at all; instead, you should
use public functions (in headers like `THTensor.h`, NOT `THTensor.hpp`)
to manipulate these structs.  However, there are a few places
in torch/csrc where we violate this abstraction.  They are marked with
a pointer to this note.  Each of those sites will have to be refactored
when we refactor the guts of THTensor and related structures.