-
Notifications
You must be signed in to change notification settings - Fork 5
[Mirror] Add Gemma3n multimodal support with MobileNetV5 vision encoder #64
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
base: master
Are you sure you want to change the base?
Changes from all commits
3e4c8f8
ad5ed98
f577054
4589d3e
28d39cb
47423a2
67801e5
04947c7
86618c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -456,6 +456,7 @@ class VISION_PROJECTOR_TYPE(IntEnum): | |||||||||||||||||||||||||||
| RESAMPLER = auto() | ||||||||||||||||||||||||||||
| GLM_EDGE = auto() | ||||||||||||||||||||||||||||
| MERGER = auto() | ||||||||||||||||||||||||||||
| GEMMA3N = auto() | ||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add GEMMA3N mapping to VISION_PROJECTOR_TYPE_NAMES. The 🔎 Proposed fixAdd the mapping to the VISION_PROJECTOR_TYPE_NAMES: dict[VISION_PROJECTOR_TYPE, str] = {
VISION_PROJECTOR_TYPE.MLP: "mlp",
VISION_PROJECTOR_TYPE.LDP: "ldp",
VISION_PROJECTOR_TYPE.LDPV2: "ldpv2",
VISION_PROJECTOR_TYPE.RESAMPLER: "resampler",
VISION_PROJECTOR_TYPE.GLM_EDGE: "adapter",
VISION_PROJECTOR_TYPE.MERGER: "qwen2vl_merger",
VISION_PROJECTOR_TYPE.GEMMA3: "gemma3",
+ VISION_PROJECTOR_TYPE.GEMMA3N: "gemma3n",
+ VISION_PROJECTOR_TYPE.QWEN3VL: "qwen3vl_merger",
+ VISION_PROJECTOR_TYPE.COGVLM: "cogvlm",
}Note: 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| GEMMA3 = auto() | ||||||||||||||||||||||||||||
| QWEN3VL = auto() | ||||||||||||||||||||||||||||
| COGVLM = auto() | ||||||||||||||||||||||||||||
|
|
@@ -666,6 +667,9 @@ class MODEL_TENSOR(IntEnum): | |||||||||||||||||||||||||||
| V_MM_INP_NORM = auto() | ||||||||||||||||||||||||||||
| V_MM_INP_PROJ = auto() # gemma3 | ||||||||||||||||||||||||||||
| V_MM_SOFT_EMB_NORM = auto() # gemma3 | ||||||||||||||||||||||||||||
| V_MM_EMBEDDING = auto() # gemma3n | ||||||||||||||||||||||||||||
| V_MM_HARD_EMB_NORM = auto() # gemma3n | ||||||||||||||||||||||||||||
| V_MM_POST_PROJ_NORM = auto() # gemma3n | ||||||||||||||||||||||||||||
| V_RESMPL_POS_EMBD_K = auto() # minicpmv | ||||||||||||||||||||||||||||
| V_RESMPL_ATTN_Q = auto() # minicpmv | ||||||||||||||||||||||||||||
| V_RESMPL_ATTN_K = auto() # minicpmv | ||||||||||||||||||||||||||||
|
|
@@ -1058,6 +1062,9 @@ class MODEL_TENSOR(IntEnum): | |||||||||||||||||||||||||||
| MODEL_TENSOR.V_MM_INP_PROJ: "mm.input_projection", | ||||||||||||||||||||||||||||
| MODEL_TENSOR.V_MM_INP_NORM: "mm.input_norm", | ||||||||||||||||||||||||||||
| MODEL_TENSOR.V_MM_SOFT_EMB_NORM: "mm.soft_emb_norm", | ||||||||||||||||||||||||||||
| MODEL_TENSOR.V_MM_EMBEDDING: "mm.embedding", | ||||||||||||||||||||||||||||
| MODEL_TENSOR.V_MM_HARD_EMB_NORM: "mm.hard_emb_norm", | ||||||||||||||||||||||||||||
| MODEL_TENSOR.V_MM_POST_PROJ_NORM: "mm.post_proj_norm", | ||||||||||||||||||||||||||||
| MODEL_TENSOR.V_RESMPL_POS_EMBD_K: "resampler.pos_embd_k", | ||||||||||||||||||||||||||||
| MODEL_TENSOR.V_RESMPL_ATTN_Q: "resampler.attn.q", | ||||||||||||||||||||||||||||
| MODEL_TENSOR.V_RESMPL_ATTN_K: "resampler.attn.k", | ||||||||||||||||||||||||||||
|
|
@@ -1156,6 +1163,9 @@ class MODEL_TENSOR(IntEnum): | |||||||||||||||||||||||||||
| MODEL_TENSOR.V_MM_INP_PROJ, | ||||||||||||||||||||||||||||
| MODEL_TENSOR.V_MM_INP_NORM, | ||||||||||||||||||||||||||||
| MODEL_TENSOR.V_MM_SOFT_EMB_NORM, | ||||||||||||||||||||||||||||
| MODEL_TENSOR.V_MM_EMBEDDING, | ||||||||||||||||||||||||||||
| MODEL_TENSOR.V_MM_HARD_EMB_NORM, | ||||||||||||||||||||||||||||
| MODEL_TENSOR.V_MM_POST_PROJ_NORM, | ||||||||||||||||||||||||||||
| MODEL_TENSOR.V_RESMPL_POS_EMBD_K, | ||||||||||||||||||||||||||||
| MODEL_TENSOR.V_RESMPL_ATTN_Q, | ||||||||||||||||||||||||||||
| MODEL_TENSOR.V_RESMPL_ATTN_K, | ||||||||||||||||||||||||||||
|
|
@@ -3397,6 +3407,7 @@ def get_type(val: Any) -> GGUFValueType: | |||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| class VisionProjectorType: | ||||||||||||||||||||||||||||
| GEMMA3 = "gemma3" | ||||||||||||||||||||||||||||
| GEMMA3N = "gemma3n" | ||||||||||||||||||||||||||||
| IDEFICS3 = "idefics3" | ||||||||||||||||||||||||||||
| PIXTRAL = "pixtral" | ||||||||||||||||||||||||||||
| LLAMA4 = "llama4" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
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.
🧩 Analysis chain
🏁 Script executed:
Repository: ngxson/llama.cpp
Length of output: 1253
Patch size computation for Gemma3n MobileNetV5 is off by a factor of √image_seq_length
The code currently computes
patch_size = 768 // 256 = 3, which results inn_per_side = 256andtokens = 65,536—wildly inconsistent with the 16×16 grid (256 tokens) described in the comment.The issue is treating
image_seq_length(total token count) as if it were patch size. Gemma 3n uses MobileNet v5 with a default image resolution of 768×768 pixels, and image_seq_length defaults to 256.The correct approach derives patch size from the per-side token count:
This yields
n_per_side = 16andtokens = 256, matching the expected grid layout and HF processor config.🧰 Tools
🪛 GitHub Actions: flake8 Lint
[error] 6010-6010: flake8: E202 whitespace before ']'. Command: /opt/hostedtoolcache/Python/3.11.14/x64/bin/flake8
[error] 6011-6011: flake8: E202 whitespace before ']'. Command: /opt/hostedtoolcache/Python/3.11.14/x64/bin/flake8
🤖 Prompt for AI Agents