Skip to content

Disable __torch_function__ wrapping if __torch_dispatch__ is defined#73942

Closed
ezyang wants to merge 2 commits intogh/ezyang/1096/basefrom
gh/ezyang/1096/head
Closed

Disable __torch_function__ wrapping if __torch_dispatch__ is defined#73942
ezyang wants to merge 2 commits intogh/ezyang/1096/basefrom
gh/ezyang/1096/head

Conversation

@ezyang
Copy link
Copy Markdown
Contributor

@ezyang ezyang commented Mar 8, 2022

Stack from ghstack (oldest at bottom):

This is never what you want and has led us to have to spray
__torch_function__ = _disabled_torch_function_impl everywhere.
Fortunately the fix is simple.

You might still want to overwrite __torch_function__ for performance
reasons, as you can bypass having to run the Python code associated with
the default __torch_function__. It might be a good performance
optimization to bypass this by default if we detect you have the
default __torch_function__ and a __torch_dispatch__, but that is
left for future work.

Signed-off-by: Edward Z. Yang [email protected]

Differential Revision: D34730883

This is never what you want and has led us to have to spray
`__torch_function__ = _disabled_torch_function_impl` everywhere.
Fortunately the fix is simple.

You might still want to overwrite `__torch_function__` for performance
reasons, as you can bypass having to run the Python code associated with
the default `__torch_function__`.  It might be a good performance
optimization to bypass this by default if we detect you have the
default `__torch_function__` and a `__torch_dispatch__`, but that is
left for future work.

Signed-off-by: Edward Z. Yang <[email protected]>

[ghstack-poisoned]
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Mar 8, 2022

CI Flow Status

⚛️ CI Flow

Ruleset - Version: v1
Ruleset - File: https://github.com/pytorch/pytorch/blob/5da4424ce92abbdc427d3845693f733970f433bd/.github/generated-ciflow-ruleset.json
PR ciflow labels: ciflow/default
Add ciflow labels to this PR to trigger more builds:

