pytorch/tools/autograd
Edward Z. Yang f7365eca90 Add unbacked symints support; item works now (#90624)
The big idea is to add `create_unbacked_symfloat` and `create_unbacked_symint` to ShapeEnv, allowing you to allocate symbolic floats/ints corresponding to data you don't know about at compile time. Then, instead of immediately erroring out when you try to call local_scalar_dense on a FakeTensor, we instead create a fresh symint/symfloat and return that.

There a bunch of odds and ends that need to be handled:

* A number of `numel` calls converted to `sym_numel`
* When we finally return from item(), we need to ensure we actually produce a SymInt/SymFloat when appropriate. The previous binding code assumed that you would have to get a normal Python item. I add a pybind11 binding for Scalar (to PyObject only) and refactor the code to use that. There is some trickiness where you are NOT allowed to go through c10::SymInt if there isn't actually any SymInt involved. See comment.
* One of our unit tests tripped an implicit data dependent access which occurs when you pass a Tensor as an argument to a sizes parameter. This is also converted to support symbolic shapes
* We now support tracking bare SymInt/SymFloat returns in proxy tensor mode (this was already in symbolic-shapes branch)
* Whenever we allocate an unbacked symint, we record the stack trace it was allocated at. These get printed when you attempt data dependent access on the symint (e.g., you try to guard on it)
* Subtlety: unbacked symints are not necessarily > 1. I added a test for this.

These unbacked symints are not very useful right now as you will almost always immediately raise an error later when you try to guard on them. The next logical step is adding an assertion refinement system that lets ShapeEnv learn facts about unbacked symints so it can do a better job eliding guards that are unnecessary.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Pull Request resolved: https://github.com/pytorch/pytorch/pull/90624
Approved by: https://github.com/Skylion007, https://github.com/voznesenskym
2022-12-12 13:33:07 +00:00
..
templates Add unbacked symints support; item works now (#90624) 2022-12-12 13:33:07 +00:00
__init__.py
BUILD.bazel port Bazel //tools/autograd to shared build structure 2022-04-14 07:40:49 +00:00
build.bzl Rename tools/codegen to torchgen (#76275) 2022-04-25 01:38:06 +00:00
context.py Enable codegen of per-dispatch key derivative formulas in derivatives.yaml (#82801) 2022-08-10 19:26:29 +00:00
deprecated.yaml Revert "Remove split functional wrapper (#74727)" 2022-08-10 19:45:23 +00:00
derivatives.yaml Give std/var correction overloads proper defaults (#56398) 2022-12-07 15:15:00 +00:00
gen_annotated_fn_args.py Apply ufmt linter to all py files under tools (#81285) 2022-07-13 07:59:22 +00:00
gen_autograd_functions.py Unify SymIntNode and SymFloatNode into SymNode (#87817) 2022-10-27 20:56:02 +00:00
gen_autograd.py fix a comment since the options in arg parser no longer require Declarations.yaml (#83337) 2022-08-12 21:10:41 +00:00
gen_inplace_or_view_type.py Revert "Revert "Symintifying slice ops (#85196)"" (#85746) 2022-09-28 04:37:35 +00:00
gen_python_functions.py Add a reshape_copy operator. (#88314) 2022-11-03 12:53:51 +00:00
gen_trace_type.py autograd: fix non-deterministic output in codegen comments (#84695) 2022-09-13 18:41:15 +00:00
gen_variable_factories.py autograd: fix non-deterministic output in codegen comments (#84695) 2022-09-13 18:41:15 +00:00
gen_variable_type.py Add a reshape_copy operator. (#88314) 2022-11-03 12:53:51 +00:00
load_derivatives.py ban .sizes() and .strides() calls in derivatives.yaml (#86611) 2022-10-19 15:59:28 +00:00
README.md

If you add a file to this directory, you MUST update torch/CMakeLists.txt and add the file as a dependency to the add_custom_command call.