Repository navigation
Conversation
… Intel XPU (Triton >= 3.9)
- select the tile only when every visible XPU maps to the same tile - keep the import hook until the kernels module actually executes - restore Triton's allocator ContextVar after each test - add tests for a mixed host, a same-tile host and a spec-only lookup
…nels module is half imported - wait for a concurrent import of verl.utils.kernel.kernels to finish - patch only once the tiled kernels exist; otherwise leave a retry possible - set the applied flag only after the patch or the import hook is in place - add tests for a half-imported module and a failed patch
…_cross_entropy layout too verl is moving verl.utils.kernel.kernels to verl.utils.kernel.linear_cross_entropy.triton.kernels; accept either module name for both the loaded-module path and the import hook.
… in verl main verl #8888 merged with the kernels at verl.utils.kernel.linear_cross_entropy.triton.lce_cuda. Drop the fallback to the two earlier module names; only the merged path is patched.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
noticed changes, will continue monitor the final workable.
after 8888,
https://github.com/verl-project/verl/pull/ 8926
What does this PR do?
Makes verl's own fused Triton lm_head + log-prob/entropy kernels (
use_fused_kernels=True,impl_backend=triton) fast on Intel XPU. It is a platform patch; nothing changes in verl core.On XPU the stock kernel is about 10x slower than it should be: 1.3-1.5 s for 4096 tokens, forward + backward, on a B60 (1.14 s on a B70). Its matrix tiles load through pointer arithmetic, which Intel's Triton does not lower to 2D block loads. The same file already has a tensor-descriptor path (
SUPPORT_CUDA_TMA), but it is enabled only for CUDA devices of compute capability >= 9.patches/fused_logprob_patch.py, applied fromPlatformXPU.__init__like the other XPU patches, changes verl's kernels module after it is imported, under either name (verl.utils.kernel.kernelstoday,verl.utils.kernel.linear_cross_entropy.triton.kernelsin the layout of verl #8888) (at once if it is loaded, otherwise through a one-shot import hook):SUPPORT_CUDA_TMA = True, which turns on verl's existing tensor-descriptor path;triton.set_allocator, which tensor descriptors need and which the module sets only for CUDA, at import time;d_logits_split_N) with a per-device tile.When it applies
It is a no-op, and logs the reason at INFO, unless all of these hold. In every other case verl's kernels run unchanged.
tl.make_tensor_descriptorexists (ships with the torch 2.15 XPU wheels)_TILESand all of them map to one tile (today B60 and B70)VERL_XPU_FUSED_LOGPROB_PATCHis not0VERL_XPU_FUSED_LOGPROB_TILE="BM,BN,BK,warps,stages"overrides the table, so a device without a row can be tried without a code change. Adding a device means adding one row after a tile sweep; a device that renames itself simply stops matching and falls back to verl's behaviour.Tiles in the table (
BLOCK_SIZE_M, N, K, num_warps, num_stages): B6064, 128, 32, 16, 2; B7064, 128, 32, 16, 2(the same tile, from its own sweep).Measurements
Shapes: hidden 1536, vocab 151936, bf16, forward + backward, one card. Triton 3.9.0 for all numbers. B60: torch 2.15.0+xpu
64, 64, 32, 8, 2, is not clearly better, so the tile that went through the GRPO run was kept.64, 128, 32, 16, 3, 355-356 ms). Other tiles are slower:128, 128, 32, 16, 294 ms at 4096 and 422 ms at 16384, and verl's own default tile on the tensor-descriptor path 456 ms at 4096. So the B70 row reuses the B60 tile. The tile still matters: it should not be left at verl's default once the descriptor path is on.tl.make_block_ptr, the older fast path on Triton 3.8, fails to compile on Triton 3.9.Testing
pytest tests/accelerators/xpu/test_fused_logprob_patch_xpu.py: 18 passed on a B60 pod at the current head (also 11 and 12 passed at earlier heads, on B60 and B70). Fake kernel modules; covers every gate, the kill switch, the override, a bad override, idempotence, the import hook, both table rows, both module names, a mixed-device host, a half-imported module and a failed patch that can be retried.linear_cross_entropyforward + backward at 512 and 4096 tokens, 125 ms at 4096.64, 128, 32, 16, 2, andlinear_cross_entropyforward + backward takes 85.5 ms at 4096 and 348.7 ms at 16384 tokens. The patch is also applied when the plugin is only discovered throughimport verl(entry point), without constructingPlatformXPU()by hand.tests/utils/test_linear_cross_entropy.py(includes entropy gradients) passed on B60 with the tensor-descriptor path forced on (patched as a source edit, same tile).check_storage_all) passes cases 0-3 and a reduced case 4 (4096 tokens instead of 8192). Two things in verl main's test, both independent of this patch: its reference helperrun_verl_original_entropyfails with the patch off as well (labels are not squeezed,torch.gatherrejects the index shape), so the run wrapped that one helper and left everything else unmodified; and case 4 at 8192 tokens runs out of memory in the test's own fp32 reference on a 32 GiB card, with or without the patch. The patched runs forced the same tile throughVERL_XPU_FUSED_LOGPROB_TILE, because the B70 row did not exist yet.gpu_memory_utilization=0.5): 16 of 16 runs reached step 1 with the patch's stack (OMIX 0.5.0, one card).1a01002, its Triton package overlaid onto the image's verl, B60): the patch finds...linear_cross_entropy.triton.kernelsand the fused kernel takes 126 ms at 4096 tokens against 1494 ms with the patch off, with the same accuracy. This needed one change that #8888 does not have: its_get_backend_kernelsaccepts onlycudaandnpu, so on XPU it raisesValueError: Unsupported device type: xpu. Mappingxputo the CUDA Triton kernels there fixes it (tried in a local copy).Not covered
Checklist
ruff checkandruff format --checkpassdocs/accelerators/xpu/README.md)