Workflows Labels (bold enabled) Status
Triggered Workflows
linux-binary-conda ciflow/binaries, ciflow/binaries_conda, ciflow/default ✅ triggered
linux-binary-libtorch-cxx11-abi ciflow/all, ciflow/binaries, ciflow/binaries_libtorch, ciflow/default, ciflow/trunk ✅ triggered
linux-binary-libtorch-pre-cxx11 ciflow/all, ciflow/binaries, ciflow/binaries_libtorch, ciflow/default, ciflow/trunk ✅ triggered
linux-binary-manywheel ciflow/all, ciflow/binaries, ciflow/binaries_wheel, ciflow/default, ciflow/trunk ✅ triggered
linux-bionic-py3.7-clang9 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/noarch, ciflow/trunk ✅ triggered
linux-bionic-rocm4.5-py3.7 ciflow/all, ciflow/default, ciflow/linux, ciflow/rocm, ciflow/trunk ✅ triggered
linux-docs ciflow/all, ciflow/cpu, ciflow/default, ciflow/docs, ciflow/linux, ciflow/trunk ✅ triggered
linux-vulkan-bionic-py3.7-clang9 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/trunk, ciflow/vulkan ✅ triggered
linux-xenial-cuda11.3-py3.7-gcc7 ciflow/all, ciflow/cuda, ciflow/default, ciflow/linux, ciflow/trunk ✅ triggered
linux-xenial-cuda11.3-py3.7-gcc7-bazel-test ciflow/all, ciflow/bazel, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/trunk ✅ triggered
linux-xenial-py3-clang5-mobile-build ciflow/all, ciflow/default, ciflow/linux, ciflow/mobile, ciflow/trunk ✅ triggered
linux-xenial-py3-clang5-mobile-custom-build-static ciflow/all, ciflow/default, ciflow/linux, ciflow/mobile, ciflow/trunk ✅ triggered
linux-xenial-py3.7-clang7-asan ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/sanitizers, ciflow/trunk ✅ triggered
linux-xenial-py3.7-clang7-onnx ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/onnx, ciflow/trunk ✅ triggered
linux-xenial-py3.7-gcc5.4 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/trunk ✅ triggered
linux-xenial-py3.7-gcc5.4-mobile-lightweight-dispatch-build ciflow/all, ciflow/cpu, ciflow/default, ciflow/libtorch, ciflow/linux, ciflow/mobile, ciflow/trunk ✅ triggered
linux-xenial-py3.7-gcc7 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/trunk ✅ triggered
linux-xenial-py3.7-gcc7-no-ops ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/trunk ✅ triggered
macos-arm64-binary-conda ciflow/binaries, ciflow/binaries_conda, ciflow/default ✅ triggered
macos-arm64-binary-wheel ciflow/binaries, ciflow/binaries_wheel, ciflow/default ✅ triggered
macos-binary-conda ciflow/binaries, ciflow/binaries_conda, ciflow/default ✅ triggered
macos-binary-libtorch-cxx11-abi ciflow/binaries, ciflow/binaries_libtorch, ciflow/default ✅ triggered
macos-binary-libtorch-pre-cxx11 ciflow/binaries, ciflow/binaries_libtorch, ciflow/default ✅ triggered
macos-binary-wheel ciflow/binaries, ciflow/binaries_wheel, ciflow/default ✅ triggered
pytorch-linux-xenial-py3-clang5-android-ndk-r19c-gradle-custom-build-single ciflow/all, ciflow/android, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/trunk ✅ triggered
pytorch-linux-xenial-py3-clang5-android-ndk-r19c-gradle-custom-build-single-full-jit ciflow/all, ciflow/android, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/trunk ✅ triggered
win-vs2019-cpu-py3 ciflow/all, ciflow/cpu, ciflow/default, ciflow/trunk, ciflow/win ✅ triggered
win-vs2019-cuda11.3-py3 ciflow/all, ciflow/cuda, ciflow/default, ciflow/trunk, ciflow/win ✅ triggered
windows-binary-libtorch-debug ciflow/all, ciflow/binaries, ciflow/binaries_libtorch, ciflow/default, ciflow/trunk ✅ triggered
windows-binary-libtorch-release ciflow/all, ciflow/binaries, ciflow/binaries_libtorch, ciflow/default, ciflow/trunk ✅ triggered
windows-binary-wheel ciflow/all, ciflow/binaries, ciflow/binaries_wheel, ciflow/default, ciflow/trunk ✅ triggered
Skipped Workflows
caffe2-linux-xenial-py3.7-gcc5.4 ciflow/all, ciflow/cpu, ciflow/linux, ciflow/trunk 🚫 skipped
docker-builds ciflow/all, ciflow/trunk 🚫 skipped
ios-12-5-1-arm64 ciflow/all, ciflow/ios, ciflow/macos, ciflow/scheduled 🚫 skipped
ios-12-5-1-arm64-coreml ciflow/all, ciflow/ios, ciflow/macos, ciflow/scheduled 🚫 skipped
ios-12-5-1-arm64-custom-ops ciflow/all, ciflow/ios, ciflow/macos, ciflow/scheduled 🚫 skipped
ios-12-5-1-arm64-metal ciflow/all, ciflow/ios, ciflow/macos, ciflow/scheduled 🚫 skipped
ios-12-5-1-x86-64 ciflow/all, ciflow/ios, ciflow/macos, ciflow/trunk 🚫 skipped
ios-12-5-1-x86-64-coreml ciflow/all, ciflow/ios, ciflow/macos, ciflow/trunk 🚫 skipped
libtorch-linux-xenial-cuda10.2-py3.7-gcc7 ciflow/all, ciflow/cuda, ciflow/libtorch, ciflow/linux, ciflow/trunk 🚫 skipped
libtorch-linux-xenial-cuda11.3-py3.7-gcc7 ciflow/all, ciflow/cuda, ciflow/libtorch, ciflow/linux, ciflow/trunk 🚫 skipped
linux-bionic-cuda10.2-py3.9-gcc7 ciflow/all, ciflow/cuda, ciflow/linux, ciflow/slow, ciflow/trunk 🚫 skipped
linux-docs-push ciflow/all, ciflow/cpu, ciflow/linux, ciflow/scheduled 🚫 skipped
linux-xenial-cuda11.3-py3.7-gcc7-no-ops ciflow/all, ciflow/cuda, ciflow/linux, ciflow/trunk 🚫 skipped
macos-10-15-py3-arm64 ciflow/all, ciflow/macos, ciflow/trunk 🚫 skipped
macos-10-15-py3-lite-interpreter-x86-64 ciflow/all, ciflow/macos, ciflow/trunk 🚫 skipped
macos-11-py3-x86-64 ciflow/all, ciflow/macos, ciflow/trunk 🚫 skipped
parallelnative-linux-xenial-py3.7-gcc5.4 ciflow/all, ciflow/cpu, ciflow/linux, ciflow/trunk 🚫 skipped
periodic-libtorch-linux-bionic-cuda11.5-py3.7-gcc7 ciflow/all, ciflow/cuda, ciflow/libtorch, ciflow/linux, ciflow/scheduled 🚫 skipped
periodic-linux-bionic-cuda11.5-py3.7-gcc7 ciflow/all, ciflow/cuda, ciflow/linux, ciflow/scheduled 🚫 skipped
periodic-linux-xenial-cuda10.2-py3-gcc7-slow-gradcheck ciflow/all, ciflow/cuda, ciflow/linux, ciflow/scheduled, ciflow/slow, ciflow/slow-gradcheck 🚫 skipped
periodic-linux-xenial-cuda11.3-py3.7-gcc7-debug ciflow/all, ciflow/cuda, ciflow/linux, ciflow/scheduled 🚫 skipped
periodic-win-vs2019-cuda11.5-py3 ciflow/all, ciflow/cuda, ciflow/scheduled, ciflow/win 🚫 skipped
pytorch-linux-xenial-py3-clang5-android-ndk-r19c-build ciflow/all, ciflow/android, ciflow/cpu, ciflow/linux, ciflow/trunk 🚫 skipped
pytorch-xla-linux-bionic-py3.7-clang8 ciflow/all, ciflow/cpu, ciflow/linux, ciflow/trunk, ciflow/xla 🚫 skipped

@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Mar 8, 2022

🔗 Helpful links

💊 CI failures summary and remediations

As of commit 38216e2 (more details on the Dr. CI page):


  • 10/10 failures introduced in this PR

🕵️ 10 new failures recognized by patterns

The following CI failures do not appear to be due to upstream breakages:

See GitHub Actions build linux-bionic-py3.7-clang9 / test (default, 2, 2, linux.2xlarge) (1/10)

Step: "Test" (full log | diagnosis details | 🔁 rerun)

2022-03-08T22:49:55.0241662Z FAIL [0.002s]: tes..._torch_dispatch (__main__.TestAutogradForwardMode)
2022-03-08T22:49:54.9656251Z   test_dataparallel_saved_tensors_hooks (__main__.TestMultithreadAutograd) ... ok (0.002s)
2022-03-08T22:49:54.9840876Z   test_fork_join_in_middle (__main__.TestMultithreadAutograd) ... ok (0.018s)
2022-03-08T22:49:54.9850392Z   test_multithread_saved_tensors_hooks (__main__.TestMultithreadAutograd) ... ok (0.001s)
2022-03-08T22:49:54.9867654Z   test_multithreaded_exception_propagation (__main__.TestMultithreadAutograd) ... ok (0.002s)
2022-03-08T22:49:54.9880205Z   test_preserve_backtrace (__main__.TestMultithreadAutograd) ... ok (0.001s)
2022-03-08T22:49:55.0075648Z   test_python_thread_in_middle (__main__.TestMultithreadAutograd) ... ok (0.019s)
2022-03-08T22:49:55.0138240Z   test_simple_backward (__main__.TestMultithreadAutograd) ... ok (0.006s)
2022-03-08T22:49:55.0240700Z   test_simple_backward_same_input (__main__.TestMultithreadAutograd) ... ok (0.010s)
2022-03-08T22:49:55.0241107Z 
2022-03-08T22:49:55.0241243Z ======================================================================
2022-03-08T22:49:55.0241662Z FAIL [0.002s]: test_make_dual_torch_dispatch (__main__.TestAutogradForwardMode)
2022-03-08T22:49:55.0242553Z ----------------------------------------------------------------------
2022-03-08T22:49:55.0243003Z Traceback (most recent call last):
2022-03-08T22:49:55.0243428Z   File "test_autograd.py", line 7975, in test_make_dual_torch_dispatch
2022-03-08T22:49:55.0243859Z     self.assertEqual(counter[0], 2)
2022-03-08T22:49:55.0244543Z   File "/opt/conda/lib/python3.7/site-packages/torch/testing/_internal/common_utils.py", line 2154, in assertEqual
2022-03-08T22:49:55.0244789Z     msg=msg,
2022-03-08T22:49:55.0245129Z   File "/opt/conda/lib/python3.7/site-packages/torch/testing/_comparison.py", line 1074, in assert_equal
2022-03-08T22:49:55.0245386Z     raise error_metas[0].to_error()
2022-03-08T22:49:55.0245604Z AssertionError: Scalars are not equal!
2022-03-08T22:49:55.0245732Z 

See GitHub Actions build linux-bionic-py3.7-clang9 / test (noarch, 1, 1, linux.2xlarge) (2/10)

Step: "Test" (full log | diagnosis details | 🔁 rerun)

2022-03-08T22:23:02.0058579Z FAIL [0.002s]: tes..._torch_dispatch (__main__.TestAutogradForwardMode)
2022-03-08T22:23:01.9522051Z   test_dataparallel_saved_tensors_hooks (__main__.TestMultithreadAutograd) ... ok (0.002s)
2022-03-08T22:23:01.9692213Z   test_fork_join_in_middle (__main__.TestMultithreadAutograd) ... ok (0.017s)
2022-03-08T22:23:01.9701082Z   test_multithread_saved_tensors_hooks (__main__.TestMultithreadAutograd) ... ok (0.001s)
2022-03-08T22:23:01.9716763Z   test_multithreaded_exception_propagation (__main__.TestMultithreadAutograd) ... ok (0.002s)
2022-03-08T22:23:01.9728834Z   test_preserve_backtrace (__main__.TestMultithreadAutograd) ... ok (0.001s)
2022-03-08T22:23:01.9916077Z   test_python_thread_in_middle (__main__.TestMultithreadAutograd) ... ok (0.019s)
2022-03-08T22:23:01.9971994Z   test_simple_backward (__main__.TestMultithreadAutograd) ... ok (0.006s)
2022-03-08T22:23:02.0057497Z   test_simple_backward_same_input (__main__.TestMultithreadAutograd) ... ok (0.008s)
2022-03-08T22:23:02.0058075Z 
2022-03-08T22:23:02.0058167Z ======================================================================
2022-03-08T22:23:02.0058579Z FAIL [0.002s]: test_make_dual_torch_dispatch (__main__.TestAutogradForwardMode)
2022-03-08T22:23:02.0059189Z ----------------------------------------------------------------------
2022-03-08T22:23:02.0059474Z Traceback (most recent call last):
2022-03-08T22:23:02.0059721Z   File "test_autograd.py", line 7975, in test_make_dual_torch_dispatch
2022-03-08T22:23:02.0059949Z     self.assertEqual(counter[0], 2)
2022-03-08T22:23:02.0060543Z   File "/opt/conda/lib/python3.7/site-packages/torch/testing/_internal/common_utils.py", line 2154, in assertEqual
2022-03-08T22:23:02.0060812Z     msg=msg,
2022-03-08T22:23:02.0061137Z   File "/opt/conda/lib/python3.7/site-packages/torch/testing/_comparison.py", line 1074, in assert_equal
2022-03-08T22:23:02.0061407Z     raise error_metas[0].to_error()
2022-03-08T22:23:02.0061602Z AssertionError: Scalars are not equal!
2022-03-08T22:23:02.0061730Z 

See GitHub Actions build linux-xenial-cuda11.3-py3.7-gcc7 / test (default, 1, 2, linux.4xlarge.nvidia.gpu) (3/10)

Step: "Test" (full log | diagnosis details | 🔁 rerun)

2022-03-08T23:58:14.9606411Z FAIL [0.003s]: tes..._torch_dispatch (__main__.TestAutogradForwardMode)
2022-03-08T23:58:14.8807462Z   test_dataparallel_saved_tensors_hooks (__main__.TestMultithreadAutograd) ... ok (0.002s)
2022-03-08T23:58:14.9061202Z   test_fork_join_in_middle (__main__.TestMultithreadAutograd) ... ok (0.025s)
2022-03-08T23:58:14.9071779Z   test_multithread_saved_tensors_hooks (__main__.TestMultithreadAutograd) ... ok (0.001s)
2022-03-08T23:58:14.9097117Z   test_multithreaded_exception_propagation (__main__.TestMultithreadAutograd) ... ok (0.002s)
2022-03-08T23:58:14.9113776Z   test_preserve_backtrace (__main__.TestMultithreadAutograd) ... ok (0.002s)
2022-03-08T23:58:14.9364838Z   test_python_thread_in_middle (__main__.TestMultithreadAutograd) ... ok (0.025s)
2022-03-08T23:58:14.9459295Z   test_simple_backward (__main__.TestMultithreadAutograd) ... ok (0.009s)
2022-03-08T23:58:14.9605332Z   test_simple_backward_same_input (__main__.TestMultithreadAutograd) ... ok (0.014s)
2022-03-08T23:58:14.9605797Z 
2022-03-08T23:58:14.9605934Z ======================================================================
2022-03-08T23:58:14.9606411Z FAIL [0.003s]: test_make_dual_torch_dispatch (__main__.TestAutogradForwardMode)
2022-03-08T23:58:14.9607400Z ----------------------------------------------------------------------
2022-03-08T23:58:14.9607896Z Traceback (most recent call last):
2022-03-08T23:58:14.9608245Z   File "test_autograd.py", line 7975, in test_make_dual_torch_dispatch
2022-03-08T23:58:14.9608578Z     self.assertEqual(counter[0], 2)
2022-03-08T23:58:14.9609122Z   File "/opt/conda/lib/python3.7/site-packages/torch/testing/_internal/common_utils.py", line 2154, in assertEqual
2022-03-08T23:58:14.9609483Z     msg=msg,
2022-03-08T23:58:14.9609918Z   File "/opt/conda/lib/python3.7/site-packages/torch/testing/_comparison.py", line 1074, in assert_equal
2022-03-08T23:58:14.9610292Z     raise error_metas[0].to_error()
2022-03-08T23:58:14.9610570Z AssertionError: Scalars are not equal!
2022-03-08T23:58:14.9610757Z 

See GitHub Actions build win-vs2019-cpu-py3 / test (default, 2, 2, windows.4xlarge) (4/10)

Step: "Test" (full log | diagnosis details | 🔁 rerun)

2022-03-08T23:39:37.0076728Z FAIL [0.000s]: tes..._torch_dispatch (__main__.TestAutogradForwardMode)
2022-03-08T23:39:36.9537871Z   test_dataparallel_saved_tensors_hooks (__main__.TestMultithreadAutograd) ... ok (0.002s)
2022-03-08T23:39:36.9765650Z   test_fork_join_in_middle (__main__.TestMultithreadAutograd) ... ok (0.019s)
2022-03-08T23:39:36.9779955Z   test_multithread_saved_tensors_hooks (__main__.TestMultithreadAutograd) ... ok (0.000s)
2022-03-08T23:39:36.9820820Z   test_multithreaded_exception_propagation (__main__.TestMultithreadAutograd) ... ok (0.000s)
2022-03-08T23:39:36.9840299Z   test_preserve_backtrace (__main__.TestMultithreadAutograd) ... ok (0.000s)
2022-03-08T23:39:36.9906419Z   test_python_thread_in_middle (__main__.TestMultithreadAutograd) ... ok (0.016s)
2022-03-08T23:39:36.9970985Z   test_simple_backward (__main__.TestMultithreadAutograd) ... ok (0.000s)
2022-03-08T23:39:37.0075318Z   test_simple_backward_same_input (__main__.TestMultithreadAutograd) ... ok (0.016s)
2022-03-08T23:39:37.0075795Z 
2022-03-08T23:39:37.0076118Z ======================================================================
2022-03-08T23:39:37.0076728Z FAIL [0.000s]: test_make_dual_torch_dispatch (__main__.TestAutogradForwardMode)
2022-03-08T23:39:37.0077403Z ----------------------------------------------------------------------
2022-03-08T23:39:37.0077860Z Traceback (most recent call last):
2022-03-08T23:39:37.0080742Z   File "test_autograd.py", line 7975, in test_make_dual_torch_dispatch
2022-03-08T23:39:37.0081287Z     self.assertEqual(counter[0], 2)
2022-03-08T23:39:37.0082087Z   File "C:\actions-runner\_work\pytorch\pytorch\build\win_tmp\build\torch\testing\_internal\common_utils.py", line 2121, in assertEqual
2022-03-08T23:39:37.0082746Z     assert_equal(
2022-03-08T23:39:37.0083426Z   File "C:\actions-runner\_work\pytorch\pytorch\build\win_tmp\build\torch\testing\_comparison.py", line 1074, in assert_equal
2022-03-08T23:39:37.0084106Z     raise error_metas[0].to_error()
2022-03-08T23:39:37.0084538Z AssertionError: Scalars are not equal!
2022-03-08T23:39:37.0084827Z 

See GitHub Actions build linux-xenial-py3.7-clang7-asan / test (default, 2, 3, linux.2xlarge) (5/10)

Step: "Test" (full log | diagnosis details | 🔁 rerun)

2022-03-08T23:35:02.8957717Z FAIL [0.003s]: tes..._torch_dispatch (__main__.TestAutogradForwardMode)
2022-03-08T23:35:02.7684580Z   test_dataparallel_saved_tensors_hooks (__main__.TestMultithreadAutograd) ... ok (0.002s)
2022-03-08T23:35:02.8217236Z   test_fork_join_in_middle (__main__.TestMultithreadAutograd) ... ok (0.053s)
2022-03-08T23:35:02.8226705Z   test_multithread_saved_tensors_hooks (__main__.TestMultithreadAutograd) ... ok (0.001s)
2022-03-08T23:35:02.8251647Z   test_multithreaded_exception_propagation (__main__.TestMultithreadAutograd) ... ok (0.002s)
2022-03-08T23:35:02.8267867Z   test_preserve_backtrace (__main__.TestMultithreadAutograd) ... ok (0.002s)
2022-03-08T23:35:02.8626359Z   test_python_thread_in_middle (__main__.TestMultithreadAutograd) ... ok (0.036s)
2022-03-08T23:35:02.8724788Z   test_simple_backward (__main__.TestMultithreadAutograd) ... ok (0.010s)
2022-03-08T23:35:02.8956373Z   test_simple_backward_same_input (__main__.TestMultithreadAutograd) ... ok (0.023s)
2022-03-08T23:35:02.8956861Z 
2022-03-08T23:35:02.8957217Z ======================================================================
2022-03-08T23:35:02.8957717Z FAIL [0.003s]: test_make_dual_torch_dispatch (__main__.TestAutogradForwardMode)
2022-03-08T23:35:02.8958532Z ----------------------------------------------------------------------
2022-03-08T23:35:02.8958889Z Traceback (most recent call last):
2022-03-08T23:35:02.8959253Z   File "test_autograd.py", line 7975, in test_make_dual_torch_dispatch
2022-03-08T23:35:02.8959670Z     self.assertEqual(counter[0], 2)
2022-03-08T23:35:02.8960313Z   File "/opt/conda/lib/python3.7/site-packages/torch/testing/_internal/common_utils.py", line 2154, in assertEqual
2022-03-08T23:35:02.8960755Z     msg=msg,
2022-03-08T23:35:02.8961286Z   File "/opt/conda/lib/python3.7/site-packages/torch/testing/_comparison.py", line 1074, in assert_equal
2022-03-08T23:35:02.8961568Z     raise error_metas[0].to_error()
2022-03-08T23:35:02.8961764Z AssertionError: Scalars are not equal!
2022-03-08T23:35:02.8961894Z 

See GitHub Actions build win-vs2019-cuda11.3-py3 / test (force_on_cpu, 1, 1, windows.4xlarge) (6/10)

Step: "Test" (full log | diagnosis details | 🔁 rerun)

2022-03-08T23:31:16.1969439Z FAIL [0.016s]: tes..._torch_dispatch (__main__.TestAutogradForwardMode)
2022-03-08T23:31:16.1453698Z   test_dataparallel_saved_tensors_hooks (__main__.TestMultithreadAutograd) ... ok (0.000s)
2022-03-08T23:31:16.1662387Z   test_fork_join_in_middle (__main__.TestMultithreadAutograd) ... ok (0.016s)
2022-03-08T23:31:16.1676148Z   test_multithread_saved_tensors_hooks (__main__.TestMultithreadAutograd) ... ok (0.000s)
2022-03-08T23:31:16.1719149Z   test_multithreaded_exception_propagation (__main__.TestMultithreadAutograd) ... ok (0.000s)
2022-03-08T23:31:16.1738093Z   test_preserve_backtrace (__main__.TestMultithreadAutograd) ... ok (0.016s)
2022-03-08T23:31:16.1803698Z   test_python_thread_in_middle (__main__.TestMultithreadAutograd) ... ok (0.000s)
2022-03-08T23:31:16.1864796Z   test_simple_backward (__main__.TestMultithreadAutograd) ... ok (0.000s)
2022-03-08T23:31:16.1968134Z   test_simple_backward_same_input (__main__.TestMultithreadAutograd) ... ok (0.022s)
2022-03-08T23:31:16.1968602Z 
2022-03-08T23:31:16.1968902Z ======================================================================
2022-03-08T23:31:16.1969439Z FAIL [0.016s]: test_make_dual_torch_dispatch (__main__.TestAutogradForwardMode)
2022-03-08T23:31:16.1970075Z ----------------------------------------------------------------------
2022-03-08T23:31:16.1970548Z Traceback (most recent call last):
2022-03-08T23:31:16.1973375Z   File "test_autograd.py", line 7975, in test_make_dual_torch_dispatch
2022-03-08T23:31:16.1973898Z     self.assertEqual(counter[0], 2)
2022-03-08T23:31:16.1974716Z   File "C:\actions-runner\_work\pytorch\pytorch\build\win_tmp\build\torch\testing\_internal\common_utils.py", line 2121, in assertEqual
2022-03-08T23:31:16.1975363Z     assert_equal(
2022-03-08T23:31:16.1976013Z   File "C:\actions-runner\_work\pytorch\pytorch\build\win_tmp\build\torch\testing\_comparison.py", line 1074, in assert_equal
2022-03-08T23:31:16.1976677Z     raise error_metas[0].to_error()
2022-03-08T23:31:16.1977097Z AssertionError: Scalars are not equal!
2022-03-08T23:31:16.1977363Z 

See GitHub Actions build linux-xenial-py3.7-gcc5.4 / test (default, 2, 2, linux.2xlarge) (7/10)

Step: "Test" (full log | diagnosis details | 🔁 rerun)

2022-03-08T22:49:12.7772182Z FAIL [0.002s]: tes..._torch_dispatch (__main__.TestAutogradForwardMode)
2022-03-08T22:49:12.7207966Z   test_dataparallel_saved_tensors_hooks (__main__.TestMultithreadAutograd) ... ok (0.002s)
2022-03-08T22:49:12.7401043Z   test_fork_join_in_middle (__main__.TestMultithreadAutograd) ... ok (0.019s)
2022-03-08T22:49:12.7409637Z   test_multithread_saved_tensors_hooks (__main__.TestMultithreadAutograd) ... ok (0.001s)
2022-03-08T22:49:12.7425350Z   test_multithreaded_exception_propagation (__main__.TestMultithreadAutograd) ... ok (0.002s)
2022-03-08T22:49:12.7437406Z   test_preserve_backtrace (__main__.TestMultithreadAutograd) ... ok (0.001s)
2022-03-08T22:49:12.7635865Z   test_python_thread_in_middle (__main__.TestMultithreadAutograd) ... ok (0.020s)
2022-03-08T22:49:12.7689607Z   test_simple_backward (__main__.TestMultithreadAutograd) ... ok (0.005s)
2022-03-08T22:49:12.7771254Z   test_simple_backward_same_input (__main__.TestMultithreadAutograd) ... ok (0.008s)
2022-03-08T22:49:12.7771687Z 
2022-03-08T22:49:12.7771845Z ======================================================================
2022-03-08T22:49:12.7772182Z FAIL [0.002s]: test_make_dual_torch_dispatch (__main__.TestAutogradForwardMode)
2022-03-08T22:49:12.7772813Z ----------------------------------------------------------------------
2022-03-08T22:49:12.7773083Z Traceback (most recent call last):
2022-03-08T22:49:12.7773335Z   File "test_autograd.py", line 7975, in test_make_dual_torch_dispatch
2022-03-08T22:49:12.7773569Z     self.assertEqual(counter[0], 2)
2022-03-08T22:49:12.7773972Z   File "/opt/conda/lib/python3.7/site-packages/torch/testing/_internal/common_utils.py", line 2154, in assertEqual
2022-03-08T22:49:12.7774230Z     msg=msg,
2022-03-08T22:49:12.7774571Z   File "/opt/conda/lib/python3.7/site-packages/torch/testing/_comparison.py", line 1074, in assert_equal
2022-03-08T22:49:12.7774841Z     raise error_metas[0].to_error()
2022-03-08T22:49:12.7775036Z AssertionError: Scalars are not equal!
2022-03-08T22:49:12.7775166Z 

See GitHub Actions build win-vs2019-cuda11.3-py3 / test (default, 2, 2, windows.8xlarge.nvidia.gpu) (8/10)

Step: "Test" (full log | diagnosis details | 🔁 rerun)

2022-03-09T01:07:33.1361041Z FAIL [0.000s]: tes..._torch_dispatch (__main__.TestAutogradForwardMode)
2022-03-09T01:07:33.0653066Z   test_dataparallel_saved_tensors_hooks (__main__.TestMultithreadAutograd) ... ok (0.016s)
2022-03-09T01:07:33.0936861Z   test_fork_join_in_middle (__main__.TestMultithreadAutograd) ... ok (0.016s)
2022-03-09T01:07:33.0951984Z   test_multithread_saved_tensors_hooks (__main__.TestMultithreadAutograd) ... ok (0.000s)
2022-03-09T01:07:33.1005857Z   test_multithreaded_exception_propagation (__main__.TestMultithreadAutograd) ... ok (0.016s)
2022-03-09T01:07:33.1028889Z   test_preserve_backtrace (__main__.TestMultithreadAutograd) ... ok (0.000s)
2022-03-09T01:07:33.1120008Z   test_python_thread_in_middle (__main__.TestMultithreadAutograd) ... ok (0.000s)
2022-03-09T01:07:33.1208169Z   test_simple_backward (__main__.TestMultithreadAutograd) ... ok (0.016s)
2022-03-09T01:07:33.1358207Z   test_simple_backward_same_input (__main__.TestMultithreadAutograd) ... ok (0.022s)
2022-03-09T01:07:33.1359302Z 
2022-03-09T01:07:33.1359836Z ======================================================================
2022-03-09T01:07:33.1361041Z FAIL [0.000s]: test_make_dual_torch_dispatch (__main__.TestAutogradForwardMode)
2022-03-09T01:07:33.1362354Z ----------------------------------------------------------------------
2022-03-09T01:07:33.1362978Z Traceback (most recent call last):
2022-03-09T01:07:33.1363979Z   File "test_autograd.py", line 7975, in test_make_dual_torch_dispatch
2022-03-09T01:07:33.1364707Z     self.assertEqual(counter[0], 2)
2022-03-09T01:07:33.1365957Z   File "C:\actions-runner\_work\pytorch\pytorch\build\win_tmp\build\torch\testing\_internal\common_utils.py", line 2121, in assertEqual
2022-03-09T01:07:33.1366849Z     assert_equal(
2022-03-09T01:07:33.1368195Z   File "C:\actions-runner\_work\pytorch\pytorch\build\win_tmp\build\torch\testing\_comparison.py", line 1074, in assert_equal
2022-03-09T01:07:33.1369097Z     raise error_metas[0].to_error()
2022-03-09T01:07:33.1369649Z AssertionError: Scalars are not equal!
2022-03-09T01:07:33.1370018Z 

See GitHub Actions build linux-bionic-rocm4.5-py3.7 / test (default, 2, 2, linux.rocm.gpu) (9/10)

Step: "Test" (full log | diagnosis details | 🔁 rerun)

2022-03-09T05:05:33.9669366Z FAIL [0.002s]: tes..._torch_dispatch (__main__.TestAutogradForwardMode)
2022-03-09T05:05:33.8648746Z   test_dataparallel_saved_tensors_hooks (__main__.TestMultithreadAutograd) ... ok (0.002s)
2022-03-09T05:05:33.8990718Z   test_fork_join_in_middle (__main__.TestMultithreadAutograd) ... ok (0.034s)
2022-03-09T05:05:33.8998750Z   test_multithread_saved_tensors_hooks (__main__.TestMultithreadAutograd) ... ok (0.001s)
2022-03-09T05:05:33.9026316Z   test_multithreaded_exception_propagation (__main__.TestMultithreadAutograd) ... ok (0.002s)
2022-03-09T05:05:33.9034667Z   test_preserve_backtrace (__main__.TestMultithreadAutograd) ... ok (0.001s)
2022-03-09T05:05:33.9439031Z   test_python_thread_in_middle (__main__.TestMultithreadAutograd) ... ok (0.040s)
2022-03-09T05:05:33.9520175Z   test_simple_backward (__main__.TestMultithreadAutograd) ... ok (0.008s)
2022-03-09T05:05:33.9667065Z   test_simple_backward_same_input (__main__.TestMultithreadAutograd) ... ok (0.015s)
2022-03-09T05:05:33.9668004Z 
2022-03-09T05:05:33.9668445Z ======================================================================
2022-03-09T05:05:33.9669366Z FAIL [0.002s]: test_make_dual_torch_dispatch (__main__.TestAutogradForwardMode)
2022-03-09T05:05:33.9670804Z ----------------------------------------------------------------------
2022-03-09T05:05:33.9671651Z Traceback (most recent call last):
2022-03-09T05:05:33.9672498Z   File "test_autograd.py", line 7975, in test_make_dual_torch_dispatch
2022-03-09T05:05:33.9673292Z     self.assertEqual(counter[0], 2)
2022-03-09T05:05:33.9674676Z   File "/opt/conda/lib/python3.7/site-packages/torch/testing/_internal/common_utils.py", line 2154, in assertEqual
2022-03-09T05:05:33.9675537Z     msg=msg,
2022-03-09T05:05:33.9676740Z   File "/opt/conda/lib/python3.7/site-packages/torch/testing/_comparison.py", line 1074, in assert_equal
2022-03-09T05:05:33.9677677Z     raise error_metas[0].to_error()
2022-03-09T05:05:33.9678373Z AssertionError: Scalars are not equal!
2022-03-09T05:05:33.9678815Z 

See GitHub Actions build linux-xenial-py3.7-gcc7 / test (default, 1, 2, linux.2xlarge) (10/10)

Step: "Test" (full log | diagnosis details | 🔁 rerun)

2022-03-08T22:46:59.3864570Z FAIL [0.002s]: tes..._torch_dispatch (__main__.TestAutogradForwardMode)
2022-03-08T22:46:59.3261939Z   test_dataparallel_saved_tensors_hooks (__main__.TestMultithreadAutograd) ... ok (0.002s)
2022-03-08T22:46:59.3464889Z   test_fork_join_in_middle (__main__.TestMultithreadAutograd) ... ok (0.020s)
2022-03-08T22:46:59.3474399Z   test_multithread_saved_tensors_hooks (__main__.TestMultithreadAutograd) ... ok (0.001s)
2022-03-08T22:46:59.3492910Z   test_multithreaded_exception_propagation (__main__.TestMultithreadAutograd) ... ok (0.002s)
2022-03-08T22:46:59.3506625Z   test_preserve_backtrace (__main__.TestMultithreadAutograd) ... ok (0.001s)
2022-03-08T22:46:59.3716024Z   test_python_thread_in_middle (__main__.TestMultithreadAutograd) ... ok (0.021s)
2022-03-08T22:46:59.3772135Z   test_simple_backward (__main__.TestMultithreadAutograd) ... ok (0.006s)
2022-03-08T22:46:59.3863452Z   test_simple_backward_same_input (__main__.TestMultithreadAutograd) ... ok (0.009s)
2022-03-08T22:46:59.3863945Z 
2022-03-08T22:46:59.3864224Z ======================================================================
2022-03-08T22:46:59.3864570Z FAIL [0.002s]: test_make_dual_torch_dispatch (__main__.TestAutogradForwardMode)
2022-03-08T22:46:59.3865296Z ----------------------------------------------------------------------
2022-03-08T22:46:59.3865571Z Traceback (most recent call last):
2022-03-08T22:46:59.3865821Z   File "test_autograd.py", line 7975, in test_make_dual_torch_dispatch
2022-03-08T22:46:59.3866090Z     self.assertEqual(counter[0], 2)
2022-03-08T22:46:59.3866503Z   File "/opt/conda/lib/python3.7/site-packages/torch/testing/_internal/common_utils.py", line 2154, in assertEqual
2022-03-08T22:46:59.3866784Z     msg=msg,
2022-03-08T22:46:59.3867144Z   File "/opt/conda/lib/python3.7/site-packages/torch/testing/_comparison.py", line 1074, in assert_equal
2022-03-08T22:46:59.3867420Z     raise error_metas[0].to_error()
2022-03-08T22:46:59.3867643Z AssertionError: Scalars are not equal!
2022-03-08T22:46:59.3867784Z 

This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

…is defined"

This is never what you want and has led us to have to spray
`__torch_function__ = _disabled_torch_function_impl` everywhere.
Fortunately the fix is simple.

You might still want to overwrite `__torch_function__` for performance
reasons, as you can bypass having to run the Python code associated with
the default `__torch_function__`.  It might be a good performance
optimization to bypass this by default if we detect you have the
default `__torch_function__` and a `__torch_dispatch__`, but that is
left for future work.

Signed-off-by: Edward Z. Yang <ezyangfb.com>

[ghstack-poisoned]
ezyang added a commit that referenced this pull request Mar 8, 2022
This is never what you want and has led us to have to spray
`__torch_function__ = _disabled_torch_function_impl` everywhere.
Fortunately the fix is simple.

You might still want to overwrite `__torch_function__` for performance
reasons, as you can bypass having to run the Python code associated with
the default `__torch_function__`.  It might be a good performance
optimization to bypass this by default if we detect you have the
default `__torch_function__` and a `__torch_dispatch__`, but that is
left for future work.

Signed-off-by: Edward Z. Yang <ezyangfb.com>

ghstack-source-id: ab8e7d1
Pull Request resolved: #73942
@ezyang ezyang requested review from albanD and bdhirsh March 8, 2022 22:05
@ezyang
Copy link
Copy Markdown
Contributor Author

ezyang commented Mar 8, 2022

@ezyang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Copy Markdown
Collaborator

@bdhirsh bdhirsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I was actually thinking of something like updating check_has_torch_function() to return false by default when torch_dispatch is defined (and maybe renaming it to check_should_call_torch_function()), but this seems cleaner (but more expensive)

@ezyang
Copy link
Copy Markdown
Contributor Author

ezyang commented Mar 8, 2022

It also doesn't work in all cases, because the DisableTorchFunction in the default implementation means that I cannot call FX proxies anymore (as they work on torch function). Need #55093

ezyang added a commit that referenced this pull request Apr 1, 2022
If __torch_function__ was disabled, this TLS should propagate to
other threads.

Although I was thinking about #73942
when I did this, this doesn't actually help solve the problem, because
when I disable __torch_function__ as part of the disabled
__torch_function__ implementation, this is prior to when snapshotting
happens (also snapshotting only happens for Python tensors anyway).

I intend to add some more TLS to this struct soon, which is why it's
a struct and not just a bool.

Testing is not so easy to do because on CPU there isn't an easy way
to get Python code running in another thread.

Signed-off-by: Edward Z. Yang <[email protected]>

[ghstack-poisoned]
ezyang added a commit that referenced this pull request Apr 1, 2022
If __torch_function__ was disabled, this TLS should propagate to
other threads.

Although I was thinking about #73942
when I did this, this doesn't actually help solve the problem, because
when I disable __torch_function__ as part of the disabled
__torch_function__ implementation, this is prior to when snapshotting
happens (also snapshotting only happens for Python tensors anyway).

I intend to add some more TLS to this struct soon, which is why it's
a struct and not just a bool.

Testing is not so easy to do because on CPU there isn't an easy way
to get Python code running in another thread.

Signed-off-by: Edward Z. Yang <ezyangfb.com>

ghstack-source-id: 90ce891
Pull Request resolved: #75110
ezyang added a commit that referenced this pull request Apr 1, 2022
…State"

If __torch_function__ was disabled, this TLS should propagate to
other threads.

Although I was thinking about #73942
when I did this, this doesn't actually help solve the problem, because
when I disable __torch_function__ as part of the disabled
__torch_function__ implementation, this is prior to when snapshotting
happens (also snapshotting only happens for Python tensors anyway).

I intend to add some more TLS to this struct soon, which is why it's
a struct and not just a bool.

Testing is not so easy to do because on CPU there isn't an easy way
to get Python code running in another thread.

Signed-off-by: Edward Z. Yang <ezyangfb.com>

[ghstack-poisoned]
ezyang added a commit that referenced this pull request Apr 1, 2022
If __torch_function__ was disabled, this TLS should propagate to
other threads.

Although I was thinking about #73942
when I did this, this doesn't actually help solve the problem, because
when I disable __torch_function__ as part of the disabled
__torch_function__ implementation, this is prior to when snapshotting
happens (also snapshotting only happens for Python tensors anyway).

I intend to add some more TLS to this struct soon, which is why it's
a struct and not just a bool.

Testing is not so easy to do because on CPU there isn't an easy way
to get Python code running in another thread.

Signed-off-by: Edward Z. Yang <ezyangfb.com>

[ghstack-poisoned]
pytorchmergebot pushed a commit that referenced this pull request Apr 2, 2022
If __torch_function__ was disabled, this TLS should propagate to
other threads.

Although I was thinking about #73942
when I did this, this doesn't actually help solve the problem, because
when I disable __torch_function__ as part of the disabled
__torch_function__ implementation, this is prior to when snapshotting
happens (also snapshotting only happens for Python tensors anyway).

I intend to add some more TLS to this struct soon, which is why it's
a struct and not just a bool.

Testing is not so easy to do because on CPU there isn't an easy way
to get Python code running in another thread.

Signed-off-by: Edward Z. Yang <ezyangfb.com>

Pull Request resolved: #75110

Approved by: https://github.com/albanD
facebook-github-bot pushed a commit that referenced this pull request Apr 4, 2022
Summary:
If __torch_function__ was disabled, this TLS should propagate to
other threads.

Although I was thinking about #73942
when I did this, this doesn't actually help solve the problem, because
when I disable __torch_function__ as part of the disabled
__torch_function__ implementation, this is prior to when snapshotting
happens (also snapshotting only happens for Python tensors anyway).

I intend to add some more TLS to this struct soon, which is why it's
a struct and not just a bool.

Testing is not so easy to do because on CPU there isn't an easy way
to get Python code running in another thread.

Signed-off-by: Edward Z. Yang <ezyangfb.com>

Pull Request resolved: #75110

Approved by: https://github.com/albanD

Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/3f108a5cc132f5940553980c2b84947f7d9e1ed2

Reviewed By: atalman

Differential Revision: D35359970

Pulled By: atalman

fbshipit-source-id: 98b3910b05f79f5a4860f12959878d72c6ce6f56
@albanD
Copy link
Copy Markdown
Collaborator

albanD commented Apr 19, 2022

cc @ezyang anything blocking this?

@ezyang
Copy link
Copy Markdown
Contributor Author

ezyang commented Apr 19, 2022

yeah, the PR doesn't work because reentrant torch function is broken T.T

@github-actions
Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as Stale.
Feel free to remove the Stale label if you feel this was a mistake.
If you are unable to remove the Stale label please contact a maintainer in order to do so.
If you want the bot to never mark this PR stale again, add the no-stale label.
Stale pull requests will automatically be closed after 30 days of inactivity.

@github-actions github-actions Bot added the Stale label Jun 18, 2022
@github-actions github-actions Bot closed this Jul 18, 2022
@facebook-github-bot facebook-github-bot deleted the gh/ezyang/1096/head branch August 18, 2022 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants