-
Notifications
You must be signed in to change notification settings - Fork 252
feat: add Gemma4 dense and MoE custom implementations #2190
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
hallerite
wants to merge
7
commits into
main
Choose a base branch
from
feat/gemma4
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
80d2e33
feat: add Gemma4 dense and MoE custom implementations
hallerite f45a110
Merge remote-tracking branch 'origin/main' into feat/gemma4
hallerite 3d2c452
fix: Gemma4 VLM support, SDPA fallback for head_dim>256, chat templat…
hallerite 22720b0
chore: add Gemma4 test configs for SFT and RL
hallerite 0a9f357
feat: add Gemma4 tool call parser entries
hallerite d1fc53d
style: ruff format modeling_gemma4.py
hallerite 84f98f4
refactor: use shared quack RMSNorm for Gemma4
hallerite 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,39 @@ | ||
| # Gemma4 31B dense RL test (reverse-text) | ||
| output_dir = "outputs/gemma4-dense-rl" | ||
| max_steps = 5 | ||
| seq_len = 2048 | ||
|
|
||
| [slurm] | ||
| job_name = "gemma4-dense-rl" | ||
|
|
||
| [deployment] | ||
| type = "single_node" | ||
| num_train_gpus = 4 | ||
| num_infer_gpus = 4 | ||
|
|
||
| [model] | ||
| name = "google/gemma-4-31B-it" | ||
|
|
||
| [wandb] | ||
| project = "gemma4-test" | ||
| name = "rl-dense" | ||
|
|
||
| [orchestrator] | ||
| batch_size = 128 | ||
| rollouts_per_example = 16 | ||
|
|
||
| [orchestrator.sampling] | ||
| max_tokens = 128 | ||
|
|
||
| [[orchestrator.env]] | ||
| id = "reverse-text" | ||
|
|
||
| [trainer.model] | ||
| attn = "flash_attention_2" | ||
|
|
||
| [trainer.model.ac] | ||
|
|
||
| [trainer.optim] | ||
| lr = 3e-6 | ||
|
|
||
| [inference] |
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,43 @@ | ||
| # Gemma4 26B-A4B MoE RL test (reverse-text) | ||
| output_dir = "outputs/gemma4-moe-rl" | ||
| max_steps = 5 | ||
| seq_len = 2048 | ||
|
|
||
| [slurm] | ||
| job_name = "gemma4-moe-rl" | ||
|
|
||
| [deployment] | ||
| type = "single_node" | ||
| num_train_gpus = 4 | ||
| num_infer_gpus = 4 | ||
|
|
||
| [model] | ||
| name = "google/gemma-4-26B-A4B-it" | ||
|
|
||
| [wandb] | ||
| project = "gemma4-test" | ||
| name = "rl-moe" | ||
|
|
||
| [orchestrator] | ||
| batch_size = 128 | ||
| rollouts_per_example = 16 | ||
|
|
||
| [orchestrator.sampling] | ||
| max_tokens = 128 | ||
|
|
||
| [[orchestrator.env]] | ||
| id = "reverse-text" | ||
|
|
||
| [trainer.model] | ||
| attn = "flash_attention_2" | ||
|
|
||
| [trainer.model.ac] | ||
|
|
||
| [trainer.optim] | ||
| lr = 3e-6 | ||
|
|
||
| [inference] | ||
| gpu_memory_utilization = 0.7 | ||
|
|
||
| [inference.model] | ||
| max_model_len = 2048 |
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,29 @@ | ||
| # Gemma4 31B dense SFT test | ||
| # Usage: uv run sft @ configs/gemma4/sft_dense.toml | ||
| output_dir = "outputs/gemma4-dense-sft" | ||
| max_steps = 10 | ||
|
|
||
| [slurm] | ||
| job_name = "gemma4-dense-sft" | ||
|
|
||
| [deployment] | ||
| type = "single_node" | ||
| num_gpus = 8 | ||
|
|
||
| [model] | ||
| name = "google/gemma-4-31B-it" | ||
| attn = "flash_attention_2" | ||
|
|
||
| [model.ac] | ||
|
|
||
| [wandb] | ||
| project = "gemma4-test" | ||
| name = "sft-dense" | ||
|
|
||
| [data] | ||
| name = "PrimeIntellect/Reverse-Text-SFT" | ||
| batch_size = 8 | ||
| seq_len = 2048 | ||
|
|
||
| [data.chat_template_kwargs] | ||
| enable_thinking = true |
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,29 @@ | ||
| # Gemma4 26B-A4B MoE SFT test | ||
| # Usage: uv run sft @ configs/gemma4/sft_moe.toml | ||
| output_dir = "outputs/gemma4-moe-sft" | ||
| max_steps = 10 | ||
|
|
||
| [slurm] | ||
| job_name = "gemma4-moe-sft" | ||
|
|
||
| [deployment] | ||
| type = "single_node" | ||
| num_gpus = 8 | ||
|
|
||
| [model] | ||
| name = "google/gemma-4-26B-A4B-it" | ||
| attn = "flash_attention_2" | ||
|
|
||
| [model.ac] | ||
|
|
||
| [wandb] | ||
| project = "gemma4-test" | ||
| name = "sft-moe" | ||
|
|
||
| [data] | ||
| name = "PrimeIntellect/Reverse-Text-SFT" | ||
| batch_size = 8 | ||
| seq_len = 2048 | ||
|
|
||
| [data.chat_template_kwargs] | ||
| enable_thinking = true |
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,18 @@ | ||
| # Qwen3 0.6B SFT sanity check | ||
| output_dir = "outputs/qwen3-sft" | ||
| max_steps = 5 | ||
|
|
||
| [slurm] | ||
| job_name = "qwen3-sft" | ||
|
|
||
| [model] | ||
| name = "PrimeIntellect/Qwen3-0.6B" | ||
|
|
||
| [wandb] | ||
| project = "gemma4-test" | ||
| name = "sft-qwen3" | ||
|
|
||
| [data] | ||
| name = "PrimeIntellect/Reverse-Text-SFT" | ||
| batch_size = 4 | ||
| seq_len = 1024 |
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,19 @@ | ||
| # Qwen3.5 MoE text-only SFT test (proving VLM bug) | ||
| # Usage: uv run sft @ configs/gemma4/sft_qwen35.toml | ||
| output_dir = "outputs/qwen35-moe-sft" | ||
| max_steps = 5 | ||
|
|
||
| [slurm] | ||
| job_name = "qwen35-moe-sft" | ||
|
|
||
| [model] | ||
| name = "Qwen/Qwen3.5-35B-A3B" | ||
|
|
||
| [wandb] | ||
| project = "gemma4-test" | ||
| name = "sft-qwen35" | ||
|
|
||
| [data] | ||
| name = "PrimeIntellect/Reverse-Text-SFT" | ||
| batch_size = 4 | ||
| seq_len = 2048 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| import prime_rl._compat # noqa: F401 — must run before ring_flash_attn is imported |
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,19 @@ | ||
| """Compatibility shim: ring_flash_attn + transformers >= 5.4. | ||
|
|
||
| ring_flash_attn 0.1.8 imports `is_flash_attn_greater_or_equal_2_10` from | ||
| `transformers.modeling_flash_attention_utils`. This symbol was removed from | ||
| that module in transformers 5.4 (still available as a deprecated function | ||
| in `transformers.utils.import_utils`, scheduled for removal in 5.8). | ||
|
|
||
| ring_flash_attn's except-branch is a no-op (imports the same symbol again), | ||
| so the import crashes on transformers >= 5.4. We patch the symbol back in as | ||
| `True` — the check is dead code since no one uses flash_attn < 2.1.0 anymore. | ||
|
|
||
| Upstream fix: https://github.com/zhuzilin/ring-flash-attention/pull/85 | ||
| Remove this shim once ring_flash_attn ships a fixed version. | ||
| """ | ||
|
|
||
| import transformers.modeling_flash_attention_utils as _mfau | ||
|
|
||
| if not hasattr(_mfau, "is_flash_attn_greater_or_equal_2_10"): | ||
| _mfau.is_flash_attn_greater_or_equal_2_10 = True |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing CHANGELOG entry for new config field
Low Severity
A new
chat_template_kwargsfield is added toSFTDataConfiginsrc/prime_rl/configs/sft.py, butCHANGELOG.mdhas no corresponding entry. Per the project rule, any PR modifying configuration structures or usage patterns in config files must update the changelog.Triggered by project rule: BugBot Instructions