Skip to content

[diffusion][model] Add LingBot-Video MoE 30B T2V support - #32341

Merged
mickqian merged 23 commits into
sgl-project:mainfrom
pandalee99:feat/lingbot-video-moe-30b
Aug 7, 2026
Merged

mickqian merged 23 commits into
sgl-project:mainfrom
pandalee99:feat/lingbot-video-moe-30b

Conversation

@pandalee99

@pandalee99 pandalee99 commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Add native SGLang support for LingBot-Video MoE 30B (robbyant/lingbot-video-moe-30b-a3b) — a DeepSeek-V3-style MoE text-to-video model (128 experts, 30B total / ~3B active per token, 48 MoE layers). This is the first MoE DiT in multimodal_gen, reusing SGLang's fused_experts Triton kernel for the expert GEMMs.

Related issue: #32336

Modifications

  • runtime/layers/moe.py (NEW): DeepSeek-V3-style MoE FFN block — LingBotVideoRouter (fp32, group-limited top-k, sigmoid + e_score_correction_bias), LingBotVideoGroupedExperts (w1/w2/w3 nn.Parameter), LingBotVideoSparseMoeBlock reusing sglang.srt.layers.moe...fused_experts. First MoE layer in the diffusion runtime. Parity-critical config: gate_up_interleaved=False, inplace=False.
  • runtime/models/dits/lingbot_video_moe.py (NEW): LingBotVideoTransformer3DModel (joint self-attn over [video;text], complex64 RoPE via view_as_complex, AdaLN with fp32-sensitive modules). LingBotVideoAttention (SDPA + complex RoPE), LingBotVideoBlock.
  • configs/models/dits/lingbot_video_moe.py (NEW): LingBotVideoMoEArchConfig (30B arch + identity param_names_mapping).
  • configs/pipeline_configs/lingbot_video_moe.py (NEW): LingBotVideoMoEPipelineConfig (T2V, get_decode_scale_and_shift reading vae.config).
  • configs/sample/lingbot_video_moe.py (NEW): LingBotVideoMoESamplingParams.
  • runtime/pipelines_core/stages/model_specific_stages/lingbot_video_moe/ (NEW): LingBotVideoBeforeDenoisingStage (Hybrid monolithic: encode_prompt + Qwen3-VL + PROMPT_TEMPLATE, prepare_latents, FlowUniPC).
  • runtime/pipelines/lingbot_video_moe.py (NEW): LingBotVideoPipeline (EntryClass).
  • registry.py (MODIFIED): register_configs(...) entry.
  • configs/models/dits/__init__.py, configs/pipeline_configs/__init__.py, configs/sample/__init__.py (MODIFIED): exports.

Usage

# 32GB GPU (offload):
CUDA_VISIBLE_DEVICES=0 sglang serve robbyant/lingbot-video-moe-30b-a3b \
  --num-gpus 1 --dit-layerwise-offload --warmup-mode off

# 80GB+ GPU (resident):
CUDA_VISIBLE_DEVICES=0 sglang serve robbyant/lingbot-video-moe-30b-a3b --num-gpus 1
curl http://localhost:30000/v1/videos \
  -F "model=robbyant/lingbot-video-moe-30b-a3b" \
  -F "prompt=<structured JSON caption>" \
  -F "size=320x192" -F "num_frames=241" -F "fps=24" \
  -F "num_inference_steps=40" -F "guidance_scale=6.0" \
  -F "flow_shift=3.0" -F "seed=42"

Note: The DiT is trained on structured JSON captions (from the prompt-rewriter). Raw natural-language prompts are out-of-distribution. The prompt field should carry a structured JSON caption (e.g., the rewriter's output from the upstream assets/cases/t2v/example_1/prompt.json).

Accuracy Tests

Verified output precision against the upstream LingBotVideoPipeline (diffusers) with identical parameters: same prompt (structured JSON caption), seed (42), resolution (320×192), num_frames (241), steps (40), guidance_scale (6.0), shift (3.0).

Hardware Time Notes
SGLang (this PR) RTX 5090 (32GB, --dit-layerwise-offload) 115s DiT blocks streamed from CPU
SGLang (this PR) H100 80GB (resident) 70s No offload
Upstream (diffusers) H100 80GB (resident) 85s Original LingBotVideoPipeline

Both SGLang and the upstream produce coherent video (cat running on grass, 10s, 320×192, 241 frames) at the same settings.

Output Videos

SGLang (this PR, H100 80GB):

sglang_10s_h100.mp4

SGLang (this PR, RTX 5090 32GB, --dit-layerwise-offload):

sglang_10s_5090.mp4

Upstream LingBotVideoPipeline (diffusers, H100 80GB, reference):

upstream_10s_h100.mp4

All three videos are generated with identical parameters: same structured JSON caption ("a cat running on grass"), seed (42), resolution (320×192), num_frames (241), steps (40), guidance_scale (6.0), shift (3.0).

Note on Minor Output Differences

The SGLang output and the upstream output show slightly different camera movement and action trajectory, while the scene content (the cat, the grass, the overall composition) is fully consistent with the prompt. The differences come from two BF16 numerical sources:

  1. MoE expert GEMM kernel: SGLang uses fused_experts (srt Triton kernel with gate_up_interleaved=False, inplace=False), while the upstream uses torch._grouped_mm (or a per-expert loop). These are different implementations of the same grouped GEMM math, with BF16 accumulation-order differences that compound across 48 MoE layers × 40 denoise steps.

  2. Attention backend: SGLang uses F.scaled_dot_product_attention with auto backend selection (flash SDP on Hopper), while the upstream uses diffusers dispatch_attention_fn with _native_flash (sdpa_kernel(SDPBackend.FLASH_ATTENTION)). The two paths use different SDP dispatch logic, introducing BF16 rounding differences before MoE routing, which accumulates over steps.

These are expected BF16 inference-level differences (not correctness bugs). The scene content, prompt adherence, and overall quality are equivalent.

  • ruff check: All checks passed.
  • ruff format: All files formatted.
  • Follows the sglang-diffusion-add-model skill (Hybrid Monolithic pipeline, EntryClass, ComposedPipelineBase, Req batch contract).

Future Work

To reduce review difficulty, this PR implements T2V base-only, single-GPU. Follow-up PRs will add:

  • Multi-GPU: TP/SP/FSDP (swap plain nn.Linear → ColumnParallelLinear, SDPA → USPAttention; integrate complex64 RoPE with Ulysses).
  • Refiner: the 1080p upscaling stage (the model includes a refiner/ DiT with identical MoE architecture; wired via the low-noise-tail t_thresh mechanism).
  • Prompt rewriter: the two-stage Qwen3.6-27B rewriter (raw prompt → structured JSON caption) as a preprocessing service.
  • The srt bridge (_ensure_moe_server_args, _ensure_srt_distributed) is a pragmatic workaround; a framework-level fix (the multimodal_gen worker initializing the srt parallel_state when using fused_experts) would replace these.

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ✅ Run #31158986364
Latest PR Test (Extra): ❌ Run #31158986144

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@github-actions github-actions Bot added the diffusion SGLang Diffusion label Jul 24, 2026
Signed-off-by: Pan Li <[email protected]>
Signed-off-by: Pan Li <[email protected]>
Signed-off-by: Pan Li <[email protected]>
@pandalee99

Copy link
Copy Markdown
Contributor Author

Hey mickqian, all are done. Re-ran a dog video ("a dog running on grass",320×192/241f/40steps/gs6/shift3/seed42) .

  • replaced the complex64 RoPE + manual SDPA with NDRotaryEmbedding + _apply_rotary_emb + USPAttention; q/k/v/out now use ColumnParallelLinear/RowParallelLinear.
  • dropped the monolithic BeforeDenoisingStage for LingBotVideoTextEncodingStage + the standard latent/timestep/decoding stages.

Speed :

Hardware Time
sglang (this PR) RTX 5090 32GB (--dit-layerwise-offload) 110s
sglang (this PR) H100 80GB (resident) 70s
original diffusers H100 80GB (resident) 83s

Videos:

sglang_dog_10s_5090.mp4
sglang_dog_10s_h100.mp4
orig_dog_10s_h100.mp4

@pandalee99

Copy link
Copy Markdown
Contributor Author

Hi @mickqian, I've addressed the review comments and also added unit tests plus a GPU quality case, ready for review now.

@mickqian mickqian left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The native MoE hot path needs another pass before merge.

  1. torch.cat((self.experts.w1, self.experts.w3), dim=1) runs in every MoE block forward. At the current BF16 shape, it materializes [128, 1536, 2048] (768 MiB) per invocation. Across 48 blocks and 40 denoising steps this adds substantial HBM copies and allocator pressure. Please pack/load w13 in the fused-kernel layout once, or cache it with correct invalidation for LoRA and other weight updates, instead of concatenating on every forward.

  2. text_lens.detach().cpu().tolist() synchronizes the GPU on every denoising step, and the B > 1 path dispatches attention once per sample. Please keep the text-length/RoPE preparation on-device or cache it for the request shape, then verify whether a batched/varlen attention path preserves parity. This will otherwise hurt CFG and batched serving latency.

The SRT TP-group bridge itself looks justified; no change requested there.

@pandalee99

Copy link
Copy Markdown
Contributor Author

@mickqian You have reviewed this point very patiently. Thank you!
both fair points, Fixed:

  • w13 is one param loaded once at load time; the per-forward cat is gone, and layerwise offload handles it like any other param.
  • RoPE is built on-device in one shot, so the per-step sync and the per-sample loop are gone; B>1 attention is one batched call. Output is byte-identical to before.

5090, dog video:

code RTX 5090 32GB
before 110s
after 105s

Video, same as before:

dog.mp4

@mickqian

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Jul 28, 2026
@pandalee99

Copy link
Copy Markdown
Contributor Author

Hey,@mickqian . CI fails in test_update_weights_from_disk.py on FLUX.2 and Qwen-Image, a weight-name mapping mismatch in linear.py. This PR touches neither that file nor weights_updater.py, and LingBot is absent from the log. Is this known on main? Happy to rebase and re-run.

@pandalee99

Copy link
Copy Markdown
Contributor Author

The current CI jobs are all failing after a few seconds. It seems like some label is missing, even though the checks appear to have passed.

@mickqian
mickqian merged commit a42683e into sgl-project:main Aug 7, 2026
124 of 136 checks passed
saturn-acc pushed a commit to saturn-acc/sglang that referenced this pull request Aug 16, 2026
Atituiset pushed a commit to Atituiset/sglang that referenced this pull request Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diffusion SGLang Diffusion run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants