Misc. bug: convert_hf_to_gguf.py crashes with KeyError: 'image_mean' when preprocessor_config.json is incomplete
Name and Version
version: 8757 (a29e4c0b7) built with Clang 19.1.5 for Windows x86_64
Operating systems
Windows, Linux, Mac
Which llama.cpp modules do you know to be affected?
Python/Bash scripts
Command line
python convert_hf_to_gguf.py path/to/model --outfile mmproj.gguf --mmproj --verbose
Problem description & steps to reproduce
The MmprojModel class in convert_hf_to_gguf.py crashes with a KeyError: 'image_mean' when exporting a multimodal projector if the Hugging Face preprocessor_config.json is missing the image_mean or image_std keys. This occurs with several newer Gemma 4 and custom vision checkpoints that don't include these standard preprocessor keys.
The current implementation assumes these keys always exist:
image_mean = _MISTRAL_COMMON_DATASET_MEAN if self.is_mistral_format else self.preprocessor_config["image_mean"]
Relevant log output
Logs
File "convert_hf_to_gguf.py", line 2233, in set_gguf_parameters
image_mean = _MISTRAL_COMMON_DATASET_MEAN if self.is_mistral_format else self.preprocessor_config["image_mean"]
KeyError: 'image_mean'
Thanks for providing the detailed reproduction steps and logs. I see what’s happening: the MmprojModel class assumes that preprocessor_config.json contains certain standard keys like image_mean, which causes a KeyError when these are missing.
في السبت، 11 أبريل 2026 22:17 Ryan Nett @.***> كتب:
rnett created an issue (ggml-org/llama.cpp#21775) https://github.com/ggml-org/llama.cpp/issues/21775 Name and Version
$./llama-cli --version version: 8757 (a29e4c0 https://github.com/ggml-org/llama.cpp/commit/a29e4c0b7b23e020107058480dabbe03b7cba6e1 ) built with Clang 19.1.5 for Windows x86_64 Operating systems
Windows Which llama.cpp modules do you know to be affected?
Python/Bash scripts Command line
uv run python llama/quant/src/quantize_nvfp4/convert_hf_to_gguf.py llama/quant/models/gemma-4-E2B-nvfp4 --outfile llama/quant/models/gemma4-nvfp4-mmproj.gguf --mmproj --verbose Problem description & steps to reproduce
The \MmprojModel\ class in \convert_hf_to_gguf.py\ crashes with a \KeyError: 'image_mean'\ when exporting a multimodal projector if the Hugging Face \preprocessor_config.json\ is missing standard keys. This is a follow-up to closed issue #18514 https://github.com/ggml-org/llama.cpp/issues/18514, which suggested a manual workaround rather than fixing the script's robustness. Relevant log output Logs
\console File ".../convert_hf_to_gguf.py", line 2233, in set_gguf_parameters image_mean = _MISTRAL_COMMON_DATASET_MEAN if self.is_mistral_format else self.preprocessor_config["image_mean"]
KeyError: 'image_mean' \\ — Reply to this email directly, view it on GitHub <https://github.com/ggml-org/llama.cpp/issues/21775>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/CBTQ2IU3AHBD5PI4DZK55HT4VKZADAVCNFSM6AAAAACXVGGWRCVHI2DSMVQWIX3LMV43ASLTON2WKOZUGI2DKOBQGUZDSNQ> . You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
im going to see if i can fix this @rnett
also, are you still having the issue? I checked gemma 4 models and I havent found one that is missing image_mean and image_std keys?
https://github.com/ryan-mangeno/llama.cpp/tree/mmproj-conversion-fix added default values for image mean and image std if they dont exist