fix: gracefully handle pixel_values TypeError for text-only Gemma 4 models#82
Open
yelban wants to merge 1 commit intojjang-ai:mainfrom
Open
fix: gracefully handle pixel_values TypeError for text-only Gemma 4 models#82yelban wants to merge 1 commit intojjang-ai:mainfrom
yelban wants to merge 1 commit intojjang-ai:mainfrom
Conversation
…odels
Text-only Gemma 4 models (e.g., supergemma4-26b-uncensored-mlx-4bit-v2)
have model_type="gemma4" in config.json but do not accept pixel_values.
The fallback heuristic in MLLMModelWrapper.__init__ detects "gemma4" in
model_type and enables pixel_values injection, which then causes a
TypeError crash in continuous-batching mode.
Add a try/except in __call__ that catches the TypeError, permanently
disables injection for the session, and retries without pixel_values.
This is self-healing: the first call pays a tiny retry cost, all
subsequent calls run without overhead.
Reproducer:
vmlx serve Jiunsong/supergemma4-26b-uncensored-mlx-4bit-v2 \
--continuous-batching
Before: [Engine error: Model.__call__() got an unexpected keyword
argument 'pixel_values'] on every request, 3 retries then crash.
After: first request auto-detects text-only model, disables injection,
and all subsequent requests work normally.
jjang-ai
added a commit
that referenced
this pull request
Apr 23, 2026
User-added model folders silently hid image/diffusion pipelines: - mlxstudio #85 (Chinese): 'swift 版本不能添加模型文件夹' ("Swift version cannot add model folder") - mlxstudio #82: 'Moved image models still not opening REDUX' - mlxstudio #96: 'Relocated image models do not work. Nor do other mflux models by others.' Root cause: walkUserDir accepted only dirs containing config.json. Diffusion pipelines (Flux, Z-Image, SD) ship a root-level model_index.json and their config.json files live inside the transformer / vae / text_encoder subdirs — which the walker was ALSO skipping via the diffusionSubmodules allowlist. Net effect: zero entries produced for a valid relocated Flux dir. Two-part fix: 1. walkUserDir accepts either 'config.json' OR 'model_index.json' as a model-root marker. Sub-module rejection (parent owns model_index.json) still applies so the tree doesn't double-emit transformer/text_encoder as standalone models. 2. buildEntry forces modality=.image when model_index.json is present at the root. Without this, a non-obviously-named Flux folder (e.g. 'my-custom-flux-weights/') would land as modality=.unknown and the Image tab filter hides it. Adjacent benefit: the minimum-weight-bytes guard already passes image modality through, so the root-level model_index.json path (which doesn't carry weights at the root — transformer/vae subdirs do) no longer rejects via the stub-snapshot guard.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Jiunsong/supergemma4-26b-uncensored-mlx-4bit-v2) havemodel_type="gemma4"inconfig.jsonbut do not acceptpixel_valuesMLLMModelWrapper.__init__detects"gemma4"inmodel_typeand enablespixel_valuesinjection, causing aTypeErrorcrash in continuous-batching modetry/exceptin__call__: on the firstpixel_valuesTypeError, it permanently disables injection and retries — all subsequent calls work without overheadReproducer
Before: Every request fails with
[Engine error: Model.__call__() got an unexpected keyword argument 'pixel_values'], retries 3 times, then crashes the engine loop.After: First request auto-detects text-only model, disables
pixel_valuesinjection for the session, and all subsequent requests work normally.Root cause
The
model_config_registry.lookup()receives a HuggingFace model name (e.g.,Jiunsong/supergemma4-26b-uncensored-mlx-4bit-v2) and tries to readconfig.jsonfrom the relative path — which doesn't exist (the model is in the HF cache). It falls back to the"unknown"config, and the fallback heuristic at line 47-53 then checksmodel.model_type == "gemma4"and enablespixel_valuesinjection, even though the model is text-only (text_config.model_type="gemma4_text",is_mllm=False).Test plan
vmlx servewith--continuous-batchingonJiunsong/supergemma4-26b-uncensored-mlx-4bit-v2— requests succeed after patchinject_pixel_values: Truein registry are unaffected (injection still happens, no TypeError)pixel_valuesTypeError