Skip to content

fix: GLM4.7-FP4 usage#16581

Closed
JustinTong0323 wants to merge 5 commits intosgl-project:mainfrom
JustinTong0323:fix-glm47nvfp4
Closed

fix: GLM4.7-FP4 usage#16581
JustinTong0323 wants to merge 5 commits intosgl-project:mainfrom
JustinTong0323:fix-glm47nvfp4

Conversation

@JustinTong0323
Copy link
Copy Markdown
Collaborator

@JustinTong0323 JustinTong0323 commented Jan 6, 2026

Motivation

cc @ynwang007 report this. Let glm-4.7-fp4 work with eagle in sglang

Usage

python3 -m sglang.launch_server \
  --model-path baseten-admin/glm-4.7-fp4 \
  --quantization modelopt_fp4 \
  --tp-size 8 \
  --ep-size=8 \
  --moe-runner-backend=flashinfer_cutlass \
  --tool-call-parser glm47  \
  --reasoning-parser glm45 \
  --speculative-algorithm EAGLE \
  --speculative-num-steps 3 \
  --speculative-eagle-topk 1 \
  --speculative-num-draft-tokens 4

Note: moe-runner-backend=flashinfer_trtllm would lead to garbage output

Modifications

  1. model_config.py - Disable FP4 quantization for draft NextN models
    - Adds a safeguard for architectures: DeepseekV3ForCausalLMNextN, Glm4MoeForCausalLMNextN, BailingMoeForCausalLMNextN
    - When a draft model uses modelopt_fp4 quantization, it's automatically disabled since NextN layers are not FP4 quantized
    - Prevents loader errors that would occur from mismatched quantization
  2. glm4_moe.py - Update routing method for Glm4MoeSparseMoeBlock
    - Imports RoutingMethodType utility
    - Explicitly sets routing_method_type=RoutingMethodType.DeepSeekV3 when creating the FusedMoE layer

The fix ensures proper handling of GLM-4 MoE models with FP4 quantization and speculative decoding (NextN draft models).

Accuracy Tests

python3 ./benchmark/gsm8k/bench_sglang.py  
Accuracy: 0.975
Invalid: 0.000
Latency: 42.875 s
Output throughput: 480.882 token/s

Benchmarking and Profiling

Checklist

Review Process

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

…py and update Glm4MoeSparseMoeBlock to use DeepSeekV3 routing method

Signed-off-by: Xinyuan Tong <xinyuantong.cs@gmail.com>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @JustinTong0323, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue preventing the "glm-4.7-fp4" model from working correctly with the "EAGLE" speculative decoding algorithm in sglang. The changes involve refining the model configuration to properly handle quantization for certain draft models and specifying the routing method for the GLM4 MoE layer, thereby enhancing compatibility and stability.

Highlights

  • Quantization Handling for Draft Models: Disabled "modelopt_fp4" quantization for specific NextN/MTP draft models, including "Glm4MoeForCausalLMNextN", "DeepseekV3ForCausalLMNextN", and "BailingMoeForCausalLMNextN". This change prevents loader errors by recognizing that the NextN layers of these draft models are not FP4 quantized.
  • GLM4 MoE Layer Configuration: Explicitly configured the Mixture-of-Experts (MoE) layer for GLM4 models by setting the "routing_method_type" to "DeepSeekV3" during its initialization. This ensures correct routing behavior within the MoE architecture.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces fixes to enable glm-4.7-fp4 to work with EAGLE speculative decoding. The changes include disabling modelopt_fp4 quantization for certain NextN draft models to prevent loader errors, and updating the MoE routing method for GLM-4.7 to be compatible with the DeepSeekV3 implementation in sglang. The changes are logical and well-targeted. I have one suggestion to improve performance and maintainability in model_config.py.

Comment on lines +770 to +774
nextn_architectures_without_fp4 = [
"DeepseekV3ForCausalLMNextN",
"Glm4MoeForCausalLMNextN",
"BailingMoeForCausalLMNextN",
]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For better performance and code clarity, it's recommended to define nextn_architectures_without_fp4 as a module-level constant (e.g., _NEXTN_ARCHITECTURES_WITHOUT_FP4) instead of redefining it within the _verify_quantization method on each call. Using a frozenset would also be more efficient for membership testing.

@JustinTong0323
Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions bot added the run-ci label Jan 6, 2026
…ptNvFp4FusedMoEMethod

Signed-off-by: Xinyuan Tong <xinyuantong.cs@gmail.com>
@github-actions github-actions bot added the quant LLM Quantization label Jan 7, 2026
JustinTong0323 and others added 3 commits January 7, 2026 18:02
Signed-off-by: Xinyuan Tong <xinyuantong.cs@gmail.com>
Signed-off-by: Xinyuan Tong <xinyuantong.cs@gmail.com>
@b8zhong
Copy link
Copy Markdown
Collaborator

b8zhong commented Feb 13, 2026

Closing, because I think we resolved the issue

@b8zhong b8zhong closed this Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

quant LLM Quantization run-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants