Repository navigation
[model, ops] feat: add Gemma 4 E2B support #1242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Levius-Fubuki
wants to merge
20
commits into
ByteDance-Seed:main
Choose a base branch
from
Levius-Fubuki:feat/gemma4-e2b
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
961f0e2
feat: add Gemma 4 E2B modeling support
Levius-Fubuki 5706ce6
fix: support wide-head FlexAttention on Ampere
Levius-Fubuki 809bff7
fix: preserve Gemma 4 softcapping with non-eager loss selection
Levius-Fubuki 007c9b7
fix: guard Gemma 4 audio states when the input mask is missing
Levius-Fubuki 72f3376
fix: reject uncapped auxiliary log-probs for softcapped Gemma 4
Levius-Fubuki c6eff62
fix: build backend-independent boolean masks for Gemma 4 audio
Levius-Fubuki 2a35313
fix: preserve channel-loss interception for softcapped Gemma 4
Levius-Fubuki 7a58622
fix: reject unsupported Gemma 4 vision Ulysses layouts
Levius-Fubuki c36c7aa
fix: align Gemma 4 modality forwards across FSDP ranks
Levius-Fubuki 29a6186
Merge main and migrate Gemma 4 to current op interfaces
Levius-Fubuki 4e9c5f7
fix: preserve packed Gemma 4 bidirectional attention
Levius-Fubuki 6cb4323
fix: preserve Gemma 4 packed FlashAttention dispatch
Levius-Fubuki 0faf789
[model, ci] fix: disable packed Gemma caches and declare dual-GPU tests
Levius-Fubuki 28e88e0
[docs] fix: clarify packed Gemma vision attention support
Levius-Fubuki 02bac55
test: add controlled Gemma4 numerical references and diagnostics
Levius-Fubuki 2f25175
fix: connect Gemma4 VLM training and native data pipeline
Levius-Fubuki 7dac922
Merge main and reconcile VLM trainer integration
Levius-Fubuki 3158fc3
fix: reject reentrant checkpointing with Gemma4 shared KV
Levius-Fubuki 6740e22
fix: clarify Gemma4 attention modes and isolate Flex test
Levius-Fubuki 141b146
test: reserve CPU for wide-head Flex regression
Levius-Fubuki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # Gemma 4 | ||
|
|
||
| The `gemma4` and `gemma4_text` registrations provide generated modeling for | ||
| Gemma 4 E2B against Transformers 5.16.1. They retain per-layer embeddings, | ||
| shared KV states and the Hugging Face checkpoint layout. The multimodal | ||
| registration includes image, video and audio towers. | ||
|
|
||
| ## Attention and loss | ||
|
|
||
| Choose attention through `OpsImplementationConfig`, for example | ||
| `attn_implementation="flex_attention"`. The normalized HF interface name is | ||
| `veomni_flex_attention`. Packed full and sliding masks use the public | ||
| `veomni.ops.mask` builders with `cu_seq_lens_q` boundaries. Packed attention | ||
| does not support `past_key_values`; unpacked masks retain HF cache handling. | ||
| With `use_bidirectional_attention="all"`, full attention remains bidirectional | ||
| within each packed sample. Sliding attention preserves HF's inclusive, symmetric | ||
| window on both sides of each token; document boundaries still apply. | ||
|
|
||
| Each LM instance holds its own `VeomniOp("cross_entropy_loss", "standard", impl)` | ||
| as `veomni_ce`. Training calls its `loss_function` wrapper so channel-loss | ||
| callbacks can observe both eager and fused loss selections. An uncapped model | ||
| retains the selected loss implementation. Logit softcapping forces eager loss | ||
| on capped logits and materializes logits in memory. Capped models reject | ||
| `return_log_probs=True`, including the top-k distillation path, since the | ||
| auxiliary helpers would reproject uncapped logits. | ||
|
|
||
| Audio uses a boolean local mask independently of the LM attention backend. | ||
| Vision Ulysses is unsupported: use `ulysses_size=1` for models retaining the | ||
| vision tower. Such models reject Ulysses on text-only ranks too, before peers | ||
| could enter different collectives. | ||
|
|
||
| Under FSDP2, missing modalities participate through config-derived dummy | ||
| forwards in a fixed image, video, audio order, with live compute dtypes and | ||
| zero-valued projected graph dependencies. | ||
|
|
||
| ## Validation | ||
|
|
||
| CPU regressions cover output/loss/gradient parity, packed sample isolation, | ||
| channel-loss interception, audio visibility and dummy graph participation: | ||
|
|
||
| ```bash | ||
| pytest tests/models/test_gemma4.py -q | ||
| pytest tests/models/base/test_auto_registry.py -k gemma4 -q | ||
| ``` | ||
|
|
||
| Actual asymmetric BF16 FSDP2 validation requires two CUDA GPUs: | ||
|
|
||
| ```bash | ||
| pytest tests/distributed/test_dummy_forward.py -k gemma4 -q | ||
| ``` | ||
|
|
||
| The three cases cover image versus text, video/audio versus text, and split | ||
| modalities across ranks. They skip on CPU. Local checks do not establish | ||
| collective correctness or full-checkpoint memory requirements. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.