Repository navigation
Add MiniCPM-Llama3-V 2.5 #50929
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
Open
arywk40-hue
wants to merge
9
commits into
huggingface:main
Choose a base branch
from
arywk40-hue:add-minicpmv2_5
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,776
−1
Open
Add MiniCPM-Llama3-V 2.5 #50929
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
dde3bed
Add MiniCPM-Llama3-V 2.5
arywk40-hue 9a94cd1
Address review: conversion mapping, attention interface, padding in t…
arywk40-hue 48bb9d4
Use SDPA for the resampler under flash attention; cover padded slices…
arywk40-hue cab6318
Pin the integration test to the Hub PR with the converted config (ref…
arywk40-hue e8bbd5c
Resampler: one head for text widths below 128 (tiny fixtures); add re…
arywk40-hue efe4aa8
Declare the test model settings in small_config_overrides
arywk40-hue 41afa80
Flash attention: keep every query in non-causal cross-attention over …
arywk40-hue c56c507
Address review: DETR cross-attention, config fields, image processor …
arywk40-hue cf287bf
Return the shared multimodal outputs (image_outputs) from #50379
arywk40-hue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| <!--Copyright 2026 OpenBMB and the HuggingFace Inc. team. All rights reserved. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
| the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
| an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations under the License. | ||
|
|
||
| ⚠️ Note that this file is in Markdown but contains specific syntax for our doc-builder (similar to MDX) that may not be | ||
| rendered properly in your Markdown viewer. | ||
|
|
||
| --> | ||
| *This model was published in HF papers on 2024-08-03 and contributed to Hugging Face Transformers on 2026-11-20.* | ||
|
|
||
| <div style="float: right;"> | ||
| <div class="flex flex-wrap space-x-1"> | ||
| <img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white"> | ||
| </div> | ||
| </div> | ||
|
|
||
| # MiniCPM-Llama3-V 2.5 | ||
|
|
||
| [MiniCPM-Llama3-V 2.5](https://huggingface.co/papers/2408.01800) is an 8B multimodal model from [OpenBMB](https://github.com/OpenBMB). An image is cut into an overview plus up to 9 slices. Each slice goes through an [Idefics2](idefics2) (SigLIP-based) vision encoder, and a cross-attention resampler with 96 learned queries turns it into 96 tokens for a [Llama 3](llama3) 8B language model. | ||
|
|
||
| The original code can be found [here](https://github.com/OpenBMB/MiniCPM-V). | ||
|
|
||
| ## Usage example | ||
|
|
||
| ```python | ||
| from transformers import AutoModelForImageTextToText, AutoProcessor | ||
|
|
||
| model_id = "openbmb/MiniCPM-Llama3-V-2_5" | ||
| model = AutoModelForImageTextToText.from_pretrained(model_id, device_map="auto") | ||
| processor = AutoProcessor.from_pretrained(model_id) | ||
|
|
||
| messages = [ | ||
| { | ||
| "role": "user", | ||
| "content": [ | ||
| {"type": "image", "url": "http://images.cocodataset.org/val2017/000000039769.jpg"}, | ||
| {"type": "text", "text": "What is in this image?"}, | ||
| ], | ||
| } | ||
| ] | ||
| inputs = processor.apply_chat_template( | ||
| messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt" | ||
| ).to(model.device) | ||
| generated = model.generate(**inputs, max_new_tokens=64) | ||
| print(processor.post_process_image_text_to_text(generated[:, inputs["input_ids"].shape[1] :])[0]) | ||
| ``` | ||
|
|
||
| ## Notes | ||
|
|
||
| - In a prompt, each image is marked with `<unk>`. The processor expands it to `<image>` + 96 × `<unk>` + `</image>` for the overview image, followed by the slices row by row inside `<slice>...</slice>`. | ||
| - The original remote code never masked the zero padding added when slices of different sizes are batched together, so a slice's features depended on the other images in the batch. This implementation masks the padding, so each slice is encoded independently. Outputs therefore differ slightly from the original code, whose results it reproduces token-for-token when that behavior is replicated. | ||
|
|
||
| ## MiniCPMV2_5Config | ||
|
|
||
| [[autodoc]] MiniCPMV2_5Config | ||
|
|
||
| ## MiniCPMV2_5VisionConfig | ||
|
|
||
| [[autodoc]] MiniCPMV2_5VisionConfig | ||
|
|
||
| ## MiniCPMV2_5VisionTransformer | ||
|
|
||
| [[autodoc]] MiniCPMV2_5VisionTransformer | ||
| - forward | ||
|
|
||
| ## MiniCPMV2_5Model | ||
|
|
||
| [[autodoc]] MiniCPMV2_5Model | ||
| - forward | ||
| - get_image_features | ||
|
|
||
| ## MiniCPMV2_5ForConditionalGeneration | ||
|
|
||
| [[autodoc]] MiniCPMV2_5ForConditionalGeneration | ||
| - forward | ||
| - get_image_features | ||
|
|
||
| ## MiniCPMV2_5Processor | ||
|
|
||
| [[autodoc]] MiniCPMV2_5Processor | ||
| - __call__ | ||
|
|
||
| ## MiniCPMV2_5ImageProcessor | ||
|
|
||
| [[autodoc]] MiniCPMV2_5ImageProcessor | ||
| - preprocess | ||
|
|
||
| ## MiniCPMV2_5ImageProcessorPil | ||
|
|
||
| [[autodoc]] MiniCPMV2_5ImageProcessorPil | ||
| - preprocess |
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 | ||
| # This file was automatically generated from the modules in `src/transformers/models/minicpmv2_5`. | ||
| # Do NOT edit this file manually as any edits will be overwritten by auto-generation of the file. | ||
| # A module is picked up once it exports a name through `__all__`. | ||
| # Regenerate the file with: `python utils/check_inits.py --fix_and_overwrite` | ||
| # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 | ||
| # Copyright 2026 OpenBMB and the HuggingFace Inc. team. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from ...utils import _LazyModule | ||
| from ...utils.import_utils import define_import_structure | ||
|
|
||
|
|
||
| if TYPE_CHECKING: | ||
| from .configuration_minicpmv2_5 import * | ||
| from .image_processing_minicpmv2_5 import * | ||
| from .image_processing_pil_minicpmv2_5 import * | ||
| from .modeling_minicpmv2_5 import * | ||
| from .processing_minicpmv2_5 import * | ||
| else: | ||
| import sys | ||
|
|
||
| _file = globals()["__file__"] | ||
| sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__) |
Oops, something went wrong.
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.
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.
can you explain why is this needed, an dif it is a generic bug on main it'll be better to open a separate PR