Repository navigation
Guard FP8 Triton launches with tensor device context - #6888
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a device context manager, _fp8_triton_device_context, to ensure that Triton FP8 kernels are executed on the correct GPU or XPU device in multi-device environments. It wraps several kernel launches with this context and adds a comprehensive test suite in tests/test_fp8_device_context.py to verify correct device selection and execution behavior. I have no additional feedback to provide as the implementation is clean and well-tested.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
I looked at the failing |
|
Noting overlap with #6912, which appears to address the same #6831 FP8 device-context root cause and has useful validation on the original 8x H200 repro. This PR takes a slightly broader approach: it adds regression tests, uses a local device-context helper for CUDA/XPU/single-device behavior and also guards the FBGEMM Happy to adapt this PR to the preferred style @danielhanchen or split out the tests as a follow-up. |
|
Verified your fix live on a 2-GPU box. On main, a weight_dequant with the tensor on a non-current device reproduces the exact #6831 failure (the Triton cross-device pointer error). With your guard it runs clean: output on the tensor's device, current device untouched. Suite green. Folded in two follow-ups on top of your commits: a capability skip so the act_quant runtime test skips on non-FP8 hardware instead of failing at kernel compile, and a guard on the torchao block-matmul path (the preferred backend) the diff left uncovered. Checked that one against real torchao: unguarded it crashes the same way; guarded, it runs clean. Your original change is unchanged. Merging. |
Summary
Fixes #6831.
unsloth/kernels/fp8.pylaunches several FP8 Triton kernels without first selecting the device where the input tensor lives. In a multi-GPUdevice_mapsetup, the current CUDA device can still becuda:0while an FP8 tensor is oncuda:1or another device. That can make Triton launch against the wrong device and produce silent corruption, NaNs, or illegal memory access.This adds a local FP8 device-context helper and wraps the FP8 Triton-style launch paths so they run under the tensor's CUDA/XPU device context.
Changes
_fp8_triton_device_contextinfp8.py.weight_dequant_kernelinweight_dequant_block.act_quant_kernelinact_quant._w8a8_block_fp8_matmulinw8a8_block_fp8_matmul_triton.triton_quantize_fp8_blockin the FBGEMM block path.The helper is local instead of importing
torch_gpu_devicefromunsloth.kernels.utilsbecauseutils.pyalready importsfp8.py, so importing back fromutils.pywould risk a circular import.Tests
Passed locally:
Repo default pytest selection:
Larger bounded CPU/static suite:
The three skipped tests are CUDA/Triton runtime checks that require a 2+ GPU CUDA environment. I could not run those locally because this machine has no CUDA GPUs and Triton is not installable on macOS, but the tests are included for maintainers/CI with suitable hardware.