Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ src/transformers/models/llava_next_video/configuration_*.py linguist-generated=t
src/transformers/models/llava_next_video/modeling_*.py linguist-generated=true
src/transformers/models/llava_onevision/image_*.py linguist-generated=true
src/transformers/models/llava_onevision/modeling_*.py linguist-generated=true
src/transformers/models/llava_onevision1_5/configuration_*.py linguist-generated=true
src/transformers/models/llava_onevision1_5/modeling_*.py linguist-generated=true
src/transformers/models/longcat_flash/modeling_*.py linguist-generated=true
src/transformers/models/lw_detr/configuration_*.py linguist-generated=true
src/transformers/models/lw_detr/modeling_*.py linguist-generated=true
Expand Down
2 changes: 2 additions & 0 deletions docs/source/en/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,8 @@
title: LLaVa-NeXT-Video
- local: model_doc/llava_onevision
title: LLaVA-Onevision
- local: model_doc/llava_onevision1_5
title: LLaVA-OneVision-1.5
- local: model_doc/lxmert
title: LXMERT
- local: model_doc/matcha
Expand Down
68 changes: 68 additions & 0 deletions docs/source/en/model_doc/llava_onevision1_5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!--Copyright 2025 The HuggingFace Team. All rights reserved.

Copy link
Copy Markdown
Member

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 :)

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use AutoForImageTextToText in model


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."},
]}]
Comment thread
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)
```
Comment thread
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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
6 changes: 6 additions & 0 deletions src/transformers/conversion_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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:

"Qwen2VLForConditionalGeneration": [
            WeightRenaming(source_patterns=r"^visual", target_patterns="model.visual"),
            WeightRenaming(
                source_patterns=r"^model(?!\.(language_model|visual))", target_patterns="model.language_model"
            ),
        ],

Then can point like this:
https://github.com/g1050/transformers/blob/0ed53a99f383fe94f4972f14b05c3a448486d167/src/transformers/conversion_mapping.py#L134-L137

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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(
Expand Down
1 change: 1 addition & 0 deletions src/transformers/exporters/exporter_dynamo.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ def _to_batched(t):
# Combined `qkv` + `(cos, sin)` rotary + `.proj`
"transformers.models.qwen2_vl.modeling_qwen2_vl.VisionAttention.forward",
"transformers.models.qwen2_5_vl.modeling_qwen2_5_vl.Qwen2_5_VLVisionAttention.forward",
"transformers.models.llava_onevision1_5.modeling_llava_onevision1_5.LlavaOnevision15VisionAttention.forward",
"transformers.models.qwen3_vl.modeling_qwen3_vl.Qwen3VLVisionAttention.forward",
"transformers.models.qwen3_vl_moe.modeling_qwen3_vl_moe.Qwen3VLMoeVisionAttention.forward",
"transformers.models.qwen3_5.modeling_qwen3_5.Qwen3_5VisionAttention.forward",
Expand Down
3 changes: 3 additions & 0 deletions src/transformers/exporters/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use same convention as in kimi with get_vision_frame_index, i.e. no hardcoding model type so similar arch can use same code path

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:
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@
from .llava_next import *
from .llava_next_video import *
from .llava_onevision import *
from .llava_onevision1_5 import *
from .longcat_flash import *
from .longformer import *
from .longt5 import *
Expand Down
3 changes: 3 additions & 0 deletions src/transformers/models/auto/auto_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@
("llava_next", "LlavaNextConfig"),
("llava_next_video", "LlavaNextVideoConfig"),
("llava_onevision", "LlavaOnevisionConfig"),
("llava_onevision1_5", "LlavaOnevision15Config"),
("llava_onevision1_5_vision", "LlavaOnevision15VisionConfig"),
("longcat_flash", "LongcatFlashConfig"),
("longformer", "LongformerConfig"),
("longt5", "LongT5Config"),
Expand Down Expand Up @@ -944,6 +946,7 @@
("lfm3_vl_vision", "lfm3_vl"),
("llama4_text", "llama4"),
("llama4_vision_model", "llama4"),
("llava_onevision1_5_vision", "llava_onevision1_5"),
("lw_detr_vit", "lw_detr"),
("maskformer-swin", "maskformer"),
("megatron-bert", "megatron_bert"),
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/auto/image_processing_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
("lfm3_vl", {"torchvision": "Qwen2VLImageProcessor", "pil": "Qwen2VLImageProcessorPil"}),
("lighton_ocr", {"torchvision": "PixtralImageProcessor", "pil": "PixtralImageProcessorPil"}),
("llava_next_video", {"torchvision": "LlavaNextImageProcessor", "pil": "LlavaNextImageProcessorPil"}),
("llava_onevision1_5", {"torchvision": "Qwen2VLImageProcessor", "pil": "Qwen2VLImageProcessorPil"}),
("lw_detr", {"torchvision": "DeformableDetrImageProcessor", "pil": "DeformableDetrImageProcessorPil"}),
("metaclip_2", {"torchvision": "CLIPImageProcessor", "pil": "CLIPImageProcessorPil"}),
("mgp-str", {"torchvision": "ViTImageProcessor", "pil": "ViTImageProcessorPil"}),
Expand Down
3 changes: 3 additions & 0 deletions src/transformers/models/auto/modeling_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ class _BaseModelWithGenerate(PreTrainedModel, GenerationMixin):
("llava_next", "LlavaNextModel"),
("llava_next_video", "LlavaNextVideoModel"),
("llava_onevision", "LlavaOnevisionModel"),
("llava_onevision1_5", "LlavaOnevision15Model"),
("llava_onevision1_5_vision", "LlavaOnevision15VisionModel"),
("longcat_flash", "LongcatFlashModel"),
("longformer", "LongformerModel"),
("longt5", "LongT5Model"),
Expand Down Expand Up @@ -1198,6 +1200,7 @@ class _BaseModelWithGenerate(PreTrainedModel, GenerationMixin):
("llava_next", "LlavaNextForConditionalGeneration"),
("llava_next_video", "LlavaNextVideoForConditionalGeneration"),
("llava_onevision", "LlavaOnevisionForConditionalGeneration"),
("llava_onevision1_5", "LlavaOnevision15ForConditionalGeneration"),
("minicpm_ocr", "MiniCPMOcrForConditionalGeneration"),
("minicpmv4_6", "MiniCPMV4_6ForConditionalGeneration"),
("minicpmv4_7", "MiniCPMV4_7ForConditionalGeneration"),
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/auto/processing_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
("inkling_mm_model", "InklingProcessor"),
("lasr_ctc", "LasrProcessor"),
("lasr_encoder", "LasrProcessor"),
("llava_onevision1_5", "Qwen2_5_VLProcessor"),
("metaclip_2", "CLIPProcessor"),
("mistral3", "PixtralProcessor"),
("mistral_large4", "PixtralProcessor"),
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/auto/tokenization_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
("led", "LEDTokenizer" if is_tokenizers_available() else None),
("lighton_ocr", "Qwen2TokenizerFast" if is_tokenizers_available() else None),
("lilt", "RobertaTokenizer" if is_tokenizers_available() else None),
("llava_onevision1_5", "Qwen2Tokenizer" if is_tokenizers_available() else None),
("longformer", "RobertaTokenizer" if is_tokenizers_available() else None),
("luke", "LukeTokenizer"),
("lxmert", "LxmertTokenizer" if is_tokenizers_available() else None),
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/auto/video_processing_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
("hyperclovax_vision_v2", {"torchvision": "Qwen2VLVideoProcessor"}),
("instructblip", {"torchvision": "InstructBlipVideoVideoProcessor"}),
("lfm3_vl", {"torchvision": "Qwen3VLVideoProcessor"}),
("llava_onevision1_5", {"torchvision": "Qwen2VLVideoProcessor"}),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super super nice on mapping processors to existing classes 🫶

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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"}),
Expand Down
33 changes: 33 additions & 0 deletions src/transformers/models/llava_onevision1_5/__init__.py
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"]
Loading
Loading