Skip to content

perf(glm5next): select KDA backend per server - #495

Closed
voipmonitor wants to merge 4 commits into
dev/jovian-judgementfrom
codex/glm53-kda-backend-20260828
Closed

perf(glm5next): select KDA backend per server#495
voipmonitor wants to merge 4 commits into
dev/jovian-judgementfrom
codex/glm53-kda-backend-20260828

Conversation

@voipmonitor

@voipmonitor voipmonitor commented Aug 28, 2026

Copy link
Copy Markdown

Resulting behavior

Status: implemented and qualified for GLM-5.3 tensor-parallel serving at tensor parallel size 4.

vLLM creates a B12X KDA binding from caller-owned scratch for each invocation. No binding outlives recyclable workspace scratch or scheduler-owned recurrent state.

GLM-5.3 selects one KDA implementation for the lifetime of a server:

  • automatic selection uses the packed Triton KDA path when speculative decoding is disabled;
  • automatic selection uses B12X when MTP or DFlash speculation is configured, preserving B12X checkpoint selection and rejected-draft rollback;
  • glm53_kda_decode_backend=triton|b12x provides an explicit qualification and diagnostic override.

Keeping one implementation for the recurrent cache lifetime prevents differences in BF16 operation order from changing later speculative acceptance.

Source contract

  • Base: local-inference-lab/vllm:dev/jovian-judgement at c79f35ca00e8e93e0943a0d79b85b22b18aac939.
  • Head: da60b74f2a6aadbb0dcb53a97590b159fae96431.
  • B12X uses plan.bind(scratch=...) on every invocation. vLLM does not cache a B12X workspace, arena, or binding.
  • Prefill retains the established packed Triton chunk path.

Validation

  • tests/models/test_glm5next_model.py -k 'kda or b12x': 15 passed, 24 deselected.
  • Direct BF16 comparison against the B12X operation reference passed for batch 1 over 64 recurrent steps and for batch 16.
  • Repository pre-commit hooks, including Ruff, mypy, SPDX, forbidden-import, and configuration checks: passed.
  • git diff --check: passed.
  • TP4 target-only serving with Triton KDA and B12X PCIe all-reduce sustained 140.30 output tokens/s at concurrency 1 for 30 seconds.
  • The composed DFlash2 runtime used B12X KDA, completed full-graph capture, and sustained 987.69 output tokens/s at concurrency 16 for 30 seconds with zero request errors.

Duplicate-work check

local-inference-lab/vllm#490 integrates the proposed public run_kda_single_token API from local-inference-lab/b12x#249 for ordinary non-speculative decode. This pull request does not add that API. It provides caller-scratch binding lifetime and server-stable backend selection, including speculative transaction semantics. The direct B12X single-token optimization can be implemented later as an internal B12X route without changing this server-lifetime contract.

Open upstream vLLM pull requests were searched for GLM KDA, B12X, and Triton backend selection. No open upstream pull request implements this contract.

Review disclosure

OpenAI Codex assisted with implementation, kernel comparison, tests, profiling, benchmarking, and pull-request preparation. Human review of every changed line and the recurrent-state contract is required before merge.

Summary by CodeRabbit

  • New Features
    • Added configurable GLM-5.3 KDA decode backends: automatic, B12X, or Triton.
    • Added speculative decoding support for automatic backend selection.
    • Improved decode execution with direct tensor processing when capacity allows.
    • Added validation for unsupported backend selections and oversized requests.
  • Bug Fixes
    • Improved KDA decode setup and backend selection reliability across supported configurations.

GLM KDA decode retains the shape plan and creates a fresh B12X binding for each call from vLLM workspace scratch. This prevents a binding from outliving recyclable scratch or KV-cache state while leaving non-B12X and prefill paths unchanged.

Validation: tests/models/test_glm5next_model.py (26 passed); ruff check and format check.

Assisted-by: OpenAI Codex <codex@openai.com>

Signed-off-by: Martin Vit <martin@voipmonitor.org>
Use the packed Triton KDA path for plain GLM-5.3 decode and the B12X KDA path for speculative decode by default. Plain decode avoids B12X metadata staging and validation overhead, while speculative decode retains B12X checkpoint selection and rollback handling.

Expose glm53_kda_decode_backend=auto|b12x|triton through additional_config. The default auto mode preserves B12X initialization for speculative requests; explicit values remain available for qualification and diagnosis. Unknown values fail during model construction.

Validation: six targeted GLM model tests; Ruff check and format; direct BF16 kernel comparison against the B12X reference for batch 1 over 64 sequential steps and batch 16; TP4 W4A4 decode benchmarks on physical GPUs 4-7.

Signed-off-by: Martin Vit <martin@voipmonitor.org>
Select one KDA implementation for the lifetime of every recurrent cache. Auto mode uses Triton when speculative decoding is disabled and B12X when an MTP or DFlash configuration is present. Explicit b12x and triton selections remain unchanged.

Both implementations satisfy the BF16 operation reference, but switching their rounding behavior between plain and speculative steps changes subsequent draft acceptance. A server-level choice preserves stable recurrent-state behavior and retains the qualified speculative rollback path.

Compatibility: the additional_config interface remains glm53_kda_decode_backend=auto|b12x|triton. Validation: nine targeted GLM model tests, Ruff check and format, and git diff validation.

Signed-off-by: Martin Vit <martin@voipmonitor.org>
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d1e6755b-23bb-4e1a-980d-e14884ceb8e1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d72f9d5f-284b-49bb-866e-249220abf3f6

📥 Commits

Reviewing files that changed from the base of the PR and between c79f35c and 41dbe99.

📒 Files selected for processing (3)
  • tests/models/test_glm5next_model.py
  • vllm/model_executor/layers/mamba/gdn/kimi_gdn_linear_attn.py
  • vllm/models/glm5next/nvidia/kda.py

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

GLM-5.3 KDA now validates backend configuration and selects B12X decoding for supported cases. B12X decoding stores a reusable plan, acquires workspace scratch buffers per call, supports direct tensor binding, and validates token capacity.

Changes

GLM-5.3 KDA decode

Layer / File(s) Summary
Backend selection and validation
vllm/models/glm5next/nvidia/kda.py, tests/models/test_glm5next_model.py
The adapter validates glm53_kda_decode_backend, applies auto, b12x, and triton behavior, and tests default, configured, and invalid values.
Per-cache KDA plan lifecycle
vllm/model_executor/layers/mamba/gdn/kimi_gdn_linear_attn.py, tests/models/test_glm5next_model.py
KDA cache binding now stores a plan instead of a pre-bound binding. Cache lifecycle checks and test setup use _b12x_kda_plan.
Workspace-backed decode execution
vllm/model_executor/layers/mamba/gdn/kimi_gdn_linear_attn.py, tests/models/test_glm5next_model.py
Decode validates token capacity, obtains scratch buffers from the workspace manager, binds caller tensors on the direct path, and uses scratch buffers otherwise. Tests verify direct speculative tensor binding.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: 🟡 Moderate · up to 41dbe

The change selects a server-stable KDA backend and uses per-invocation scratch, but some mutable execution buffers remain shared and rollback after interrupted or failed recurrent-state updates is not established. Overlapping requests or failures could mix request data or corrupt later decoding, so the PR is not merge-ready until those execution and recovery guarantees are explicitly ensured or accepted.

Sequence Diagram(s)

sequenceDiagram
  participant Attention as Glm5NextLinearAttention
  participant Workspace as current_workspace_manager
  participant API as B12X KDA API
  Attention->>Workspace: get_simultaneous(plan.shapes_and_dtypes())
  Workspace-->>Attention: scratch buffers
  Attention->>API: bind_kda(plan, caller tensors or scratch buffers)
  API-->>Attention: binding
  Attention->>API: run_kda(binding)
Loading

Suggested reviewers: lukealonso

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: server-level KDA backend selection for GLM-5.3.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/glm53-kda-backend-20260828

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Use the existing B12X binding contract for speculative verified-prefix tensors while preserving the established staged path for ordinary decode. Supply live token count from an independent caller-owned scalar so B12X can validate packed metadata end to end.

Co-authored-by: OpenAI Codex <codex@openai.com>
@voipmonitor

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@voipmonitor

Copy link
Copy Markdown
Author

Closed as not planned. The qualified GLM-5.3-Flash runtime keeps target KDA ownership in B12X instead of selecting Triton KDA for non-speculative serving. The B12X-only policy avoids maintaining two target-state implementations with different checkpoint and rollback contracts. This pull request is not part of the qualified merge checklist in issue #590.

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.

2 participants