-
Notifications
You must be signed in to change notification settings - Fork 2
Fix Gemma4 bidirectional attention + add gemma-4-12B (gemma4_unified) #338
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b116505
Fix Gemma4 bidirectional vision-block attention
justinchuby 5231691
Add gemma4_unified_text (gemma-4-12B text backbone)
justinchuby fa9834d
Add gemma-4-12B unified multimodal model (gemma4_unified)
justinchuby 40b829f
Wire gemma4_unified vision projector to mm_embed_dim input
justinchuby 7487726
Add unit tests for gemma4_unified weight mapping and config hooks
justinchuby d527838
test: hoist imports to module top in _common_test
justinchuby 04fcc19
test: complete gemma4_unified (gemma-4-12B) coverage
justinchuby bba76eb
refactor(gemma4): derive vision-block overlay in decoder from input_ids
justinchuby 4b17bd1
feat(ort_genai): wire gemma4_unified into model-type resolution
justinchuby ee47419
fix(gemma4): upcast unified vision patch embedding for float16
justinchuby aa5dede
docs(examples): gemma4_unified multimodal genai example (text/image/a…
justinchuby ab8a56c
feat(examples): Olive INT4 quantization for gemma4_unified decoder
justinchuby 131faa2
fix(gemma4): exclude audio tokens from vision-block bidirectional att…
justinchuby fb0ad6b
docs+test(gemma4): clarify bidirectional doc, device-robust HF parity
justinchuby 8dffc8c
fix(examples): suppress structural image/audio tokens in gemma4 decode
justinchuby bf3e7d8
fix(gemma4): reject unsupported use_bidirectional_attention modes
justinchuby 7d6fd16
fix(gemma4): address PR review (block-overlay gating, unified process…
justinchuby 61513c8
test(gemma4): add L4+L5 golden tests for gemma-4-12B text/image/audio
justinchuby 44fdbd0
fix(gemma4): make bf16 unified vision/audio Compress loadable
justinchuby 389fa47
refactor(gqa): gate GQA head_dim limit on EP capability
justinchuby 0547679
feat(gqa): lift CUDA head_dim cap to enable Gemma4 global-attention GQA
justinchuby 89d7ed6
Remove head_dim cap on GroupQueryAttention fusion
justinchuby 1c2dc4d
Fix ruff-format lint: remove extra blank line in e2e_golden_test
justinchuby 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """Gemma4-unified (gemma-4-12B) audio extractor hook. | ||
|
|
||
| The ``gemma4_unified`` audio config describes an *encoder-free* embedder (no | ||
| Conformer tower). It exposes only ``audio_embed_dim`` (input feature size for | ||
| the projection) and ``rms_norm_eps``. This hook maps those onto | ||
| :class:`Gemma4AudioConfig` so | ||
| :class:`~mobius.models.gemma4._Gemma4UnifiedAudioEmbedderModel` can read them. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from mobius._configs._extractors import register_audio_hook | ||
| from mobius._configs._sub_configs import Gemma4AudioConfig | ||
|
|
||
| _UNIFIED_TYPES = ("gemma4_unified", "gemma4_unified_text", "gemma4_unified_audio") | ||
|
|
||
|
|
||
| @register_audio_hook | ||
| def _gemma4_unified_audio(config, parent_config, model_type: str, fields: dict): | ||
| composite = parent_config or config | ||
| parent_model_type = getattr(composite, "model_type", "") | ||
| if model_type not in _UNIFIED_TYPES and parent_model_type != "gemma4_unified": | ||
| return None | ||
| hf_audio = getattr(composite, "audio_config", None) | ||
| if hf_audio is None: | ||
| return None | ||
| audio_embed_dim = getattr(hf_audio, "audio_embed_dim", 640) | ||
| return { | ||
| "audio": Gemma4AudioConfig( | ||
| hidden_size=audio_embed_dim, | ||
| output_proj_dims=audio_embed_dim, | ||
| audio_token_id=getattr(composite, "audio_token_id", None), | ||
| ) | ||
| } |
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,49 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """Gemma4-unified (gemma-4-12B) vision extractor hook. | ||
|
|
||
| The ``gemma4_unified`` vision config describes an *encoder-free* embedder, not | ||
| a SigLIP tower. Its fields differ from the generic ``vision_config``: | ||
|
|
||
| - ``patch_size`` / ``pooling_kernel_size`` → merged ``model_patch_size`` | ||
| - ``mm_embed_dim`` → embedder hidden size (``VisionConfig.hidden_size``) | ||
| - ``mm_posemb_size`` → factorized positional-embedding table size | ||
| (``VisionConfig.position_embedding_size``) | ||
| - ``output_proj_dims`` → projection input dim (``VisionConfig.out_hidden_size``) | ||
|
|
||
| This hook maps those onto :class:`VisionConfig` so | ||
| :class:`~mobius.models.gemma4._Gemma4UnifiedVisionEmbedderModel` can read them. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from mobius._configs._extractors import register_vision_hook | ||
|
|
||
| _UNIFIED_TYPES = ("gemma4_unified", "gemma4_unified_text", "gemma4_unified_vision") | ||
|
|
||
|
|
||
| @register_vision_hook | ||
| def _gemma4_unified_vision(config, parent_config, model_type: str, fields: dict): | ||
| composite = parent_config or config | ||
| parent_model_type = getattr(composite, "model_type", "") | ||
| if model_type not in _UNIFIED_TYPES and parent_model_type != "gemma4_unified": | ||
| return None | ||
| hf_vision = getattr(composite, "vision_config", None) | ||
| if hf_vision is None: | ||
| return None | ||
|
|
||
| def _get(name, default=None): | ||
| return getattr(hf_vision, name, default) | ||
|
|
||
| fields.update( | ||
| model_type="gemma4_unified_vision", | ||
| hidden_size=_get("mm_embed_dim", 3840), | ||
| patch_size=_get("patch_size", 16), | ||
| pooling_kernel_size=_get("pooling_kernel_size", 3), | ||
| position_embedding_size=_get("mm_posemb_size", 1120), | ||
| out_hidden_size=_get("output_proj_dims", _get("mm_embed_dim", 3840)), | ||
| norm_eps=_get("rms_norm_eps", 1e-6), | ||
| ) | ||
| fields["image_token_id"] = getattr(composite, "image_token_id", None) | ||
| return None |
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
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.