pytorch/tools/autograd
Laith Sakka 7cfd054075 [attempt 2] Compute contiguity symbolically to avoid dde, and introduce c++ sym_is_contiguous (#157472)
Summary:
When we compute contiguity for a tensor with dynamic shapes we first:
1) Try to compute it without guarding.
2) If all shapes hinted, compute it with potentially adding guards.
3) if any input is not hinted, compute it symbolically.

sym_is_contiguous return a SymBool that is then either evaluated or guard_or_false can be called
on it to avoid data dependent errors.

ex:
 bool is_contiguous = input.sym_is_contiguous().guard_or_false(__FILE__, __LINE__);
is_contiguous_or_false is a helper function that does that.

In this PR I only handle default contiguity, will follow up with changes for other formats like  channel_last .
We use this patter in this PR for several locations to avoid DDEs.

Test Plan:
contbuild & OSS CI,

Rollback Plan:

Reviewed By: malfet

Differential Revision: D77639021

Pull Request resolved: https://github.com/pytorch/pytorch/pull/157472
Approved by: https://github.com/aorenste
2025-07-02 23:12:29 +00:00
..
templates [attempt 2] Compute contiguity symbolically to avoid dde, and introduce c++ sym_is_contiguous (#157472) 2025-07-02 23:12:29 +00:00
__init__.py
BUILD.bazel
build.bzl
context.py [BE] Format .ci/ / .github/ / benchmarks/ / functorch/ / tools/ / torchgen/ with ruff format (#132577) 2024-10-11 18:30:26 +00:00
deprecated.yaml
derivatives.yaml Revert "Fused RMSNorm implementation (#153666)" 2025-07-01 18:46:45 +00:00
gen_annotated_fn_args.py [3/N] Apply py39 ruff fixes (#142115) 2024-12-11 17:50:10 +00:00
gen_autograd_functions.py [torchgen] Refactor torchgen.utils.FileManager to accept pathlib.Path (#150726) 2025-05-15 02:52:24 +00:00
gen_autograd.py [BE] Format .ci/ / .github/ / benchmarks/ / functorch/ / tools/ / torchgen/ with ruff format (#132577) 2024-10-11 18:30:26 +00:00
gen_inplace_or_view_type.py [BE] fix typos in tools/ (#156082) 2025-06-17 19:25:50 +00:00
gen_python_functions.py [BE] fix typos in tools/ (#156082) 2025-06-17 19:25:50 +00:00
gen_trace_type.py [BE] fix typos in tools/ (#156082) 2025-06-17 19:25:50 +00:00
gen_variable_factories.py [BE][CI] bump ruff to 0.9.0: string quote styles (#144569) 2025-02-24 19:56:09 +00:00
gen_variable_type.py [BE][CI] bump ruff to 0.9.2: multiline assert statements (#144546) 2025-02-27 20:46:16 +00:00
gen_view_funcs.py [torchgen] Refactor torchgen.utils.FileManager to accept pathlib.Path (#150726) 2025-05-15 02:52:24 +00:00
load_derivatives.py Revert "Use std::string_view in torchgen (#157050)" 2025-06-30 18:08:54 +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.