Add native Transformers support (config and processor files only)

#6

This PR adds native Transformers support for MiniCPM-V 4.0 while keeping the existing remote code working. It goes with https://github.com/huggingface/transformers/pull/51299, which adds the model to Transformers as minicpmv2_6, on top of MiniCPM-Llama3-V 2.5 (https://github.com/huggingface/transformers/pull/50929, whose Hub files are openbmb/MiniCPM-Llama3-V-2_5#80, with the same layout).

The weights are not changed. Transformers maps the original weight names at load time.

It can be merged now: the remote code keeps loading as before (trust_remote_code=True, auto_map and the tokenizer's chat template unchanged), and Transformers versions that include the model load it natively.

File Change
config.json All original keys kept, incl. auto_map. Added: model_type: "minicpmv2_6", text_config, resampler_n_latents, resampler_n_heads, image_token_id. vision_config gets model_type: "minicpmv2_6_vision" (the remote code only reads its sizes), and slice_config no longer has its own model_type (on Transformers 4.57 the remote config was otherwise built from that sub-dict).
configuration_minicpm.py 1 line: MiniCPMVConfig accepts and ignores text_config, so get_text_config() keeps returning the config itself.
preprocessor_config.json Original keys and auto_map kept; the native image processor settings are added next to them, and image_processor_type names the native class (the remote code still loads its own through auto_map).
processor_config.json New: native processor settings, plus an auto_map so the remote processor is still found.
chat_template.json New: chat template for the native processor. Only the processor reads this file, so the tokenizer keeps its own template.
tokenizer_config.json pad_token: "</s>" (it had none, and <unk> is the image token) and padding_side: "left".

I used Claude Code for parts of this change.

How it was checked
  • Remote code (trust_remote_code=True) on Transformers 4.57.3: the same input_ids as the current revision, and the same greedy output (bf16 on CUDA). vLLM's MiniCPM-V, which loads the remote processor on Transformers 5, loads this revision as before.
  • Native (the Transformers PR branch, no remote code): the prompt tokenizes to the same input_ids as the remote processor, and fp32 greedy generation matches the remote code (details in the Transformers PR).
Ready to merge
This branch is ready to get merged automatically.

Sign up or log in to comment