Skip to content

[FEAT] Support GLM4.1V series - #534

Open
ZiyiTsang wants to merge 10 commits into
hiyouga:mainfrom
ZiyiTsang:main
Open

[FEAT] Support GLM4.1V series#534
ZiyiTsang wants to merge 10 commits into
hiyouga:mainfrom
ZiyiTsang:main

Conversation

@ZiyiTsang

@ZiyiTsang ZiyiTsang commented Oct 15, 2025

Copy link
Copy Markdown

This pull request adds support for GLM-4.1V models in the codebase, including training scripts, monkey patching, dataset position ID handling, and input preprocessing. The changes primarily focus on enabling training and inference with GLM-4.1V models and ensuring compatibility with their specific requirements.

GLM-4.1V Model Support:

  • Added two new example training scripts for GLM-4.1V models: glm4.1v_base_geo3k_grpo.sh and glm4.1v_thinking_geo3k_grpo.sh, enabling quick setup for training on the Geometry3K dataset. [1] [2]
  • Updated verl/models/monkey_patch.py to recognize GLM-4.1V models in the GLM_VL_MODELS tuple for future monkey patching support.

Dataset and Preprocessing Adjustments:

  • Modified verl/utils/dataset.py to add special handling for GLM-4.1V position IDs, using only 3D vision position IDs for rotary embedding as required by these models.
  • Updated verl/workers/fsdp_workers.py to ensure that pixel values from certain image processors (such as GLM-4.1V) are properly squeezed to remove the batch dimension.

@ZiyiTsang

Copy link
Copy Markdown
Author

Ready for review.
Note: Monkey patch is not support yet, kust put it in future PRs

@ZiyiTsang
ZiyiTsang marked this pull request as ready for review October 15, 2025 11:16
@ZiyiTsang

This comment was marked as resolved.

@ZiyiTsang ZiyiTsang changed the title [WIP] Support GLM4.1V series [FEAT] Support GLM4.1V series Oct 15, 2025

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

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.

Code Review

This pull request introduces support for GLM-4.1V models, including training scripts, monkey patching, dataset position ID handling, and input preprocessing. The changes primarily focus on enabling training and inference with GLM-4.1V models and ensuring compatibility with their specific requirements. I have added comments to address potential issues related to code correctness and efficiency.

Comment thread verl/workers/fsdp_workers.py Outdated
Comment thread verl/models/monkey_patch.py
Comment thread verl/utils/dataset.py
@ZiyiTsang

ZiyiTsang commented Oct 15, 2025

Copy link
Copy Markdown
Author

Ready for review. @hiyouga

Comment thread verl/models/transformers/glm4v.py Outdated
temperature: float = 1.0,
**kwargs,
) -> tuple | Glm4vCausalLMOutputForPPO:
from verl.utils.experimental.torch_functional import FusedLinearForPPO

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

this module does not exist

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed for no used.
This PR is modified by PR #3291 of VeRL, with removed 'padding_free' tech.

QWEN2_VL_MODELS = ("qwen2_vl", "qwen2_5_vl")
QWEN3_VL_MODELS = ("qwen3_vl", "qwen3_vl_moe")
# TODO support monkey patch for glm4.1v
GLM_VL_MODELS = ("glm4.1v_base", "glm4.1v_thinking")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

the patch is essential IMO

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The 'padding_free' haven been tested, I suggest putting it in the future

@ZiyiTsang

Copy link
Copy Markdown
Author

The swanlab log with glm4.1v_9b_thinking_geo3k_grpo.sh
This run is over 4 H200, which observes acc raise.
image

@ZiyiTsang
ZiyiTsang requested a review from hiyouga October 23, 2025 05:32
@ZiyiTsang

Copy link
Copy Markdown
Author

Done for 2nd review.

@ZiyiTsang

This comment was marked as resolved.

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

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.

Code Review

This pull request adds support for GLM-4.1V models, introducing new training scripts and model-specific handling for position IDs and input preprocessing. The changes are well-structured. However, I've identified a critical bug in the video position ID generation logic that could lead to incorrect embeddings. Additionally, there's a potential KeyError in the FSDP worker and a minor performance concern in the new get_rope_index function. Addressing these issues will improve the robustness and correctness of the implementation.

Comment thread verl/models/transformers/glm4v.py
Comment thread verl/workers/fsdp_workers.py Outdated
Comment thread verl/models/transformers/glm4v.py
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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