Files
pytorch/test/dynamo_expected_failures/TestTorchFunctionMode.test_subclass_hash
Ryan Guo bb98749230 [dynamo] Always trace into tensor subclass __torch_function__ (#149792)
This patch effectively ignores traceable_tensor_subclasses, allowing
Dynamo to always try tracing into the `__torch_function__` of tensor
subclass. This helps us with 2 things:
1. allowing users to directly benefit from better compilation of tensor
   subclass, by just upgrading pytorch, without having to change legacy
   library code (see earlier patches in the stack for examples).
2. potentially exposing more issues in compiling tensor subclass, so we
   can get signals and improve them.

As a consequence, it exposed and fixes 2 subtle bugs:
1. In `build_torch_function_fn`, we could get
   `torch._C._disabled_torch_function_impl` because we have a
   `Parameter` subclass without `__torch_function__` override or if we
   have a tensor subclass with `__torch_dispatch__` override. We graph
   break on this for now, and plan to add support -- the logic for
   simulating `torch._C._disabled_torch_function_impl` is already in
   `SuperVariable`, we just need to reuse it.
2. Sometimes we create `SyntheticLocalSource` and need to remove all the
   guards installed on it, but we only removed the ones whose source
   _is_ the created synthetic source `s`, but forgot about chained
   source like `s.foo`, this showed up as
   `SYNTHETIC_LOCAL['tmp_0'].__torch_function__.__func__`.

Differential Revision: [D71906141](https://our.internmc.facebook.com/intern/diff/D71906141)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/149792
Approved by: https://github.com/jansel, https://github.com/mlazos
ghstack dependencies: #149482, #149483, #149484
2025-04-02 20:57:00 +00:00

11 lines
592 B
Plaintext

Need to handle `class` block inside `torch.compile` region (`LOAD_BUILD_CLASS`)
or properly graph break on it rather than skipping the frame altogether.
https://github.com/pytorch/pytorch/issues/128942
Fundamental issue is Dynamo tries to probe tensor object properties, but that
could trigger user-defined `__torch_function__` for tensor subclass objects.
In this case the `LOAD_BUILD_CLASS` error caused Dynamo to start tracing in the
`__init__` of the following class, but `self._diag = _diag` hasn't fired yet, and
its `__torch_function__` errors when Dynamo is probing tensor property