Skip to content

[feat] Add GLM-Image inference support - #1030

Merged
SolitaryThinker merged 28 commits into
hao-ai-lab:mainfrom
ShreejithSG:feature/glm-image-inference
Jul 13, 2026
Merged

[feat] Add GLM-Image inference support#1030
SolitaryThinker merged 28 commits into
hao-ai-lab:mainfrom
ShreejithSG:feature/glm-image-inference

Conversation

@ShreejithSG

@ShreejithSG ShreejithSG commented Jan 21, 2026

Copy link
Copy Markdown
Collaborator

Ported the GLM-Image architecture to FastVideo, enabling high-quality image generation.

Key features and fixes:

  • Implemented GlmImageTransformer2DModel in fastvideo/models/dits/glm_image.py.
  • Fixed architectural alignment with SGLang (timesteps, prior embeddings, CFG batching).
  • Created modular GlmImagePipeline with before_denoising, denoising, and decoding stages!

Test Plan

All tests are local (GPU + full zai-org/GLM-Image weights required; they skip cleanly in CI). Run on GB200, transformers 5.x, diffusers 0.37.x.

Component parity (FastVideo component vs official HF transformers/diffusers):

pytest tests/local_tests/glm_image/test_transformer_parity.py -v -s
pytest tests/local_tests/glm_image/test_transformer_strict_load.py -v -s
pytest tests/local_tests/glm_image/test_vae_parity.py -v -s
pytest tests/local_tests/glm_image/test_t5_parity.py -v -s
pytest tests/local_tests/glm_image/test_ar_parity.py -v -s

Pipeline parity — full-pipeline pixel parity is ill-posed (stochastic AR + independent latent RNG), so the test injects matched (prompt_embeds, prior_token_ids, latents) into both the diffusers pipeline and the real GlmImageDenoisingStage, then compares denoised latents (cosine + relative MAE) and the decoded image (uint8 MAE):

pytest tests/local_tests/glm_image/test_pipeline_parity.py -v -s       # T2I
pytest tests/local_tests/glm_image/test_edit_pipeline_parity.py -v -s  # I2I / edit

End-to-end examples (smoke, real generation):

python examples/inference/basic/basic_glm_image.py   # T2I
python examples/inference/basic/edit_glm_image.py    # I2I / edit

Test Results

Component parity — all non-skip PASS:

Component Result
transformer (DiT) fp32 cosine 1.000000 (100% within 5e-3); bf16 cosine 0.999969 (rounding over 30 layers vs a different SDPA kernel; RoPE proven exactly equivalent)
transformer strict-load strict=True state-dict load, 0 unmatched params (loader raises on any miss)
vae (AutoencoderKL) decode + encode + config, 3/3
text_encoder (T5) + ByT5 tokenizer tokenizer + glyph extract + embeds, 3/3
vision_language_encoder (GLM-4-9B AR) surface + to/eval + greedy determinism, 3/3

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @ShreejithSG, 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 introduces comprehensive support for the GLM-Image model within the FastVideo framework. It integrates the GLM-Image's diffusion transformer and VAE, along with its unique autoregressive vision-language encoder for prior token generation. The changes include new model implementations, configuration structures, and a dedicated pipeline with distinct stages for preprocessing, denoising, and decoding, ensuring high-quality image generation and architectural compatibility with the original SGLang implementation.

Highlights

  • GLM-Image Integration: The GLM-Image architecture has been successfully ported to FastVideo, enabling high-quality image generation capabilities within the framework.
  • New Model Implementation: The GlmImageTransformer2DModel has been implemented, serving as the core diffusion transformer (DiT) decoder for GLM-Image.
  • Architectural Alignment: Key architectural components, including timesteps, prior embeddings, and Classifier-Free Guidance (CFG) batching, have been aligned with the SGLang implementation for numerical consistency.
  • Modular Pipeline: A new modular GlmImagePipeline has been created, structured into before_denoising, denoising, and decoding stages for clear separation of concerns and extensibility.
  • Configuration and Loaders: Dedicated configuration files (GlmImageDiTConfig, GlmImageVAEConfig) and new component loaders (VisionLanguageEncoderLoader, ProcessorLoader, generic AutoencoderKL loader) have been added to support the GLM-Image model and its associated components.
  • Attention Mask Support: The LocalAttention mechanism has been enhanced to accept and apply an attention_mask, crucial for handling mixed text and image sequences in GLM-Image.
  • Dynamic Flow Shift: The GlmImageBeforeDenoisingStage now dynamically calculates and sets the flow shift for the scheduler based on image resolution, optimizing the denoising process.
  • Post-Decoding Hook: A post_decoding hook has been introduced in the base pipeline configuration, allowing for custom transformations to be applied to decoded images or videos.
  • Inference Script: An example inference script (scripts/glm_image_inference.py) has been added to demonstrate how to use the new GLM-Image pipeline for text-to-image generation.

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

