Skip to content

feat(pytorch): add glm5.3-flash support - #4968

Draft
qescccczmr wants to merge 7 commits into
InternLM:mainfrom
qescccczmr:feat/glm5.3-flash-lmdeploy-reuse
Draft

qescccczmr wants to merge 7 commits into
InternLM:mainfrom
qescccczmr:feat/glm5.3-flash-lmdeploy-reuse

Conversation

@qescccczmr

@qescccczmr qescccczmr commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add GLM-5.3 Flash text/image/video integration to the PyTorch engine, prioritizing
existing LMDeploy components over model-specific kernel copies.

  • Register the architecture, native/legacy HF configuration, hybrid cache layout
    and multimodal frontend.
  • Reuse DeepSeek MLA/MoE loaders, standard TP projections, existing FA3 attention,
    HcPrePost, sparse-index Top-K, and the existing Triton blocked-FP8 MoE pipeline.
  • Add a thin backend-dispatched KDA adapter around public FLA 0.5.2 operations,
    plus KPool request-tail/cache semantics and attributed BF16 sparse MLA support.
  • Keep clamped SwiGLU, single-owner routed scaling, and GLM-specific dtype contracts.
  • Reuse decode CUDA Graph support, with fixed-shape KDA/KPool state handling.

Validation

  • Resolved conflicts with current main by adapting KDA/MoE to typed BuildSpec,
    KPool to collected/bound cache requests, and KDA metadata to the shared FLA
    step updater. Reuse the upstream KV-B post-load weight processing instead of
    retaining the old GLM loading workaround. Preserve upstream Ray device setup.
  • Ruff 0.15.4 on all changed/new Python files: passed.
  • git diff --check: passed.
  • GLM/framework CPU contracts after merging main: 105 passed, 5 CUDA tests skipped.
  • Existing executor/cache-engine/config/FP8 scope/multimodal preprocessing tests:
    499 passed, 12 skipped, 1 deselected; engine/input/health/Mooncake regressions: 176 passed, 1 skipped.
  • The excluded Kimi EAGLE config test requires GPU 0 during capability detection;
    the same No CUDA GPUs are available failure was reproduced on clean base
    2928f477 with GPUs hidden. No unrelated fix is bundled.

Accuracy

These are completed pre-cleanup/pre-merge integration runs, not a fresh benchmark
of the final commit. Local deployment: GLM-5.3 Flash FP8 on H200, TP4/EP1 with Ray and
BF16 KV cache.

Benchmark / protocol Accuracy
MMMU-Pro vision/test, full single uniform-budget run 76.94%
GPQA Diamond, conditional aggregate after length retries and diagnostic resampling 92.42%

MMMU-Pro details

  • NVIDIA publishes BF16 76.88% and NVFP4 76.30%; the local result differs
    by +0.06 and +0.64 percentage points, respectively.
    NVIDIA model card.

Reproduction and limits

Checkpoint revision: 3f1971b7b5f7a528c9c4ef6212c8785298a8c24a.
MMMU-Pro runtime: session length 344064, max batch 8, cache fraction 0.4,
cache block 64, prefill chunk 2048, CUDA Graph buckets 1/2/4/8, client concurrency 4.

MTP and latest upstream synchronization (2026-09-21)

  • Synced upstream main 9adf4856 by normal merge; implementation commit 6218f599.
  • Reuse deepseek_mtp, the shared GLM predictor, embedding/head, rejection sampler,
    cache planner, FLA kernels and CUDA Graph mixins. Six existing production files
    changed; no new production files or kernels for MTP.
  • Target KDA/KPool states retain per-token checkpoints selected by accepted history.
    The single predictor layer reconstructs its KPool tail from pageable token data.
    Multimodal embeddings use the existing target-to-draft handoff.
  • EP1 remains the default Triton MoE path; the hardcoded DeepGEMM MoE selection
    and unused EP1 extension remain removed. KPool still uses DeepGEMM scoring.
  • Canonical full projection prefixes fix an upstream FP8 ignore-list matching
    issue; unrelated models retain their existing behavior.

Reuse MLA/MoE loaders, FA3, mHC, sparse Top-K and compact DeepGEMM. Add KDA state adaptation and multimodal GLM configuration/processing. Preserve existing defaults and the positional MoE prefix argument.
@qescccczmr qescccczmr changed the title Feat/glm5.3 flash lmdeploy reuse Feat/glm5.3 flash Sep 14, 2026
@qescccczmr qescccczmr changed the title Feat/glm5.3 flash feat(pytorch): add glm5.3-flash support Sep 14, 2026
device=device,
is_tp=True,
quant_config=None,
dp_disable_tp=True,

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.

Keep KV-B sharding consistent with the attention TP group
When dp > 1 and attn_tp > 1, dp_disable_tp=True makes kv_b_proj retain all attention heads, while DeepseekV2BMM still shards kc/vc by attn_tp. The inherited process_weights_after_loading() then copies the full KV-B-derived weights directly into these sharded tensors.

@RunningLeon

Copy link
Copy Markdown
Collaborator

@qescccczmr Hi, is this PR ready to review?

@RunningLeon
RunningLeon self-requested a review September 21, 2026 06:59
from .step_metadata import register_step_metadata_impl


def _select_state(state: torch.Tensor, metadata: Any) -> torch.Tensor:

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.

can we use existing _state_select , _state_scatter in here?

def _state_select(state, state_indices, spec_offsets):

def _state_scatter(state, state_indices, spec_offsets, src):

Comment thread lmdeploy/pytorch/backends/cuda/kda.py Outdated
head_dim: int,
lower_bound: float,
) -> torch.Tensor:
if (metadata.spec_state_offsets is not None

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.

mtp may need support as well

inputs = [x.unflatten(1, (batch_size, steps))
for x in (mixed_qkv, raw_gate, raw_beta)]
outputs = []
for step in range(steps):

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.

this may lead to poor performance. If fla does not provide this verification kernel, we may need to change the tilelang kernel of gated_delta_rule.

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.

3 participants