Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/187733
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ No FailuresAs of commit 942a21d with merge base 9d625a9 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@claude review these changes |
|
Claude finished @jansel's task in 50s —— View job PR Review: Fix bmm outer product Triton launch on non-current CUDA device
I reviewed both changed files against Correctness ✅The diagnosis is sound: the Python dispatch override launches Triton directly, and Triton uses the current device/stream rather than the input tensor's device. The two changes together address it:
The conditional guard (vs. unconditional) is justified by the benchmark in the description, and the same-device fast path stays direct. Test ✅
Minor observations (non-blocking)
SummaryLGTM. The fix is correct, minimal, and the new test exercises the exact failure mode from #187729. The only thing I'd flag is the latent CUDA-only assumption on the (currently dead) XPU path. |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
|
@pytorchbot cherry-pick --onto release/2.13 -c critical |
Cherry picking #187733The cherry pick PR is at #187983 and it is recommended to link a critical cherry pick PR with an issue. The following tracker issues are updated: Details for Dev Infra teamRaised by workflow job |
Fix bmm outer product Triton launch on non-current CUDA device (#187733) The Python native bmm outer-product override launches a Triton kernel for CUDA inputs shaped like `(B, M, 1) x (B, 1, N)`. Unlike the generated C++ ATen CUDA path, this Python dispatch path does not get an automatic CUDA device guard before launching the kernel. In vLLM multimodal tests, the model hooks can run the relevant rotary embedding buffers and inputs on `cuda:1` while the process current device is still `cuda:0`; Triton then launches on the wrong device/stream and rejects the `cuda:1` pointers with `ValueError: Pointer argument cannot be accessed from Triton (cpu tensor?)`. Guard the Triton call when the input device is not already current, while leaving the common already-current path direct to avoid unnecessary Python context manager overhead. Also require both bmm inputs to be on the same CUDA device before selecting the override, so mismatched CUDA inputs fall back to native bmm and report the normal same-device error instead of reaching the Triton kernel. I considered guarding unconditionally, but a small same-device benchmark showed that the Python context manager adds measurable overhead for small outer-product bmm calls. The conditional guard keeps the fix scoped to the non-current-device case that needs it. Fixes #187729 Generated by my agent Benchmark Results: - Command: `CUDA_VISIBLE_DEVICES=0 python - <<'PY' ...` benchmarking 7 trials of 1000 `torch.bmm` calls on `(32, 128, 1) x (32, 1, 512)` CUDA tensors with current device matching the inputs. - Before: median 24.210 us/call; raw `[24.34, 24.365, 24.195, 24.206, 24.21, 24.272, 24.142]`. - After: median 24.946 us/call; raw `[25.045, 24.909, 25.008, 25.042, 24.906, 24.946, 24.926]`. Test Plan: - `CUDA_VISIBLE_DEVICES=0,1 python - <<'PY' ...` minimal repro: before the fix failed with the Triton pointer `ValueError`; after the fix produced a `cuda:1` result and preserved current device `0`. - `CUDA_VISIBLE_DEVICES=0,1 python -m pytest test/test_bmm_outer_product.py -q -rs` passed: `11 passed, 10 subtests passed`. - `lintrunner torch/_native/ops/bmm_outer_product/triton_impl.py test/test_bmm_outer_product.py` passed. - `git diff --cached --check` passed. - `lintrunner -a` was run and failed on unrelated pre-existing clang-tidy findings in untouched C++ files. Pull Request resolved: #187733 Approved by: https://github.com/slayton58 (cherry picked from commit 5a5e50f) Co-authored-by: Jason Ansel <[email protected]>
…ch#187733) The Python native bmm outer-product override launches a Triton kernel for CUDA inputs shaped like `(B, M, 1) x (B, 1, N)`. Unlike the generated C++ ATen CUDA path, this Python dispatch path does not get an automatic CUDA device guard before launching the kernel. In vLLM multimodal tests, the model hooks can run the relevant rotary embedding buffers and inputs on `cuda:1` while the process current device is still `cuda:0`; Triton then launches on the wrong device/stream and rejects the `cuda:1` pointers with `ValueError: Pointer argument cannot be accessed from Triton (cpu tensor?)`. Guard the Triton call when the input device is not already current, while leaving the common already-current path direct to avoid unnecessary Python context manager overhead. Also require both bmm inputs to be on the same CUDA device before selecting the override, so mismatched CUDA inputs fall back to native bmm and report the normal same-device error instead of reaching the Triton kernel. I considered guarding unconditionally, but a small same-device benchmark showed that the Python context manager adds measurable overhead for small outer-product bmm calls. The conditional guard keeps the fix scoped to the non-current-device case that needs it. Fixes pytorch#187729 Generated by my agent Benchmark Results: - Command: `CUDA_VISIBLE_DEVICES=0 python - <<'PY' ...` benchmarking 7 trials of 1000 `torch.bmm` calls on `(32, 128, 1) x (32, 1, 512)` CUDA tensors with current device matching the inputs. - Before: median 24.210 us/call; raw `[24.34, 24.365, 24.195, 24.206, 24.21, 24.272, 24.142]`. - After: median 24.946 us/call; raw `[25.045, 24.909, 25.008, 25.042, 24.906, 24.946, 24.926]`. Test Plan: - `CUDA_VISIBLE_DEVICES=0,1 python - <<'PY' ...` minimal repro: before the fix failed with the Triton pointer `ValueError`; after the fix produced a `cuda:1` result and preserved current device `0`. - `CUDA_VISIBLE_DEVICES=0,1 python -m pytest test/test_bmm_outer_product.py -q -rs` passed: `11 passed, 10 subtests passed`. - `lintrunner torch/_native/ops/bmm_outer_product/triton_impl.py test/test_bmm_outer_product.py` passed. - `git diff --cached --check` passed. - `lintrunner -a` was run and failed on unrelated pre-existing clang-tidy findings in untouched C++ files. Pull Request resolved: pytorch#187733 Approved by: https://github.com/slayton58
…ch#187733) The Python native bmm outer-product override launches a Triton kernel for CUDA inputs shaped like `(B, M, 1) x (B, 1, N)`. Unlike the generated C++ ATen CUDA path, this Python dispatch path does not get an automatic CUDA device guard before launching the kernel. In vLLM multimodal tests, the model hooks can run the relevant rotary embedding buffers and inputs on `cuda:1` while the process current device is still `cuda:0`; Triton then launches on the wrong device/stream and rejects the `cuda:1` pointers with `ValueError: Pointer argument cannot be accessed from Triton (cpu tensor?)`. Guard the Triton call when the input device is not already current, while leaving the common already-current path direct to avoid unnecessary Python context manager overhead. Also require both bmm inputs to be on the same CUDA device before selecting the override, so mismatched CUDA inputs fall back to native bmm and report the normal same-device error instead of reaching the Triton kernel. I considered guarding unconditionally, but a small same-device benchmark showed that the Python context manager adds measurable overhead for small outer-product bmm calls. The conditional guard keeps the fix scoped to the non-current-device case that needs it. Fixes pytorch#187729 Generated by my agent Benchmark Results: - Command: `CUDA_VISIBLE_DEVICES=0 python - <<'PY' ...` benchmarking 7 trials of 1000 `torch.bmm` calls on `(32, 128, 1) x (32, 1, 512)` CUDA tensors with current device matching the inputs. - Before: median 24.210 us/call; raw `[24.34, 24.365, 24.195, 24.206, 24.21, 24.272, 24.142]`. - After: median 24.946 us/call; raw `[25.045, 24.909, 25.008, 25.042, 24.906, 24.946, 24.926]`. Test Plan: - `CUDA_VISIBLE_DEVICES=0,1 python - <<'PY' ...` minimal repro: before the fix failed with the Triton pointer `ValueError`; after the fix produced a `cuda:1` result and preserved current device `0`. - `CUDA_VISIBLE_DEVICES=0,1 python -m pytest test/test_bmm_outer_product.py -q -rs` passed: `11 passed, 10 subtests passed`. - `lintrunner torch/_native/ops/bmm_outer_product/triton_impl.py test/test_bmm_outer_product.py` passed. - `git diff --cached --check` passed. - `lintrunner -a` was run and failed on unrelated pre-existing clang-tidy findings in untouched C++ files. Pull Request resolved: pytorch#187733 Approved by: https://github.com/slayton58
Stack from ghstack (oldest at bottom):
The Python native bmm outer-product override launches a Triton kernel for
CUDA inputs shaped like
(B, M, 1) x (B, 1, N). Unlike the generated C++ATen CUDA path, this Python dispatch path does not get an automatic CUDA
device guard before launching the kernel. In vLLM multimodal tests, the
model hooks can run the relevant rotary embedding buffers and inputs on
cuda:1while the process current device is stillcuda:0; Triton thenlaunches on the wrong device/stream and rejects the
cuda:1pointers withValueError: Pointer argument cannot be accessed from Triton (cpu tensor?).Guard the Triton call when the input device is not already current, while
leaving the common already-current path direct to avoid unnecessary Python
context manager overhead. Also require both bmm inputs to be on the same CUDA
device before selecting the override, so mismatched CUDA inputs fall back to
native bmm and report the normal same-device error instead of reaching the
Triton kernel.
I considered guarding unconditionally, but a small same-device benchmark showed
that the Python context manager adds measurable overhead for small outer-product
bmm calls. The conditional guard keeps the fix scoped to the non-current-device
case that needs it.
Fixes #187729
Generated by my agent
Benchmark Results:
CUDA_VISIBLE_DEVICES=0 python - <<'PY' ...benchmarking 7 trials of 1000torch.bmmcalls on(32, 128, 1) x (32, 1, 512)CUDA tensors with current device matching the inputs.[24.34, 24.365, 24.195, 24.206, 24.21, 24.272, 24.142].[25.045, 24.909, 25.008, 25.042, 24.906, 24.946, 24.926].Test Plan:
CUDA_VISIBLE_DEVICES=0,1 python - <<'PY' ...minimal repro: before the fix failed with the Triton pointerValueError; after the fix produced acuda:1result and preserved current device0.CUDA_VISIBLE_DEVICES=0,1 python -m pytest test/test_bmm_outer_product.py -q -rspassed:11 passed, 10 subtests passed.lintrunner torch/_native/ops/bmm_outer_product/triton_impl.py test/test_bmm_outer_product.pypassed.git diff --cached --checkpassed.lintrunner -awas run and failed on unrelated pre-existing clang-tidy findings in untouched C++ files.