Skip to content

[Feat] diffusion: Native Gemma-4-Unified text encoder for LTX-2.5 - #47411

Merged
mickqian merged 1 commit into
mainfrom
mick/ltx25-native-gemma4-encoder
Oct 30, 2026
Merged

mickqian merged 1 commit into
mainfrom
mick/ltx25-native-gemma4-encoder

Conversation

@mickqian

@mickqian mickqian commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

LTX-2.5's text encoder (Gemma4UnifiedForConditionalGeneration, 22 GB) has no SGLang implementation. On main it loads through transformers.AutoModel:

Component: text_encoder doesn't have a customized version yet, using native version
Native component text_encoder: Gemma4UnifiedModel is loaded, performance may be sub-optimal

runtime/models/encoders/gemma_4_unified.py only class-swaps that transformers module so it can be layerwise-offloaded (#43683).

Modifications

  • Gemma4UnifiedForConditionalGeneration in runtime/models/encoders/gemma_4_unified.py builds only the text path, because LTX-2.5 reads the embedding output plus all 48 decoder hidden states. The vision and audio embedders in the checkpoint are not loaded.
    • It covers the fused QKV and gate/up GEMMs (QKVParallelLinear / MergedColumnParallelLinear / RowParallelLinear), k_eq_v full-attention layers (V loads K's weights), QK/V RMSNorm, per-layer-type RoPE (default / proportional), and sliding-window plus padding masks.
    • Ops run in the same order and dtypes as the transformers SDPA path. LTX2 already pins this component to torch SDPA.
    • It declares layer_names / host_resident_table_names, so layerwise offload and the host-resident vocab table keep working.
  • The transformers class-swap adapter stays for checkpoints whose format transformers owns.
  • configs/models/encoders/gemma_4_unified.py: the config now carries the repo's text_config. The gate/up shard ids are ints.
  • The unit tests in the existing test_gemma4_unified_layerwise_offload.py check that a small random model matches transformers, the k_eq_v / GQA layers, and the layerwise and host-resident declarations.

Accuracy

4×B300 (sm_100), Lightricks/LTX-2.5-Diffusers revision 4791a110, bf16, torch 2.14.1. Native vs transformers on the same GPU:

prompts tokens connector input (all 49 hidden states)
5 single prompts (EN incl. 1-token and 198-token, ZH) 1–198 bitwise identical, max abs 0.0
batch of 2 (13 + 38 tokens, padded) bitwise identical

End-to-end sglang generate LTX-2.5 (two-stage, 1920×1088×121, same seed): the MP4 md5 is identical (4abb8c3a…) with the native encoder and with the transformers one.

Speed

  • Encode B=1 S=1024, median/min: native 47.18 / 47.15 ms, transformers 47.15 / 47.13 ms, i.e. unchanged.

  • Load time: native 4.4 s, transformers 4.9 s.

  • Serving, ltx2.5_twostage_t2v_2gpus (2×B300, Ulysses 2 + breakable CUDA graph, client wall clock, 2 requests per fresh server): this PR 5.093 / 5.086 s, main 1ab008f with the transformers encoder 5.113 / 5.101 s. vLLM-Omni 0da1d831 on the same box: 5.962 / 6.032 s.

Not tested

  • TP > 1 for this encoder on GPU. LTX-2.5's serving recipes run it at TP 1.
  • AMD / NPU.

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ✅ Run #41020614664
Latest PR Test (Extra): ❌ Run #41020614807
Latest PR Test (AMD ROCm 10): ❌ Run #41020615198

LTX-2.5's text encoder had no SGLang implementation and loaded through
transformers.AutoModel ("doesn't have a customized version yet, using
native version"). Build its text path natively: only the language model
(the vision and audio embedders are never loaded), fused QKV and
gate/up GEMMs, k_eq_v full-attention layers, per-layer-type RoPE and
sliding-window masks, and the same op order and dtypes as the
transformers SDPA path. The transformers class-swap adapter stays for
checkpoints whose format transformers owns.

On B300 (LTX-2.5-Diffusers 4791a110) the hidden states the connectors
read are bitwise identical to transformers for six prompts including a
batch of two, encode time is unchanged (47.18 vs 47.15 ms at S=1024),
and the end-to-end MP4 has the same md5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mickqian
mickqian requested a review from ping1jing2 as a code owner October 30, 2026 07:31

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@github-actions

This comment has been minimized.

mickqian added a commit to mickqian/diffusion-bench-framework that referenced this pull request Oct 30, 2026
LTX-2.5 joins b300x4-20261022, measured on b300final against vLLM-Omni
0da1d831 over two interleaved rounds: sglang 5.086 s, vLLM-Omni 6.032 s
(1.186x). The sglang tree is main 52604e1d plus sgl-project/sglang#47411,
the native Gemma-4-Unified text encoder; main still loads that encoder
through transformers, which the publish gate refuses. The encoder's
hidden states are bitwise equal to the transformers ones and the MP4 has
the same md5. sglang now leads 17/17 cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

This comment has been minimized.

@mickqian mickqian changed the title [diffusion] LTX-2.5: native Gemma-4-Unified text encoder [Feat] diffusion: Native Gemma-4-Unified text encoder for LTX-2.5 Oct 30, 2026
@mickqian

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Oct 30, 2026
@mickqian
mickqian merged commit e3e3729 into main Oct 30, 2026
220 of 242 checks passed
@mickqian
mickqian deleted the mick/ltx25-native-gemma4-encoder branch October 30, 2026 14:02
Yuxingwang-intel pushed a commit to Yuxingwang-intel/sglang that referenced this pull request Nov 6, 2026
…l-project#47411)

Co-authored-by: Mick Qian <mickqian@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diffusion SGLang Diffusion run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant