Skip to content

Misc. bug: convert_hf_to_gguf.py crashes with KeyError: 'image_mean' when preprocessor_config.json is incomplete #21775

@rnett

Description

@rnett

Name and Version

version: 8757 (a29e4c0)
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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions