pytorch/torch/csrc/jit/python
Vasiliy Kuznetsov bf896a2988 dbr quant: add torchscript pass to remove redundant aliases (#71230)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/71230

DBR quantization uses `torch.Tensor.as_subclass` frequently. When
the quantized model is traced with `torch.jit.trace`, these calls appear
in the resulting graph as `aten::alias`. This PR adds a pass to remove
these calls from the graph, for two reasons:
1. ease of debugging (these calls do nothing)
2. less work for downstream passes (for example, converting to ONNX currently breaks if these alias calls are present)

For now, we have to inline the graph in order for `aliasDb` to determine
safety properly. In the future, we may choose to relax this if there is
a need for it.

Test Plan:
Test plan is pretty basic for now, it can be improved in future PRs.
```
python test/test_quantization.py TestQuantizeDBR.test_jit_tracing_removes_aliases
```

Reviewed By: eellison

Differential Revision: D33552387

Pulled By: vkuzo

fbshipit-source-id: 681a33ddfff394a91e971263ac593afd93c5ea78
(cherry picked from commit 0f8412725d0c6fd9ef1072a50d4203465aa5d1f9)
2022-03-03 15:31:53 +00:00
..
init.cpp dbr quant: add torchscript pass to remove redundant aliases (#71230) 2022-03-03 15:31:53 +00:00
init.h
module_python.h
pybind_utils.cpp Enable Python bindings for UntypedStorage (#68945) 2022-01-20 02:11:34 +00:00
pybind_utils.h Enable Python bindings for UntypedStorage (#68945) 2022-01-20 02:11:34 +00:00
pybind.h [AutoAccept][Codemod][FBSourceClangFormatLinter] Daily arc lint --take CLANGFORMAT 2021-12-19 16:38:25 -08:00
python_arg_flatten.cpp
python_arg_flatten.h
python_custom_class.cpp
python_custom_class.h
python_dict.cpp
python_dict.h
python_interpreter.cpp [jit] Make operation call accept Stack& instead Stack* (#63414) 2021-08-30 11:49:20 -07:00
python_ir.cpp [JIT] script & logging for extracting IR from logs (#72889) 2022-03-02 18:34:35 +00:00
python_ir.h
python_ivalue.h
python_list.cpp [BE] Fix pybind deprecation warnings (#72376) 2022-02-07 18:33:32 +00:00
python_list.h Use ptrdiff_t rather than ssize_t (#71271) 2022-01-13 12:41:53 -08:00
python_sugared_value.cpp (2/2) Make TorchScript Preserve Fully Qualified Class Name for Python Exceptions: frontend change (#72899) 2022-02-16 03:45:15 +00:00
python_sugared_value.h (2/2) Make TorchScript Preserve Fully Qualified Class Name for Python Exceptions: frontend change (#72899) 2022-02-16 03:45:15 +00:00
python_tracer.cpp
python_tracer.h
python_tree_views.cpp Make debug_pkl smaller by only emitting unique traces. (#73368) 2022-03-02 08:37:08 +00:00
python_tree_views.h
script_init.cpp Make debug_pkl smaller by only emitting unique traces. (#73368) 2022-03-02 08:37:08 +00:00
script_init.h
update_graph_executor_opt.cpp
update_graph_executor_opt.h Remove WindowsTorchApiMacro.h in favor of Export.h (#69585) 2021-12-09 17:30:09 -08:00