@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-Image inference, a significant feature addition. The changes are extensive, including a new DiT model, VAE and pipeline configurations, new pipeline stages, and updates to the model loading infrastructure. The implementation is comprehensive and follows the existing structure of FastVideo well. I've identified a critical issue with how Classifier-Free Guidance (CFG) inputs are prepared, which would lead to incorrect outputs or runtime errors. I've also included several medium-severity suggestions to improve maintainability, flexibility, and robustness. Overall, this is a great contribution, and with the suggested fixes, it will be a solid addition to the project.

Comment thread fastvideo/pipelines/stages/glm_image_before_denoising.py Outdated
Comment thread fastvideo/pipelines/stages/glm_image_denoising.py Outdated
Comment thread fastvideo/pipelines/stages/glm_image_before_denoising.py Outdated
Comment thread fastvideo/attention/layer.py Outdated
Comment thread fastvideo/models/dits/glm_image.py Outdated
Comment thread fastvideo/models/dits/glm_image.py Outdated
Comment thread fastvideo/models/loader/component_loader.py Outdated
Comment thread fastvideo/models/loader/component_loader.py Outdated
Comment thread fastvideo/models/dits/glm_image.py Outdated
Comment thread fastvideo/pipelines/basic/glm_image/glm_image_pipeline.py Outdated
Comment thread scripts/glm_image_inference.py Outdated
@ShreejithSG
ShreejithSG force-pushed the feature/glm-image-inference branch 2 times, most recently from 0ffb397 to 197ffdf Compare January 24, 2026 05:07
@SolitaryThinker

Copy link
Copy Markdown
Collaborator

could you run pre-commit and also rebase to resolve conflicts? thanks

@ShreejithSG
ShreejithSG force-pushed the feature/glm-image-inference branch from 197ffdf to daee7e7 Compare January 25, 2026 03:35
Copilot AI review requested due to automatic review settings January 25, 2026 03:35

This comment was marked as spam.

@ShreejithSG

Copy link
Copy Markdown
Collaborator Author

@SolitaryThinker I've rebased and fixed pre-commit issues!

Comment thread fastvideo/configs/models/base.py Outdated
Comment thread fastvideo/attention/utils/flash_attn_no_pad.py Outdated
Comment thread fastvideo/pipelines/stages/decoding.py Outdated
Comment thread fastvideo/pipelines/composed_pipeline_base.py
Comment thread fastvideo/attention/layer.py Outdated
@loaydatrain

Copy link
Copy Markdown
Collaborator

would the current CI support SSIM tests for this? @SolitaryThinker

Comment thread examples/inference/basic/basic_glm_image.py
Comment thread examples/inference/basic/basic_glm_image.py Outdated
Comment thread fastvideo/attention/utils/flash_attn_no_pad.py Outdated
Comment thread fastvideo/attention/layer.py Outdated
Comment thread fastvideo/attention/layer.py Outdated
Comment thread fastvideo/models/loader/component_loader.py Outdated
Comment thread fastvideo/pipelines/stages/decoding.py Outdated
Comment thread fastvideo/pipelines/stages/glm_image_decoding.py Outdated
Comment thread fastvideo/attention/layer.py Outdated
@ShreejithSG
ShreejithSG force-pushed the feature/glm-image-inference branch 3 times, most recently from 027c613 to 5c7dfe2 Compare January 29, 2026 05:56
@ShreejithSG
ShreejithSG force-pushed the feature/glm-image-inference branch 5 times, most recently from b9290bc to f698d27 Compare January 31, 2026 20:59
@SolitaryThinker
SolitaryThinker force-pushed the feature/glm-image-inference branch from fd270f1 to ee62319 Compare July 7, 2026 22:02
@SolitaryThinker

Copy link
Copy Markdown
Collaborator

Rebased onto current main (fd270f15 -> ee623198c) to clear the merge conflict — no content changes. Union-resolved mechanically: fastvideo/configs/models/dits/__init__.py (__all__, main's ordering + GlmImageDiTConfig) and pyproject.toml/pyproject_other.toml (kept main's tokenizers>=0.20.1,<0.23 pin + this PR's transformers>=5.0.0 floor). fastvideo/registry.py, fastvideo/models/registry.py, configs/models/vaes/__init__.py, and component_loader.py auto-merged. Two intermediate commits became empty (absorbed by later cleanups) and were dropped; intermediate fastvideo/attention/layer.py edits that the branch itself later reverted were resolved to main's version throughout. No adaptation commits were needed. Range-diff verified: net delta vs main is identical to the pre-rebase delta.

@mergify

mergify Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 1 protections blocking · waiting on 👀 reviews and 🙋 you

Protection Waiting on
🔴 PR merge requirements 👀 reviews and 🙋 you

🔴 PR merge requirements

Waiting for

  • #approved-reviews-by>=1
  • title~=(?i)^\[(feat|feature|bugfix|fix|refactor|perf|ci|doc|docs|misc|chore|kernel|new.?model|skill|skills|infra)\]
This rule is failing.
  • #approved-reviews-by>=1
  • title~=(?i)^\[(feat|feature|bugfix|fix|refactor|perf|ci|doc|docs|misc|chore|kernel|new.?model|skill|skills|infra)\]
  • check-success=fastcheck-passed
  • check-success=full-suite-passed
  • check-success~=pre-commit

@SolitaryThinker SolitaryThinker added the type: new-model New model support label Jul 9, 2026
@mergify

mergify Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 1 protections blocking · waiting on 👀 reviews and 🙋 you

Protection Waiting on
🔴 PR merge requirements 👀 reviews and 🙋 you

🔴 PR merge requirements

Waiting for

  • #approved-reviews-by>=1
  • title~=(?i)^\[(feat|feature|bugfix|fix|refactor|perf|ci|doc|docs|misc|chore|kernel|new.?model|skill|skills|infra)\]
This rule is failing.
  • #approved-reviews-by>=1
  • title~=(?i)^\[(feat|feature|bugfix|fix|refactor|perf|ci|doc|docs|misc|chore|kernel|new.?model|skill|skills|infra)\]
  • check-success=fastcheck-passed
  • check-success=full-suite-passed
  • check-success~=pre-commit

@SolitaryThinker SolitaryThinker changed the title feat: Add GLM-Image inference support [feat] Add GLM-Image inference support Jul 11, 2026
@mergify mergify Bot added the type: feat New feature or capability label Jul 11, 2026
@mergify

mergify Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 1 protections blocking · waiting on 👀 reviews

Protection Waiting on
🔴 PR merge requirements 👀 reviews

🔴 PR merge requirements

Waiting for

  • #approved-reviews-by>=1
This rule is failing.
  • #approved-reviews-by>=1
  • check-success=fastcheck-passed
  • check-success=full-suite-passed
  • check-success~=pre-commit
  • title~=(?i)^\[(feat|feature|bugfix|fix|refactor|perf|ci|doc|docs|misc|chore|kernel|new.?model|skill|skills|infra)\]

@SolitaryThinker SolitaryThinker left a comment

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.

Approving per review: all items from the 2026-01-25 request-changes are fixed or moot at head ee62319 (none of the flagged files are touched anymore; SDPAMetadata replaced the attn-mask mutation; all 36 threads resolved), both June pushbacks verified correct, CI 25/25 green.

@mergify

mergify Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 PR merge requirements

  • #approved-reviews-by>=1
  • check-success=fastcheck-passed
  • check-success=full-suite-passed
  • check-success~=pre-commit
  • title~=(?i)^\[(feat|feature|bugfix|fix|refactor|perf|ci|doc|docs|misc|chore|kernel|new.?model|skill|skills|infra)\]

@SolitaryThinker
SolitaryThinker merged commit d82abc2 into hao-ai-lab:main Jul 13, 2026
33 checks passed
@SolitaryThinker SolitaryThinker mentioned this pull request Jul 15, 2026
42 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready PR is ready to merge scope: attention Attention backends (VSA, STA, Flash, etc.) scope: inference Inference pipeline, serving, CLI scope: infra CI, tests, Docker, build scope: model Model architecture (DiTs, encoders, VAEs) type: feat New feature or capability type: new-model New model support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants