pytorch/torch/_dynamo/variables
angelayi c844b377fa [dynamo] Reorder logs (#116106)
Currently when there is a print/warning in the graph, dynamo graph breaks causing export to fail. However export would like to just skip over these print/warning calls: https://github.com/pytorch/pytorch/issues/113792.

Additionally there's a torch.compile feature request to "reorder prints" so that instead of graph breaking when hitting prints/logging, we can skip over these prints to create larger compiled graphs, and then print the results out after those compiled graphs: https://github.com/pytorch/pytorch/issues/93739. This PR also adds the `reorderable_logging_functions` config for users to register logging functions to be reordered (like `print` or a custom logging function). Printout of the bytecode after reordering the prints looks like the following: P914736600

There are some limitations to the printing right now:
* You can only register logging functions, not methods
* Inputs to the logging functions can only be tensors, constants, and format strings
* Inputs to the logging functions which will later be mutated in-place will not be printed correctly

TODO: Add the following tests
* print function with argument of nested data structure;
* print function with argument of nested data structure being updated inside of compile region (this would test if we handle side effect correctly);
* custom defined logging functions with nn.Module or nn.Module attribute arguments;
* custom defined logging functions with submodule input/output as arguments (we need to handle the mapping and fused-out value);
* custom defined logging functions with tensor argument and mutation inside of the function (TBD: this may increase memory usage);

Pull Request resolved: https://github.com/pytorch/pytorch/pull/116106
Approved by: https://github.com/yanboliang
2024-03-01 17:04:24 +00:00
..
__init__.py [dynamo] Support module backwards hooks (#120685) 2024-03-01 02:24:26 +00:00
base.py [dynamo] Improve support for backwards hooks (#119525) 2024-02-10 01:14:03 +00:00
builder.py [dynamo] Reorder logs (#116106) 2024-03-01 17:04:24 +00:00
builtin.py [dynamo][refactor] Rename LIST_LENGTH to SEQUENCE_LENGTH, separate DICT_LENGTH (#120721) 2024-02-28 02:19:10 +00:00
constant.py Print the value of constants in __str__ (#119276) 2024-02-08 16:23:36 +00:00
ctx_manager.py [dynamo] Fix inference_mode context variable (#120830) 2024-02-29 17:10:06 +00:00
dicts.py [dynamo] Refactor reconstruct() not to return anything (#120150) 2024-02-17 17:13:41 +00:00
distributed.py [dynamo] Support module backwards hooks (#120685) 2024-03-01 02:24:26 +00:00
functions.py Ban reset_to_zero argument to triton.autotune in user defined kernels (#120938) 2024-03-01 02:37:24 +00:00
higher_order_ops.py [Compiled Autograd] Introduce BackwardState capture (#120382) 2024-02-28 20:36:47 +00:00
iter.py Unify MYPYINDUCTOR and MYPY (#118432) 2024-01-27 17:23:20 +00:00
lazy.py Unify MYPYINDUCTOR and MYPY (#118432) 2024-01-27 17:23:20 +00:00
lists.py [dynamo] Refactor reconstruct() not to return anything (#120150) 2024-02-17 17:13:41 +00:00
misc.py [dynamo] Reorder logs (#116106) 2024-03-01 17:04:24 +00:00
nn_module.py [Dynamo] Support lazy module with namedtuple/dict input (#119972) 2024-02-15 23:18:18 +00:00
optimizer.py [dynamo,optim] Use the actual sources from the parameters when tracing "params" in an optimizer (#118535) 2024-02-02 14:42:56 +00:00
sdpa.py [dynamo] Refactor reconstruct() not to return anything (#120150) 2024-02-17 17:13:41 +00:00
tensor.py [Compiled Autograd] Introduce BackwardState capture (#120382) 2024-02-28 20:36:47 +00:00
torch_function.py Fix handling none source in build_torch_function_fn (#119724) 2024-02-15 21:21:47 +00:00
torch.py [dynamo] Support module backwards hooks (#120685) 2024-03-01 02:24:26 +00:00
user_defined.py Revert "[Dynamo] Fix inspect.getattr_static doesn't work well for torch.utils._cxx_pytree.PyTreeSpec (#120812)" 2024-03-01 03:53:27 +00:00