[VLM] Replace conv3d proj with linear for GLM4V#20033
[VLM] Replace conv3d proj with linear for GLM4V#20033Kangyan-Zhou merged 2 commits intosgl-project:mainfrom
Conversation
Summary of ChangesHello, 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 refactors the visual patch embedding mechanism within the GLM4V model to optimize memory usage and streamline the model loading process. It introduces a dynamic conversion from a Conv3d layer to an nn.Linear layer, ensuring that the Conv3d layer is only present during initial weight loading and is subsequently replaced and freed, leading to a more efficient memory footprint. Highlights
🧠 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. Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
|
/tag-and-rerun-ci |
There was a problem hiding this comment.
Code Review
This pull request aims to optimize memory usage by replacing a Conv3d layer with a Linear layer after loading model weights. The overall strategy is sound and the changes to enable this conversion are mostly correct. However, there is a critical issue where a Linear layer is redundantly initialized in the __init__ method, which contradicts the stated goal of the PR and unnecessarily increases memory consumption. I have provided a suggestion to fix this. Additionally, there's a minor point of feedback to improve code quality by avoiding the use of .data.
313b951 to
06185f0
Compare
06185f0 to
4af41de
Compare
|
/rerun-failed-ci |
1 similar comment
|
/rerun-failed-ci |
|
Please report some benchmark results. |
Sure, will update. |
|
/rerun-failed-ci |
|
B200 CI failed due to no disk space. |
Added benchmark test, linear vs conv3d speedup 24x . |
|
/rerun-failed-ci |
b5b7508 to
1e97895
Compare
|
/rerun-failed-ci |
3 similar comments
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
/rerun-failed-ci |
1e97895 to
ff7f7f5
Compare
|
/rerun-failed-ci |
PR sgl-project#20033 replaced Conv3d with Linear in Glm4vVisionPatchEmbed and added copy_conv3d_weight_to_linear() to glm4v.py's load_weights, but missed adding it to glm4v_moe.py and glm_ocr.py. This left the linear layer with random weights, causing the vision encoder to produce garbage embeddings — the model outputs text unrelated to the image. Fixes sgl-project#20462
Co-authored-by: luoyuan.luo <luoyuan.luo@antgroup.com>
Motivation
Inspired by #19788 with some optimizations:
lmms_evals no drops.
Main and PR are the same score:
More performance test will be done soon.
Server:
Client:
Modifications
Accuracy Tests
Benchmarking and Profiling
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci