Skip to content

[XPU] feat: enable faster fused log-prob/entropy kernel for intel triton - #198

Draft
kahlun wants to merge 6 commits into
verl-project:mainfrom
kahlun:feature/xpu-fused-logprob-nocri
Draft

kahlun wants to merge 6 commits into
verl-project:mainfrom
kahlun:feature/xpu-fused-logprob-nocri

Conversation

@kahlun

@kahlun kahlun commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

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 from PlatformXPU.__init__ like the other XPU patches, changes verl's kernels module after it is imported, under either name (verl.utils.kernel.kernels today, verl.utils.kernel.linear_cross_entropy.triton.kernels in the layout of verl #8888) (at once if it is loaded, otherwise through a one-shot import hook):

  • sets SUPPORT_CUDA_TMA = True, which turns on verl's existing tensor-descriptor path;
  • calls triton.set_allocator, which tensor descriptors need and which the module sets only for CUDA, at import time;
  • replaces the one hard-coded NVIDIA autotune tile of the two matmul kernels (forward main loop, 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.

Gate Why
Triton >= 3.9 and tl.make_tensor_descriptor exists (ships with the torch 2.15 XPU wheels) on Triton 3.8 (torch 2.14) the tensor-descriptor path is 13x slower than block pointers (7 vs 96 TFLOPS on B60), so it stays off. The stock kernel runs there, slowly
Every visible XPU name contains a key of _TILES and all of them map to one tile (today B60 and B70) a tile does not always transfer between devices (on B70 the B60 tile was best or tied in a sweep, so B70 has its own row holding the same tile), and Ray may pin a worker to any physical index, so a mixed host keeps verl's defaults
VERL_XPU_FUSED_LOGPROB_PATCH is not 0 kill switch

VERL_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): B60 64, 128, 32, 16, 2; B70 64, 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

Device, tokens stock verl Triton with this patch chunked vendor-GEMM reference floor (4 vendor GEMMs)
B60, 4096 326-336 ms with the best tile found for the pointer path; 1262-1476 ms with verl's default tile 121-131 ms ~120 ms ~88 ms
B60, 16384 1382 ms 498-612 ms 469 ms ~330 ms
B60, 32768 not measured ~1010 ms not measured ~650 ms
B70, 4096 1144 ms (verl's default tile) 84-87 ms not comparable, see below ~64 ms
B70, 16384 not measured 349-353 ms not comparable, see below ~246 ms
  • The stock column shows two numbers on purpose: retuning the tile alone gets the pointer path to about 330 ms on B60, still 2.7x slower than this patch.
  • Outputs match the stock kernel (dh relative difference about 7e-6 on B60, 8e-6 on B70; log-prob identical on B60, max difference 1e-6 on B70). Against an fp32 reference through the plugin on B60: log-prob max error 1.9e-6, dh 4.9e-3, dW 5.3e-4, which is verl's own bf16 backward accuracy. On B70 (1024 tokens): log-prob max absolute error 2.9e-6, dh relative error 7.1e-3, dW relative error 3.5e-4, the same values for the stock kernel and the patched one.
  • B60 tile check: a sweep of 18 tiles at 4096, 16384 and 32768 tokens. The chosen tile is within 8% of the best at 4096 tokens and within 1% at 16384 and 32768; the best tile there, 64, 64, 32, 8, 2, is not clearly better, so the tile that went through the GRPO run was kept.
  • B70 tile check: a sweep of 20 tiles at 4096 tokens, then the top 6 re-run at 4096 and 16384 tokens in forward and in reverse order (10 timed iterations each). At 4096 four tiles tie at 86-88 ms, the B60 tile among them. At 16384 the B60 tile is the fastest, 351 and 353 ms in the two orders, about 1% ahead of the next (64, 128, 32, 16, 3, 355-356 ms). Other tiles are slower: 128, 128, 32, 16, 2 94 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.
  • B70 "chunked reference" is left out on purpose: a chunked reference written for this run took 155 / 614 ms, but it is not the implementation behind the B60 numbers, so the figures are not comparable. The B70 floor is four vendor GEMMs of these shapes (forward, recompute, dh, dW).
  • Why tensor descriptors: a plain Triton matmul with them reaches 93.7 TFLOPS on B60 (vendor GEMM 93.0). 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.
  • Real verl kernels on the same B60, patch applied before verl imports its kernels (the production order): linear_cross_entropy forward + backward at 512 and 4096 tokens, 125 ms at 4096.
  • Real verl kernels on the B70 at the current head, no environment override: the log shows the descriptor path on with tile 64, 128, 32, 16, 2, and linear_cross_entropy forward + 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 through import verl (entry point), without constructing PlatformXPU() by hand.
  • verl's 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).
  • The same test on B70, with the patch and without it: its main loop (forward, entropy-gradient backward, 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 helper run_verl_original_entropy fails with the patch off as well (labels are not squeezed, torch.gather rejects 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 through VERL_XPU_FUSED_LOGPROB_TILE, because the B70 row did not exist yet.
  • Real GRPO, 2x B60, Qwen2.5-1.5B, batch 32 x n8, FSDP, 3 steps: micro-batch 2 steady step 111-115 s, micro-batch 8 steady step 56-62 s, grad_norm 0.6-0.9, healthy metrics. The default non-fused route ran out of memory at micro-batch 2 on this image. The stock fused kernel took 474 s for step 1 and was stopped before steady state, so there is no steady-state comparison for it.
  • LoRA GRPO (Qwen2.5-0.5B, rank 16, one B60, one step, gpu_memory_utilization=0.5): 16 of 16 runs reached step 1 with the patch's stack (OMIX 0.5.0, one card).
  • Layout of verl #8888 (head 1a01002, its Triton package overlaid onto the image's verl, B60): the patch finds ...linear_cross_entropy.triton.kernels and 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_kernels accepts only cuda and npu, so on XPU it raises ValueError: Unsupported device type: xpu. Mapping xpu to the CUDA Triton kernels there fixes it (tried in a local copy).

Not covered

  • Other Intel GPUs (B50, B580 and others): no row, they keep verl's behaviour.
  • Multi-GPU runs on OMIX 0.5.0 (Intel lists a multi-GPU host-copy regression in its release notes); the runs above use one or two cards.
  • Hidden sizes other than 1536, any quality or reward curve, more than 3 GRPO steps, multi-node, tensor-parallel lm_head, torch 2.14 (off by design).
  • verl #8888 beyond its Triton package (not run: TileLang, Liger, Ascend).

Checklist

  • ruff check and ruff format --check pass
  • Documentation updated (docs/accelerators/xpu/README.md)
  • No secrets or credentials included

- 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
@kahlun kahlun changed the title Feature/xpu fused logprob nocri [XPU] feat: enable faster fused log-prob/entropy kernel for intel triton Nov 27, 2026
…_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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant