Skip to content

[Bug Fix] GLM-V / GLM-OCR: field detection for transformers 5.x and MTP omission fix#21134

Merged
Fridge003 merged 2 commits intosgl-project:mainfrom
zRzRzRzRzRzRzR:glm
Mar 23, 2026
Merged

[Bug Fix] GLM-V / GLM-OCR: field detection for transformers 5.x and MTP omission fix#21134
Fridge003 merged 2 commits intosgl-project:mainfrom
zRzRzRzRzRzRzR:glm

Conversation

@zRzRzRzRzRzRzR
Copy link
Copy Markdown
Contributor

Mainly modify several issues

  1. Modified the position of the replacement model module to ensure that the MTP has a normal acceptance rate after reading, otherwise the accept len must be 1
  2. Added detection of text_config, which is required for GLM-4.6V
  3. Modified the reading logic in GLM-OCR, the original algorithm implementation error, although the numbers just want to wait, but in fact, it should be text_config intermediate_size is the correct design intention, and not modifying it will affect subsequent model iterations.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 primarily focuses on enhancing the robustness and compatibility of the model loading and processing mechanisms for GLM-V and GLM-OCR architectures. It resolves issues related to MTP acceptance rates, ensures proper configuration detection for newer GLM models, and corrects an underlying algorithmic flaw in GLM-OCR's data interpretation, leading to more accurate and stable model behavior.

Highlights

  • MTP Acceptance Rate Fix: The position of the replacement model module was adjusted to ensure the MTP (Multi-Turn Prediction) has a normal acceptance rate after reading, preventing scenarios where the accept length was incorrectly forced to 1.
  • GLM-4.6V Compatibility: Detection for text_config was added, which is essential for proper functioning with GLM-4.6V models.
  • GLM-OCR Reading Logic Correction: The reading logic in GLM-OCR was modified to correctly use text_config.intermediate_size for context_dim, addressing an algorithmic error that could impact future model iterations.

🧠 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.

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 several bug fixes for GLM-V and GLM-OCR models. The changes include correctly detecting num_nextn_layers from text_config for newer transformer versions, adjusting the model weight loading logic for MTP, and fixing an incorrect context_dim calculation in GLM-OCR. The changes appear correct and align with the pull request's objectives. I've provided one suggestion to improve code readability in weight_utils.py.

Comment on lines +607 to +611
num_nextn_layers = getattr(
getattr(hf_config, "text_config", hf_config),
"num_nextn_predict_layers",
getattr(hf_config, "num_nextn_predict_layers", 0),
)
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

While this logic correctly retrieves num_nextn_layers by checking text_config first, the nested getattr calls are a bit difficult to parse. For improved readability and maintainability, consider refactoring this into a more explicit conditional block.

For example:

text_config = getattr(hf_config, "text_config", None)
if text_config and hasattr(text_config, "num_nextn_predict_layers"):
    num_nextn_layers = text_config.num_nextn_predict_layers
else:
    num_nextn_layers = getattr(hf_config, "num_nextn_predict_layers", 0)

@JustinTong0323
Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@JustinTong0323
Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@JustinTong0323 JustinTong0323 enabled auto-merge (squash) March 23, 2026 02:30
@JustinTong0323
Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

13 similar comments
@JustinTong0323
Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@JustinTong0323
Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@JustinTong0323
Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@JustinTong0323
Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@JustinTong0323
Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@JustinTong0323
Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@JustinTong0323
Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@JustinTong0323
Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@JustinTong0323
Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@JustinTong0323
Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@JustinTong0323
Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@JustinTong0323
Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@JustinTong0323
Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@Fridge003 Fridge003 disabled auto-merge March 23, 2026 20:19
@Fridge003 Fridge003 merged commit fcaad42 into sgl-project:main Mar 23, 2026
810 of 874 checks passed
@zRzRzRzRzRzRzR zRzRzRzRzRzRzR deleted the glm branch March 24, 2026 03:10
adityavaid pushed a commit to adityavaid/sglang that referenced this pull request Mar 24, 2026
adityavaid pushed a commit to adityavaid/sglang that referenced this pull request Mar 24, 2026
0-693 pushed a commit to 0-693/sglang that referenced this pull request Mar 25, 2026
JustinTong0323 pushed a commit to JustinTong0323/sglang that referenced this pull request Apr 7, 2026
yhyang201 pushed a commit to yhyang201/sglang that referenced this pull request Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants