Repository navigation
[Fix] moe: Fix flashinfer TRT-LLM BF16 expert weight reload on refit - #33743
Conversation
SGLang auto-selects flashinfer_trtllm on sm100 for bf16 MoE, but stock 0.5.12.post1 rewrites expert weights into a block layout that its weight-update path never undoes, so the first refit bucket dies with "size of tensor a (64) must match the size of tensor b (2048) at non-singleton dimension 2". Until now the recipe pinned moe_runner_backend to triton to avoid the block layout entirely. Apply the upstream fix (sgl-project/sglang#33743, fixing #27787) to the installed sglang during the image build. sglang arrives as a PyPI wheel whose srt/ tree is pure Python, so the fix needs no forked wheel; the applier patches every venv and the uv cache archive they link into, and hard-fails unless all of them carry it. The vendored file is the v0.5.12.post1 backport of that PR -- the PR targets main, where the hot-update paths have since moved -- and is executable-code-identical to it. Delete it once the fix is in the pinned SGLang release. Switch the 32n4g recipe to flashinfer_trtllm, which on GB200 at tp=2 decodes 11-30% faster than triton across batch sizes 1-32, and +17% at the ~2 concurrent requests per engine this recipe produces. Validated on GB200: bit-exact generation, max abs logprob delta 0.0, over an adversarially bucketed push of all 18867 checkpoint tensors for flashinfer_trtllm, flashinfer_trtllm_routed and triton; and 4/4 refits in a 32-node async-GRPO run (status=passed, world_size=65 engines=32). Also record the two load-bearing launch overrides the refit guide omitted. Signed-off-by: Serge Panev <[email protected]>
4bae2c9 to
3acb407
Compare
|
@Kh4L could you fix the conflicts? thanks! |
3acb407 to
14712d8
Compare
|
@Kh4L could you rebase/merge with main again? github action was broken |
…atch sglang 0.5.13 pulls its companions with it: sglang-kernel 0.4.3, flashinfer 0.6.12, transformers 5.8.1 and kernels >=0.14.1,<0.15. None of them resolve alone -- uv rejects the set until all seven move together. 0.5.13 still carries the bug (unquant.py gates the inverse transform on is_flashinfer_trtllm_routed() alone), and sgl-project/sglang#33743 is still open, so the vendored patch stays. But it has to be retargeted rather than carried over, because 0.5.13 sits between v0.5.12.post1 and upstream main: - it keeps the hot-update entry points in model_executor/model_runner.py, so that hunk is the v0.5.12.post1 one (main moved them to weight_updater.py) - it has already moved to the four-argument _maybe_get_cached_w3_w1_permute_indices(..., is_gated_act_gemm=...), so base_config.py and unquant.py come from the PR's main-branch version Force-applying the old backport with fuzz would have reverted that call to three arguments and changed the permutation for non-gated MoE models -- wrong weights, and no shape check would have caught it. One hunk exists in neither upstream form: replacing the inline flashinfer block in process_weights_after_loading with the extracted helper. Reconciled by hand against the 0.5.13 tree, then verified to apply cleanly to a pristine checkout, round-trip byte-exact, call the helper exactly once, and expose all six patch-added methods. The patch REPLACES rather than joins the old one: the applier globs *.patch and applies every file it finds, so two variants targeting the same source would conflict. Not yet exercised on hardware at 0.5.13 -- the GB200 evidence in the README is against the v0.5.12.post1 backport. Signed-off-by: Serge Panev <[email protected]>
14712d8 to
5cfc305
Compare
|
/tag-and-rerun-ci |
|
/rerun-failed-ci |
|
[by Claude Code] I've started babysitting the NVIDIA CI of this PR. I'll check it every 30 minutes until all NV pipelines pass. If a relevant job fails, I may rerun it, merge the latest Anyone can stop me at any time: just post a comment asking me to stop (for example, |
Picks up the required base commit c053fc7 from CI maintenance issue sgl-project#21065; the check-maintenance gate blocked CI with "Rebase Required" (https://github.com/sgl-project/sglang/actions/runs/38385372304/job/115426940043). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Picks up the updated required base commit ff8d964 from CI maintenance issue sgl-project#21065; the check-maintenance gate blocked CI with "Rebase Required" (https://github.com/sgl-project/sglang/actions/runs/38509251941/job/115677768029). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Picks up sgl-project#44235, which fixes the unrelated CI failure https://github.com/sgl-project/sglang/actions/runs/38517077591/job/115706713398 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ts on Blackwell (#8230) ### What does this PR do? Fixes #8229: on Blackwell, a bf16 SGLang rollout of a Qwen3-MoE model crashes at the first weight sync. On compute capability 10.x, SGLang resolves `moe_runner_backend=auto` to `flashinfer_trtllm` for unquantized Qwen3-MoE-family checkpoints. That runner keeps bf16 expert weights in a block layout, and `update_weights_from_tensor` restores the load-time shape only for `flashinfer_trtllm_routed`. The first sync therefore fails in `FusedMoE._load_w13` (`The size of tensor a (64) must match the size of tensor b (512)`), and the SGLang scheduler exits. Upstream: sgl-project/sglang#27787. It still reproduces on sglang 0.5.20 and 0.5.21; the fixes in sgl-project/sglang#33743 and sgl-project/sglang#44163 are not merged. This PR has verl ask SGLang for the Triton MoE runner under the same conditions in which SGLang picks `flashinfer_trtllm` on sm100 (its Qwen3-MoE- and DeepSeek-family rules), that is when all of the following hold: - neither the rollout nor the checkpoint is quantized: `rollout.quantization` is unset and the HF config has no `quantization_config`, which SGLang would detect on its own; - `engine_kwargs.sglang.moe_runner_backend` is unset or `auto`; - `engine_kwargs.sglang.moe_a2a_backend` is unset or `none`; - the GPU is CUDA with compute capability 10.x. Triton is the runner SGLang's unquantized MoE method falls back to everywhere else, and it takes weight updates. The following keep SGLang's own choice: - quantized rollouts or checkpoints; - an a2a backend; - an explicit runner; - Hopper and other GPUs; - ROCm. The architecture lists are not copied. On other architectures SGLang already lands on Triton, so the default changes nothing there. ### Checklist Before Starting - [x] Search for similar PRs. No open issue or PR covers this: - [moe_runner_backend](https://github.com/verl-project/verl/pulls?q=is%3Apr+moe_runner_backend) - [flashinfer_trtllm bf16](https://github.com/verl-project/verl/pulls?q=is%3Apr+flashinfer_trtllm+bf16) - [_load_w13](https://github.com/verl-project/verl/issues?q=_load_w13) The closest is #7978 (closed), the same failure mode on vLLM's TRT-LLM MoE backend. - [x] Format the PR title as `[{modules}] {type}: {description}` ### Test - **CPU unit test, run and then removed at review:** a 16-case test of `default_moe_runner_backend` (each condition above, `engine_kwargs` as an OmegaConf `DictConfig`, ROCm, and capabilities 9.0, 10.0, 10.3, 12.0 and unknown) passed locally: 25 passed together with `test_lora_merge_mode_on_cpu.py`. A maintainer asked to drop it, and `e8080be0` removes it. - **pre-commit on the changed files:** ruff, ruff format, mypy, license, docstring coverage, device API usage and test structure all pass. `autogen-trainer-cfg` could not run locally because hydra-core is missing there; no config file changes. - **On 1×B200**, this PR against its base on the same pod with the same config; nothing sets `moe_runner_backend`. Environment: verl main's `uv.lock` (sglang 0.5.20, flashinfer 0.6.18, TE 2.16.1, torch 2.13.0+cu130), Megatron backend, a random 2-layer Qwen3-MoE (8 experts), GSM8K, bf16 SGLang rollout, 4 steps. | verl | MoE runner | Result | |---|---|---| | this PR (`8b9ca7df`) | Triton, picked by this PR. Server log: `sglang moe_runner_backend=triton: SGLang's default on Blackwell cannot take bf16 weight updates (sgl-project/sglang#27787); ...` | 4/4 steps, exit 0. rollout_corr/kl by step: 1.8e-4, 6.1e-5, 1.2e-4, 4.3e-5 | | base main (`2bc6ac46`) | SGLang's default `flashinfer_trtllm` (the server autotunes `flashinfer::trtllm_bf16_moe`) | Fails at the first weight sync: `RuntimeError: The size of tensor a (64) must match the size of tensor b (512) at non-singleton dimension 2` in `FusedMoE._load_w13`, then "Scheduler hit an exception" and exit 1 | On that GPU (compute capability 10.0), `default_moe_runner_backend` returns `"triton"` for bf16, `None` for fp8, and `None` when a runner is set explicitly. These runs used `8b9ca7df`, before `1d2f5ad5` narrowed the conditions above. The validated case meets every one of them, so the result carries over: a bf16 rollout of an unquantized checkpoint, no a2a backend, runner unset. ### API and Usage Example No API change. To keep SGLang's own choice on Blackwell, set it explicitly, for example: ``` +actor_rollout_ref.rollout.engine_kwargs.sglang.moe_runner_backend=flashinfer_trtllm ``` ### Design & Code Changes - `verl/workers/rollout/sglang_rollout/utils.py`: new `default_moe_runner_backend(quantization, engine_kwargs, hf_config)`. It returns `"triton"` under the conditions listed above, and `None` otherwise, which keeps SGLang's choice. - `verl/workers/rollout/sglang_rollout/async_sglang_server.py`: `launch_server` passes the rollout quantization, `engine_kwargs` and the model's HF config, applies the result to the server args, and logs the choice. The default can be dropped once SGLang restores the layout for `flashinfer_trtllm` itself. ### Checklist Before Submitting - [x] Read the [Contribute Guide](https://github.com/verl-project/verl/blob/main/CONTRIBUTING.md). - [x] Apply pre-commit checks (see Test; `autogen-trainer-cfg` needs hydra-core, no config changes here). - [ ] Add / Update the documentation: not needed, no user-facing option changes. - [ ] Add unit test(s): none in the final diff; the CPU test was removed at review (see Test). - [ ] Once your PR is ready for CI, send a message in the `ci-request` channel. AI assistance was used for the investigation, the code change and this description. --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Picks up the sgl-project#21065 MIN_BASE_SHA b677851 (sgl-project#44303) and recent PD-disaggregation changes on main; the relevant CI failure https://github.com/sgl-project/sglang/actions/runs/38547120923/job/115994921014 is unrelated to this PR. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
[by Claude Code] I've started babysitting the NVIDIA CI of this PR. I'll check it every 30 minutes until all NV pipelines pass. If a relevant job fails, I may rerun it, merge the latest Anyone can stop me at any time: just post a comment asking me to stop (for example, |
|
[by Claude Code] All NV pipelines have passed. |
|
@Fridge003 could you help to review this change that is required for RL rollout? Thanks! |
Signed-off-by: Serge Panev <[email protected]>
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
|
@Fridge003 @ispobock could you review this? Thanks! |
|
Merging this since this is a low-risk, non-architectural change: only affecting unquant (BF16) MoE path with trtllm-gen backend. This is typically only used in RL. This PR fixes a long-standing RL failure when using SGLang rollout. Full CI has passed. |
|
Status: fixed on SGLang main since this PR (merged 2026-10-27); not yet in a release, no FlashInfer change needed. What we found: the first RL weight-sync crash in Next steps:
@wengeezhang @LLMShark: does either framework still need the override after this fix? |
…ts on Blackwell (verl-project#8230) ### What does this PR do? Fixes verl-project#8229: on Blackwell, a bf16 SGLang rollout of a Qwen3-MoE model crashes at the first weight sync. On compute capability 10.x, SGLang resolves `moe_runner_backend=auto` to `flashinfer_trtllm` for unquantized Qwen3-MoE-family checkpoints. That runner keeps bf16 expert weights in a block layout, and `update_weights_from_tensor` restores the load-time shape only for `flashinfer_trtllm_routed`. The first sync therefore fails in `FusedMoE._load_w13` (`The size of tensor a (64) must match the size of tensor b (512)`), and the SGLang scheduler exits. Upstream: sgl-project/sglang#27787. It still reproduces on sglang 0.5.20 and 0.5.21; the fixes in sgl-project/sglang#33743 and sgl-project/sglang#44163 are not merged. This PR has verl ask SGLang for the Triton MoE runner under the same conditions in which SGLang picks `flashinfer_trtllm` on sm100 (its Qwen3-MoE- and DeepSeek-family rules), that is when all of the following hold: - neither the rollout nor the checkpoint is quantized: `rollout.quantization` is unset and the HF config has no `quantization_config`, which SGLang would detect on its own; - `engine_kwargs.sglang.moe_runner_backend` is unset or `auto`; - `engine_kwargs.sglang.moe_a2a_backend` is unset or `none`; - the GPU is CUDA with compute capability 10.x. Triton is the runner SGLang's unquantized MoE method falls back to everywhere else, and it takes weight updates. The following keep SGLang's own choice: - quantized rollouts or checkpoints; - an a2a backend; - an explicit runner; - Hopper and other GPUs; - ROCm. The architecture lists are not copied. On other architectures SGLang already lands on Triton, so the default changes nothing there. ### Checklist Before Starting - [x] Search for similar PRs. No open issue or PR covers this: - [moe_runner_backend](https://github.com/verl-project/verl/pulls?q=is%3Apr+moe_runner_backend) - [flashinfer_trtllm bf16](https://github.com/verl-project/verl/pulls?q=is%3Apr+flashinfer_trtllm+bf16) - [_load_w13](https://github.com/verl-project/verl/issues?q=_load_w13) The closest is verl-project#7978 (closed), the same failure mode on vLLM's TRT-LLM MoE backend. - [x] Format the PR title as `[{modules}] {type}: {description}` ### Test - **CPU unit test, run and then removed at review:** a 16-case test of `default_moe_runner_backend` (each condition above, `engine_kwargs` as an OmegaConf `DictConfig`, ROCm, and capabilities 9.0, 10.0, 10.3, 12.0 and unknown) passed locally: 25 passed together with `test_lora_merge_mode_on_cpu.py`. A maintainer asked to drop it, and `e8080be0` removes it. - **pre-commit on the changed files:** ruff, ruff format, mypy, license, docstring coverage, device API usage and test structure all pass. `autogen-trainer-cfg` could not run locally because hydra-core is missing there; no config file changes. - **On 1×B200**, this PR against its base on the same pod with the same config; nothing sets `moe_runner_backend`. Environment: verl main's `uv.lock` (sglang 0.5.20, flashinfer 0.6.18, TE 2.16.1, torch 2.13.0+cu130), Megatron backend, a random 2-layer Qwen3-MoE (8 experts), GSM8K, bf16 SGLang rollout, 4 steps. | verl | MoE runner | Result | |---|---|---| | this PR (`8b9ca7df`) | Triton, picked by this PR. Server log: `sglang moe_runner_backend=triton: SGLang's default on Blackwell cannot take bf16 weight updates (sgl-project/sglang#27787); ...` | 4/4 steps, exit 0. rollout_corr/kl by step: 1.8e-4, 6.1e-5, 1.2e-4, 4.3e-5 | | base main (`2bc6ac46`) | SGLang's default `flashinfer_trtllm` (the server autotunes `flashinfer::trtllm_bf16_moe`) | Fails at the first weight sync: `RuntimeError: The size of tensor a (64) must match the size of tensor b (512) at non-singleton dimension 2` in `FusedMoE._load_w13`, then "Scheduler hit an exception" and exit 1 | On that GPU (compute capability 10.0), `default_moe_runner_backend` returns `"triton"` for bf16, `None` for fp8, and `None` when a runner is set explicitly. These runs used `8b9ca7df`, before `1d2f5ad5` narrowed the conditions above. The validated case meets every one of them, so the result carries over: a bf16 rollout of an unquantized checkpoint, no a2a backend, runner unset. ### API and Usage Example No API change. To keep SGLang's own choice on Blackwell, set it explicitly, for example: ``` +actor_rollout_ref.rollout.engine_kwargs.sglang.moe_runner_backend=flashinfer_trtllm ``` ### Design & Code Changes - `verl/workers/rollout/sglang_rollout/utils.py`: new `default_moe_runner_backend(quantization, engine_kwargs, hf_config)`. It returns `"triton"` under the conditions listed above, and `None` otherwise, which keeps SGLang's choice. - `verl/workers/rollout/sglang_rollout/async_sglang_server.py`: `launch_server` passes the rollout quantization, `engine_kwargs` and the model's HF config, applies the result to the server args, and logs the choice. The default can be dropped once SGLang restores the layout for `flashinfer_trtllm` itself. ### Checklist Before Submitting - [x] Read the [Contribute Guide](https://github.com/verl-project/verl/blob/main/CONTRIBUTING.md). - [x] Apply pre-commit checks (see Test; `autogen-trainer-cfg` needs hydra-core, no config changes here). - [ ] Add / Update the documentation: not needed, no user-facing option changes. - [ ] Add unit test(s): none in the final diff; the CPU test was removed at review (see Test). - [ ] Once your PR is ready for CI, send a message in the `ci-request` channel. AI assistance was used for the investigation, the code change and this description. --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Motivation
BF16 MoE expert weights are converted to the FlashInfer TRT-LLM BlockMajorK
layout on cold load. The inverse restore previously ran only for the routed
backend, although both
flashinfer_trtllmandflashinfer_trtllm_routedusethe transform. A subsequent checkpoint-format copy into a blocked parameter
can therefore fail with:
A shape-only restore is insufficient: unchanged expert values must also be
returned to checkpoint order before the next pack, or repeated refits can
silently scramble them.
Fixes #27787
Modifications
use_flashinfer_trtllm_moe, matching the transform forboth routed and non-routed BF16 backends.
storage and rejecting non-bijective row permutations or wrong element counts.
restore_weights_before_loadingsobegin_weight_updaterestoresboth expert parameters for direct tensor and P2P/RDMA writes that bypass
model weight loaders. Retain loader-side restoration for disk reloads,
which do not open a weight-update session.
layout, while already-blocked weights remain unchanged. The existing
end_weight_updatefinalizes once per session, not once per bucket, usingthe existing LoRA-aware model-loader traversal. No new updater/base hook or
per-bucket
finallycallback is introduced.Files changed relative to main:
python/sglang/srt/layers/quantization/unquant.pyandtest/registered/unit/layers/quantization/test_flashinfer_trtllm_bf16_moe_reload.py.Accuracy Tests
The CPU-registered unit file contains 10 test methods. It covers exact layout
round trips, bucketed tensor/flattened/distributed updates, mixed
canonical/blocked parameters, unchanged and inactive-backend behavior, invalid
permutations and element counts, LoRA-wrapped traversal, and three successive
loader-free refits through both direct tensor updates and simulated P2P flat
copies. Runtime topology is scoped with
get_parallel().override(tp_rank=0).Loader-free tests assert exact cold-load byte equality and unchanged storage
pointers, while forbidding any call to the model weight loader.
October 5 validation of commit
493fab0f593649c3c22a19302bab1b597a70aada,including main
70f0b7351e74b372cc928db533824d3993d65922: all 10 methods and5 format subtests pass, plus 22 nearby session/cache-guard methods. Controls
reproduce the three pre-fix TP-rank failures and fail the new loader-free case
in both formats when only the production restore hook is removed. Native XML,
exact source hashes and terminal accounting were independently checked;
all applicable pinned pre-commit hooks pass.
FlashInfer's layout entry points are deterministic, order-changing CPU
stand-ins; this is not on-device kernel accuracy, real RDMA transport, or
end-to-end RL validation.
Speed Tests and Profiling
No speed benchmark is claimed. Forward kernels are unchanged. Canonical restore
and pack are paid once per weight-update session; disk reloads retain their
existing load/postprocess lifecycle. This fixes representation correctness,
not rollback of partially written weight values.
Checklist
Review and Merge Process
Required review and green CI remain necessary. Full upstream GPU CI needs a
maintainer to restore the
run-cigate; no fresh GPU CI success is claimed.CI States
Latest PR Test (Base): ✅ Run #39687984610
Latest PR Test (Extra): ❌ Run #39687984537
Latest PR Test (AMD ROCm 10): ❌ Run #39687984561