Repository navigation
[inductor] Force contiguous inputs for custom ops in FallbackKernel - #179422
abaybektursun wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/179422
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
bbafe45 to
ca40916
Compare
|
@pytorchbot label "release notes: composability" |
Custom C++ ops registered via torch.library that call .data_ptr() crash when Inductor passes reinterpret_tensor views without accessible storage. FallbackKernel.process_kernel() calls realize_input() which may return ReinterpretView nodes. Internal ops (aten, prims, etc.) handle views natively, but custom C++ ops typically call .data_ptr() directly, which fails on storage-less views. Fix: for non-internal ops, if realize_input() produces a ReinterpretView, fall back to copy_input() which creates a contiguous tensor with its own storage. Internal op performance is unaffected. The copy only occurs for ReinterpretView inputs to custom ops, which is the minimum necessary to ensure .data_ptr() is callable. Error before fix: RuntimeError: Cannot access data pointer of Tensor that doesn't have storage Exception raised from throw_data_ptr_access_error at c10/core/TensorImpl.cpp:307 Regression: works on PyTorch 2.9.1, crashes on 2.11.0.
ca40916 to
8cbbcc0
Compare
eellison
left a comment
There was a problem hiding this comment.
this isn't correct, and reinterpret view do have data pointers.
zou3519
left a comment
There was a problem hiding this comment.
+1, we shouldn't force contiguous inputs
|
Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as |
Summary
Custom C++ ops registered via
torch.librarythat call.data_ptr()on their inputs crash whentorch.compileis used, because Inductor passesreinterpret_tensorviews that lack accessible storage.Works on PyTorch 2.9.1, crashes on 2.11.0.
Error
Root Cause
FallbackKernel.process_kernel()callsrealize_input()which may returnReinterpretViewnodes. Internal ops (aten, prims, etc.) handle views natively, but custom C++ ops typically call.data_ptr()directly, which fails on storage-less views.Between PyTorch 2.9.1 and 2.11.0, Inductor's codegen changed to create these storage-less views where it previously didn't.
Fix
For non-internal ops, if
realize_input()produces aReinterpretView, fall back tocopy_input()which creates a contiguous tensor with its own storage. Internal ops are identified by namespace (aten,prims,inductor,_c10d_functional,quantized,quantized_decomposed) and are unaffected. The copy only occurs forReinterpretViewinputs to custom ops.Test Plan
Added
test/inductor/test_custom_op_reinterpret_tensor.py:.data_ptr()torch.autograd.Functionwithin a multi-layer compiled model@unittest.skipIf(not HAS_CUDA, ...))Related
torch.compile()with triton'sTensorWrapperin custom triton kernel #124601 (FakeTensor + Triton descriptor = data_ptr crash, same error family)Impact
Blocks all custom CUDA C++ ops that call
.data_ptr()from working insidetorch.compileon PyTorch 2.11+. Real-world example: fused CUTLASS EVT matmul+activation backward kernel providing 3.7% training speedup on H100.cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo