Repository navigation
Add LLaVA-OneVision-1.5 model and related configurations #41095
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
0ed53a9
1cbd582
9c33f62
7a58372
05620ae
33a9845
4089739
f7cb39d
7885b4e
5fc56cd
7412b6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| <!--Copyright 2025 The HuggingFace 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 contain specific syntax for our doc-builder (similar to MDX) that may not be | ||
| rendered properly in your Markdown viewer. | ||
| --> | ||
| *This model was contributed to Hugging Face Transformers on 2026-11-11.* | ||
|
|
||
| # LLaVA-OneVision-1.5 | ||
|
|
||
| LLaVA-OneVision-1.5 was introduced in [LLaVA-OneVision-1.5: Fully Open Framework for Democratized Multimodal Training](https://huggingface.co/papers/2509.23661). | ||
| It combines a native resolution vision encoder with a Qwen3 language backbone. The vision encoder adds a learned class token to each image, applies full attention, removes the class token, and merges spatial patches into visual features for the language model. The language backbone uses ordinary one dimensional rotary positions for the combined image and text sequence. | ||
|
|
||
| The implementation reuses the Qwen2.5-VL processor and supports the converted [4B checkpoint](https://huggingface.co/Deep-VLM/LLaVA-OneVision-1.5-4B-Instruct-hf). Use left padding for batched generation. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to mentioned code implem here, can just say we support these ckpts/hub collection |
||
|
|
||
| ## Abstract | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no new section needed, abstract is part of overview and is usually formatted in italics |
||
|
|
||
| The [paper's abstract](https://arxiv.org/abs/2509.23661) describes an open framework for training vision-language models from scratch at a reduced cost. Its release includes a concept-balanced collection of 85 million pretraining examples, a curated instruction dataset containing 22 million examples, and a training system that uses offline parallel packing. The authors report a training budget of $16,000. In their evaluation, the 8B model exceeds Qwen2.5-VL-7B on 18 out of 27 benchmarks, while the 4B model exceeds Qwen2.5-VL-3B on all 27. The report also describes a lightweight reinforcement learning stage that improves multimodal reasoning through chain-of-thought responses. | ||
|
|
||
| ## Usage | ||
|
|
||
| ```python | ||
| from transformers import AutoProcessor, LlavaOnevision15ForConditionalGeneration | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use |
||
|
|
||
| model_id = "Deep-VLM/LLaVA-OneVision-1.5-4B-Instruct-hf" | ||
| processor = AutoProcessor.from_pretrained(model_id) | ||
| model = LlavaOnevision15ForConditionalGeneration.from_pretrained(model_id, device_map="auto") | ||
| messages = [{"role": "user", "content": [ | ||
| {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"}, | ||
| {"type": "text", "text": "Describe the image."}, | ||
| ]}] | ||
|
zucchini-nlp marked this conversation as resolved.
Resolved
|
||
| inputs = processor.apply_chat_template( | ||
| messages, tokenize=True, add_generation_prompt=True, return_dict=True, return_tensors="pt" | ||
| ).to(model.device) | ||
| output = model.generate(**inputs, max_new_tokens=64) | ||
| processor.batch_decode(output[:, inputs.input_ids.shape[1]:], skip_special_tokens=True) | ||
| ``` | ||
|
vasqu marked this conversation as resolved.
Resolved
|
||
|
|
||
| ## Export | ||
|
|
||
| The vision encoder can be exported with `DynamoExporter`, which prepares grid metadata before tracing. The shared vision attention export adapter requires equal patch counts per frame. The number of frames and their patch counts are specialized to the export inputs; export a new graph when these change. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same, imo not needed, many VLM models uspport tracing by default atp |
||
|
|
||
| ## LlavaOnevision15Config | ||
|
|
||
| [[autodoc]] LlavaOnevision15Config | ||
|
|
||
| ## LlavaOnevision15VisionConfig | ||
|
|
||
| [[autodoc]] LlavaOnevision15VisionConfig | ||
|
|
||
| ## LlavaOnevision15VisionModel | ||
|
|
||
| [[autodoc]] LlavaOnevision15VisionModel | ||
| - forward | ||
|
|
||
| ## LlavaOnevision15Model | ||
|
|
||
| [[autodoc]] LlavaOnevision15Model | ||
| - forward | ||
|
|
||
| ## LlavaOnevision15ForConditionalGeneration | ||
|
|
||
| [[autodoc]] LlavaOnevision15ForConditionalGeneration | ||
| - forward | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -183,6 +183,12 @@ def _build_checkpoint_conversion_mapping(): | |
| WeightRenaming(r"\.mlp\.up_proj\.", ".mlp.fc1."), | ||
| WeightRenaming(r"\.mlp\.down_proj\.", ".mlp.fc2."), | ||
| ], | ||
| "llava_onevision1_5": [ | ||
| WeightRenaming(r"merger\.mlp\.0\.", "merger.fc1."), | ||
| WeightRenaming(r"merger\.mlp\.2\.", "merger.fc2."), | ||
| WeightRenaming(r"^visual\.", "model.visual."), | ||
| WeightRenaming(r"^model\.(?!language_model\.|visual\.)", "model.language_model."), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is same as below and imo better to point/alias it Same as this: Then can point like this:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and to check if Base model also needs conversion, has to be loadable from real ckpt without errors |
||
| ], | ||
| "inkling_mm_model": [ | ||
| WeightRenaming(source_patterns=r"model\.llm\.layers", target_patterns=r"model.language_model.layers"), | ||
| WeightRenaming( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -520,6 +520,9 @@ def _prepare_grid_thw_vision_inputs(model: torch.nn.Module, inputs: dict[str, An | |
| include_temporal = getattr(model, "include_temporal", False) | ||
| inputs["position_ids"] = get_vision_position_ids(grid_thw, spatial_merge_size, include_temporal=include_temporal) | ||
|
|
||
| if model.config.model_type == "llava_onevision1_5_vision": | ||
| inputs["frame_lengths"] = module.get_vision_frame_lengths(inputs["cu_seqlens"]) | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use same convention as in kimi with |
||
| window_size = _find_submodule_attr(model, "window_size") | ||
| patch_size = _find_submodule_attr(model, "patch_size") | ||
| if window_size is not None and patch_size is not None: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,6 +61,7 @@ | |
| ("hyperclovax_vision_v2", {"torchvision": "Qwen2VLVideoProcessor"}), | ||
| ("instructblip", {"torchvision": "InstructBlipVideoVideoProcessor"}), | ||
| ("lfm3_vl", {"torchvision": "Qwen3VLVideoProcessor"}), | ||
| ("llava_onevision1_5", {"torchvision": "Qwen2VLVideoProcessor"}), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super super nice on mapping processors to existing classes 🫶
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed lovely |
||
| ("minicpmv4_7", {"torchvision": "MiniCPMV4_6VideoProcessor"}), | ||
| ("muse_spark", {"torchvision": "MuseGlimmerVideoProcessor"}), | ||
| ("pe_audio_video", {"torchvision": "PeVideoVideoProcessor"}), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 | ||
| # This file was automatically generated from the modules in `src/transformers/models/llava_onevision1_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 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_llava_onevision1_5 import * | ||
| from .modeling_llava_onevision1_5 import * | ||
| else: | ||
| import sys | ||
|
|
||
| _file = globals()["__file__"] | ||
| sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 | ||
| # This file was automatically generated from src/transformers/models/llava_onevision1_5/modular_llava_onevision1_5.py. | ||
| # Do NOT edit this file manually as any edits will be overwritten by the generation of | ||
| # the file from the modular. If any change should be done, please apply the change to the | ||
| # modular_llava_onevision1_5.py file directly. One of our CI enforces this. | ||
| # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 | ||
| # Copyright 2026 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 huggingface_hub.dataclasses import strict | ||
| from packaging import version | ||
|
|
||
| from ...configuration_utils import PreTrainedConfig, SubConfigSpec | ||
| from ...utils import auto_docstring | ||
| from ..auto import AutoConfig | ||
|
|
||
|
|
||
| @auto_docstring(checkpoint="Deep-VLM/LLaVA-OneVision-1.5-4B-Instruct-hf") | ||
| @strict | ||
| class LlavaOnevision15VisionConfig(PreTrainedConfig): | ||
| r""" | ||
| out_hidden_size (`int`, *optional*, defaults to 4096): | ||
| Size of the projected visual features, matching the text backbone's hidden size. | ||
| layer_norm_eps (`float`, *optional*, defaults to 1e-5): | ||
| Epsilon used by the vision encoder's layer normalization layers. | ||
| initializer_factor (`float`, *optional*, defaults to 1.0): | ||
| Scale factor for initializing the learned class token and its rotary position embedding. | ||
| """ | ||
|
|
||
| model_type = "llava_onevision1_5_vision" | ||
| base_config_key = "vision_config" | ||
| default_rope_type = "axial" | ||
| attribute_map = {"num_attention_heads": "num_heads", "num_hidden_layers": "depth"} | ||
|
|
||
| depth: int = 24 | ||
| hidden_size: int = 1024 | ||
| hidden_act: str = "gelu" | ||
| intermediate_size: int = 4096 | ||
| num_heads: int = 16 | ||
| in_channels: int = 3 | ||
| patch_size: int | list[int] | tuple[int, int] = 14 | ||
| spatial_merge_size: int = 2 | ||
| temporal_patch_size: int = 1 | ||
| out_hidden_size: int = 4096 | ||
| initializer_range: float = 0.02 | ||
| rope_parameters: dict | None = None | ||
| layer_norm_eps: float = 1e-5 | ||
| initializer_factor: float = 1.0 | ||
|
|
||
|
|
||
| @auto_docstring(checkpoint="Deep-VLM/LLaVA-OneVision-1.5-4B-Instruct-hf") | ||
| @strict | ||
| class LlavaOnevision15Config(PreTrainedConfig): | ||
| r""" | ||
| Example: | ||
|
|
||
| ```python | ||
| >>> from transformers import LlavaOnevision15Config, LlavaOnevision15ForConditionalGeneration | ||
|
|
||
| >>> config = LlavaOnevision15Config() | ||
| >>> model = LlavaOnevision15ForConditionalGeneration(config) | ||
| ``` | ||
| """ | ||
|
|
||
| model_type = "llava_onevision1_5" | ||
| sub_configs_defaults = { | ||
| "vision_config": SubConfigSpec(config_class=LlavaOnevision15VisionConfig), | ||
| "text_config": SubConfigSpec(config_class=AutoConfig, model_type="qwen3"), | ||
| } | ||
| keys_to_ignore_at_inference = ["past_key_values"] | ||
|
|
||
| text_config: dict | PreTrainedConfig | None = None | ||
| vision_config: dict | PreTrainedConfig | None = None | ||
| image_token_id: int = 151655 | ||
| video_token_id: int = 151656 | ||
| vision_start_token_id: int = 151652 | ||
| vision_end_token_id: int = 151653 | ||
| tie_word_embeddings: bool = False | ||
|
|
||
| def __post_init__(self, **kwargs): | ||
| if isinstance(self.vision_config, dict): | ||
| self.vision_config = dict(self.vision_config) | ||
| self.vision_config["model_type"] = LlavaOnevision15VisionConfig.model_type | ||
| if "text_hidden_size" in self.vision_config: | ||
| self.vision_config.setdefault("out_hidden_size", self.vision_config.pop("text_hidden_size")) | ||
| if isinstance(self.text_config, dict) and self.text_config.get("model_type") == "LLaVAOneVision1_5_text": | ||
| self.text_config = {**self.text_config, "model_type": "qwen3"} | ||
| # Before v5 the nested text setting controlled tying; the serialized root setting could differ. | ||
| if ( | ||
| self.transformers_version is not None | ||
| and version.parse(self.transformers_version) < version.parse("5.0.0") | ||
| and self.text_config is not None | ||
| ): | ||
| self.tie_word_embeddings = ( | ||
| self.text_config.get("tie_word_embeddings", False) | ||
| if isinstance(self.text_config, dict) | ||
| else self.text_config.tie_word_embeddings | ||
| ) | ||
| super().__post_init__(**kwargs) | ||
| self.tie_word_embeddings = self.tie_word_embeddings or self.text_config.tie_word_embeddings | ||
| if self.vision_config.out_hidden_size != self.text_config.hidden_size: | ||
| raise ValueError("vision_config.out_hidden_size must match text_config.hidden_size") | ||
|
|
||
|
|
||
| __all__ = ["LlavaOnevision15Config", "LlavaOnevision15VisionConfig"] |
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.
to re-check that it's 2026 everywhere :)