Image-Text-to-Text
Transformers
Safetensors
llava_onevision2_5
text-generation
multimodal
video-understanding
streaming
llava-onevision
conversational
custom_code
Instructions to use lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct", trust_remote_code=True) messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct
- SGLang
How to use lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct with Docker Model Runner:
docker model run hf.co/lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct
Rename classes to LlavaOnevision2_5* and model_type to llava_onevision2_5
Browse files- codec_video_processing_llava_onevision2_5.py +2 -2
- config.json +8 -8
- configuration_llava_onevision2_5.py +8 -8
- modeling_llava_onevision2_5.py +33 -33
- preprocessor_config.json +3 -3
- processing_llava_onevision2_5.py +9 -9
- processor_config.json +5 -5
- video_preprocessor_config.json +4 -4
- video_processing_llava_onevision2_5.py +7 -7
codec_video_processing_llava_onevision2_5.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
-
"""Codec (compressed-video) preprocessing backend for
|
| 2 |
|
| 3 |
This module supplies the six symbols that
|
| 4 |
-
``processing_llava_onevision2_5.
|
| 5 |
it is called with ``video_backend="codec"``:
|
| 6 |
|
| 7 |
CodecConfig
|
|
|
|
| 1 |
+
"""Codec (compressed-video) preprocessing backend for LlavaOnevision2_5.
|
| 2 |
|
| 3 |
This module supplies the six symbols that
|
| 4 |
+
``processing_llava_onevision2_5.LlavaOnevision2_5Processor.__call__`` imports when
|
| 5 |
it is called with ``video_backend="codec"``:
|
| 6 |
|
| 7 |
CodecConfig
|
config.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
| 1 |
{
|
| 2 |
"architectures": [
|
| 3 |
-
"
|
| 4 |
],
|
| 5 |
"auto_map": {
|
| 6 |
-
"AutoConfig": "configuration_llava_onevision2_5.
|
| 7 |
-
"AutoModelForCausalLM": "modeling_llava_onevision2_5.
|
| 8 |
-
"AutoModel": "modeling_llava_onevision2_5.
|
| 9 |
-
"AutoModelForImageTextToText": "modeling_llava_onevision2_5.
|
| 10 |
-
"AutoProcessor": "processing_llava_onevision2_5.
|
| 11 |
-
"AutoVideoProcessor": "video_processing_llava_onevision2_5.
|
| 12 |
},
|
| 13 |
"bos_token_id": null,
|
| 14 |
"dtype": "bfloat16",
|
| 15 |
"eos_token_id": 248044,
|
| 16 |
"image_token_id": 248056,
|
| 17 |
-
"model_type": "
|
| 18 |
"pad_token_id": null,
|
| 19 |
"text_config": {
|
| 20 |
"_name_or_path": "",
|
|
|
|
| 1 |
{
|
| 2 |
"architectures": [
|
| 3 |
+
"LlavaOnevision2_5ForConditionalGeneration"
|
| 4 |
],
|
| 5 |
"auto_map": {
|
| 6 |
+
"AutoConfig": "configuration_llava_onevision2_5.LlavaOnevision2_5Config",
|
| 7 |
+
"AutoModelForCausalLM": "modeling_llava_onevision2_5.LlavaOnevision2_5ForConditionalGeneration",
|
| 8 |
+
"AutoModel": "modeling_llava_onevision2_5.LlavaOnevision2_5ForConditionalGeneration",
|
| 9 |
+
"AutoModelForImageTextToText": "modeling_llava_onevision2_5.LlavaOnevision2_5ForConditionalGeneration",
|
| 10 |
+
"AutoProcessor": "processing_llava_onevision2_5.LlavaOnevision2_5Processor",
|
| 11 |
+
"AutoVideoProcessor": "video_processing_llava_onevision2_5.LlavaOnevision2_5VideoProcessor"
|
| 12 |
},
|
| 13 |
"bos_token_id": null,
|
| 14 |
"dtype": "bfloat16",
|
| 15 |
"eos_token_id": 248044,
|
| 16 |
"image_token_id": 248056,
|
| 17 |
+
"model_type": "llava_onevision2_5",
|
| 18 |
"pad_token_id": null,
|
| 19 |
"text_config": {
|
| 20 |
"_name_or_path": "",
|
configuration_llava_onevision2_5.py
CHANGED
|
@@ -5,7 +5,7 @@ from transformers.configuration_utils import PreTrainedConfig
|
|
| 5 |
|
| 6 |
|
| 7 |
@strict
|
| 8 |
-
class
|
| 9 |
model_type = "onevision_encoder"
|
| 10 |
base_config_key = "vision_config"
|
| 11 |
|
|
@@ -31,10 +31,10 @@ class LlavaOnevision2VisionConfig(PreTrainedConfig):
|
|
| 31 |
|
| 32 |
|
| 33 |
@strict
|
| 34 |
-
class
|
| 35 |
r"""
|
| 36 |
-
This is the configuration class to store the configuration of a [`
|
| 37 |
-
|
| 38 |
|
| 39 |
Configuration objects inherit from [`PreTrainedConfig`] and can be used to control the model outputs. Read the
|
| 40 |
documentation from [`PreTrainedConfig`] for more information.
|
|
@@ -42,7 +42,7 @@ class LlavaOnevision2Config(PreTrainedConfig):
|
|
| 42 |
Args:
|
| 43 |
text_config (`Union[PreTrainedConfig, dict]`, *optional*, defaults to `Qwen3Config`):
|
| 44 |
The config object or dictionary of the text backbone.
|
| 45 |
-
vision_config (`Union[PreTrainedConfig, dict]`, *optional*, defaults to `
|
| 46 |
The config object or dictionary of the vision backbone.
|
| 47 |
image_token_id (`int`, *optional*, defaults to 151655):
|
| 48 |
The image token index to encode the image prompt.
|
|
@@ -54,11 +54,11 @@ class LlavaOnevision2Config(PreTrainedConfig):
|
|
| 54 |
The token index to denote end of vision input.
|
| 55 |
"""
|
| 56 |
|
| 57 |
-
model_type = "
|
| 58 |
# `text_config` is resolved dynamically based on its `model_type` (defaults to `qwen3`),
|
| 59 |
# so we use `AutoConfig` here as a placeholder; `__post_init__` swaps it for the
|
| 60 |
# concrete config class via `CONFIG_MAPPING`.
|
| 61 |
-
sub_configs = {"vision_config":
|
| 62 |
keys_to_ignore_at_inference = ["past_key_values"]
|
| 63 |
|
| 64 |
text_config: dict | PreTrainedConfig | None = None
|
|
@@ -104,4 +104,4 @@ class LlavaOnevision2Config(PreTrainedConfig):
|
|
| 104 |
super().__post_init__(**kwargs)
|
| 105 |
|
| 106 |
|
| 107 |
-
__all__ = ["
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
@strict
|
| 8 |
+
class LlavaOnevision2_5VisionConfig(PreTrainedConfig):
|
| 9 |
model_type = "onevision_encoder"
|
| 10 |
base_config_key = "vision_config"
|
| 11 |
|
|
|
|
| 31 |
|
| 32 |
|
| 33 |
@strict
|
| 34 |
+
class LlavaOnevision2_5Config(PreTrainedConfig):
|
| 35 |
r"""
|
| 36 |
+
This is the configuration class to store the configuration of a [`LlavaOnevision2_5Model`]. It is used to instantiate a
|
| 37 |
+
LlavaOnevision2_5Model model according to the specified arguments, defining the model architecture.
|
| 38 |
|
| 39 |
Configuration objects inherit from [`PreTrainedConfig`] and can be used to control the model outputs. Read the
|
| 40 |
documentation from [`PreTrainedConfig`] for more information.
|
|
|
|
| 42 |
Args:
|
| 43 |
text_config (`Union[PreTrainedConfig, dict]`, *optional*, defaults to `Qwen3Config`):
|
| 44 |
The config object or dictionary of the text backbone.
|
| 45 |
+
vision_config (`Union[PreTrainedConfig, dict]`, *optional*, defaults to `LlavaOnevision2_5VisionConfig`):
|
| 46 |
The config object or dictionary of the vision backbone.
|
| 47 |
image_token_id (`int`, *optional*, defaults to 151655):
|
| 48 |
The image token index to encode the image prompt.
|
|
|
|
| 54 |
The token index to denote end of vision input.
|
| 55 |
"""
|
| 56 |
|
| 57 |
+
model_type = "llava_onevision2_5"
|
| 58 |
# `text_config` is resolved dynamically based on its `model_type` (defaults to `qwen3`),
|
| 59 |
# so we use `AutoConfig` here as a placeholder; `__post_init__` swaps it for the
|
| 60 |
# concrete config class via `CONFIG_MAPPING`.
|
| 61 |
+
sub_configs = {"vision_config": LlavaOnevision2_5VisionConfig, "text_config": AutoConfig}
|
| 62 |
keys_to_ignore_at_inference = ["past_key_values"]
|
| 63 |
|
| 64 |
text_config: dict | PreTrainedConfig | None = None
|
|
|
|
| 104 |
super().__post_init__(**kwargs)
|
| 105 |
|
| 106 |
|
| 107 |
+
__all__ = ["LlavaOnevision2_5Config", "LlavaOnevision2_5VisionConfig"]
|
modeling_llava_onevision2_5.py
CHANGED
|
@@ -22,7 +22,7 @@ from transformers.utils import (
|
|
| 22 |
)
|
| 23 |
from transformers.utils.generic import is_flash_attention_requested
|
| 24 |
|
| 25 |
-
from .configuration_llava_onevision2_5 import
|
| 26 |
|
| 27 |
|
| 28 |
def _default_patch_positions_from_grid(grid_thw, spatial_merge_size, device):
|
|
@@ -168,7 +168,7 @@ def _mrope_positions_from_patch_positions(
|
|
| 168 |
Base class for Llava-Onevision-1.5 outputs, with hidden states and attentions.
|
| 169 |
"""
|
| 170 |
)
|
| 171 |
-
class
|
| 172 |
r"""
|
| 173 |
past_key_values (`Cache`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
|
| 174 |
It is a [`~cache_utils.Cache`] instance. For more details, see our [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache).
|
|
@@ -189,7 +189,7 @@ class LlavaOnevision2ModelOutputWithPast(ModelOutput):
|
|
| 189 |
Base class for Llava-Onevision-1.5 causal language model (or autoregressive) outputs.
|
| 190 |
"""
|
| 191 |
)
|
| 192 |
-
class
|
| 193 |
r"""
|
| 194 |
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
|
| 195 |
Language modeling loss (for next-token prediction).
|
|
@@ -220,7 +220,7 @@ class VisionRotaryEmbedding(nn.Module):
|
|
| 220 |
Supports both grid_thw-based and explicit position-based RoPE computation.
|
| 221 |
"""
|
| 222 |
|
| 223 |
-
def __init__(self, config:
|
| 224 |
super().__init__()
|
| 225 |
head_dim = config.hidden_size // config.num_attention_heads
|
| 226 |
base = config.rope_theta
|
|
@@ -364,7 +364,7 @@ class OneVisionEncoderEmbeddings(nn.Module):
|
|
| 364 |
Output format: [total_patches, embed_dim]
|
| 365 |
"""
|
| 366 |
|
| 367 |
-
def __init__(self, config:
|
| 368 |
super().__init__()
|
| 369 |
self.config = config
|
| 370 |
self.embed_dim = config.hidden_size
|
|
@@ -393,7 +393,7 @@ class OneVisionEncoderEmbeddings(nn.Module):
|
|
| 393 |
# ---------------------------------------------------------------------------
|
| 394 |
|
| 395 |
|
| 396 |
-
class
|
| 397 |
"""
|
| 398 |
Patch merger that merges spatial_merge_size x spatial_merge_size patches into one.
|
| 399 |
|
|
@@ -488,7 +488,7 @@ class OneVisionEncoderAttention(nn.Module):
|
|
| 488 |
based on ``config._attn_implementation``.
|
| 489 |
"""
|
| 490 |
|
| 491 |
-
def __init__(self, config:
|
| 492 |
super().__init__()
|
| 493 |
self.config = config
|
| 494 |
self.embed_dim = config.hidden_size
|
|
@@ -608,7 +608,7 @@ class OneVisionEncoderAttention(nn.Module):
|
|
| 608 |
class OneVisionEncoderEncoderLayer(nn.Module):
|
| 609 |
"""Vision encoder layer with pre-norm and Flash Attention 2."""
|
| 610 |
|
| 611 |
-
def __init__(self, config:
|
| 612 |
super().__init__()
|
| 613 |
self.embed_dim = config.hidden_size
|
| 614 |
self.self_attn = OneVisionEncoderAttention(config)
|
|
@@ -648,7 +648,7 @@ class OneVisionEncoderEncoderLayer(nn.Module):
|
|
| 648 |
|
| 649 |
|
| 650 |
class OneVisionEncoderEncoder(nn.Module):
|
| 651 |
-
def __init__(self, config:
|
| 652 |
super().__init__()
|
| 653 |
self.config = config
|
| 654 |
self.layers = nn.ModuleList([OneVisionEncoderEncoderLayer(config) for _ in range(config.num_hidden_layers)])
|
|
@@ -711,8 +711,8 @@ class OneVisionEncoderEncoder(nn.Module):
|
|
| 711 |
)
|
| 712 |
|
| 713 |
|
| 714 |
-
class
|
| 715 |
-
config_class =
|
| 716 |
base_model_prefix = "model"
|
| 717 |
input_modalities = ("image", "video", "text")
|
| 718 |
supports_gradient_checkpointing = True
|
|
@@ -744,7 +744,7 @@ class Siglip2MultiheadAttentionPoolingHead(nn.Module):
|
|
| 744 |
Multi-Head Attention Pooling with a learned probe (PMA-style).
|
| 745 |
"""
|
| 746 |
|
| 747 |
-
def __init__(self, config:
|
| 748 |
super().__init__()
|
| 749 |
self.embed_dim = config.hidden_size
|
| 750 |
self.probe = nn.Parameter(torch.randn(1, 1, config.hidden_size))
|
|
@@ -770,7 +770,7 @@ class Siglip2MultiheadAttentionPoolingHead(nn.Module):
|
|
| 770 |
# ---------------------------------------------------------------------------
|
| 771 |
|
| 772 |
|
| 773 |
-
class
|
| 774 |
"""
|
| 775 |
LLaVA-OneVision-2.5 Vision Model.
|
| 776 |
|
|
@@ -784,7 +784,7 @@ class LlavaOnevision2VisionPretrainedModel(LlavaOnevision2PreTrainedModel):
|
|
| 784 |
grid_thw: [num_samples, 3] with [t, h, w] for each sample
|
| 785 |
"""
|
| 786 |
|
| 787 |
-
def __init__(self, config:
|
| 788 |
super().__init__(config)
|
| 789 |
self.config = config
|
| 790 |
self.spatial_merge_size = config.spatial_merge_size
|
|
@@ -802,7 +802,7 @@ class LlavaOnevision2VisionPretrainedModel(LlavaOnevision2PreTrainedModel):
|
|
| 802 |
self.layernorm_post = None
|
| 803 |
self.head = None
|
| 804 |
|
| 805 |
-
self.merger =
|
| 806 |
dim=config.out_hidden_size,
|
| 807 |
context_dim=config.hidden_size,
|
| 808 |
spatial_merge_size=config.spatial_merge_size,
|
|
@@ -926,7 +926,7 @@ class LlavaOnevision2VisionPretrainedModel(LlavaOnevision2PreTrainedModel):
|
|
| 926 |
|
| 927 |
return attn_mask
|
| 928 |
|
| 929 |
-
@replace_return_docstrings(output_type=BaseModelOutputWithPooling, config_class=
|
| 930 |
def forward(
|
| 931 |
self,
|
| 932 |
hidden_state: torch.Tensor,
|
|
@@ -1175,16 +1175,16 @@ class LlavaOnevision2VisionPretrainedModel(LlavaOnevision2PreTrainedModel):
|
|
| 1175 |
|
| 1176 |
|
| 1177 |
@auto_docstring
|
| 1178 |
-
class
|
| 1179 |
base_model_prefix = ""
|
| 1180 |
# Reference: fix gemma3 grad acc #37208
|
| 1181 |
accepts_loss_kwargs = False
|
| 1182 |
-
config:
|
| 1183 |
_no_split_modules = ["OneVisionEncoderEncoderLayer", "Qwen3DecoderLayer"]
|
| 1184 |
|
| 1185 |
-
def __init__(self, config:
|
| 1186 |
super().__init__(config)
|
| 1187 |
-
self.visual =
|
| 1188 |
self.language_model = AutoModel.from_config(config.text_config)
|
| 1189 |
|
| 1190 |
# Initialize weights and apply final processing
|
|
@@ -1353,7 +1353,7 @@ class LlavaOnevision2Model(LlavaOnevision2PreTrainedModel):
|
|
| 1353 |
second_per_grid_ts: Optional[torch.Tensor] = None,
|
| 1354 |
mm_token_type_ids: torch.Tensor | None = None, # emitted by Qwen2.5-VL-style processors; accepted and ignored
|
| 1355 |
**kwargs: Unpack[TransformersKwargs],
|
| 1356 |
-
) -> Union[tuple,
|
| 1357 |
r"""
|
| 1358 |
image_grid_thw (`torch.LongTensor` of shape `(num_images, 3)`, *optional*):
|
| 1359 |
The temporal, height and width of feature shape of each image in LLM.
|
|
@@ -1370,7 +1370,7 @@ class LlavaOnevision2Model(LlavaOnevision2PreTrainedModel):
|
|
| 1370 |
Indices depicting the position of the input sequence tokens in the sequence. Contrarily to
|
| 1371 |
`position_ids`, this tensor is not affected by padding.
|
| 1372 |
|
| 1373 |
-
Note: see the top-level ``
|
| 1374 |
docstring; in P0 video flows in via the ``image_grid_thw`` / ``pixel_values``
|
| 1375 |
alias, so ``pixel_values_videos`` / ``video_grid_thw`` /
|
| 1376 |
``second_per_grid_ts`` are unused at this layer.
|
|
@@ -1482,7 +1482,7 @@ class LlavaOnevision2Model(LlavaOnevision2PreTrainedModel):
|
|
| 1482 |
**kwargs,
|
| 1483 |
)
|
| 1484 |
|
| 1485 |
-
output =
|
| 1486 |
last_hidden_state=outputs.last_hidden_state,
|
| 1487 |
past_key_values=outputs.past_key_values,
|
| 1488 |
hidden_states=outputs.hidden_states,
|
|
@@ -1492,14 +1492,14 @@ class LlavaOnevision2Model(LlavaOnevision2PreTrainedModel):
|
|
| 1492 |
|
| 1493 |
|
| 1494 |
@auto_docstring
|
| 1495 |
-
class
|
| 1496 |
_tied_weights_keys = {"lm_head.weight": "model.language_model.embed_tokens.weight"}
|
| 1497 |
# Reference: fix gemma3 grad acc #37208
|
| 1498 |
accepts_loss_kwargs = False
|
| 1499 |
|
| 1500 |
def __init__(self, config):
|
| 1501 |
super().__init__(config)
|
| 1502 |
-
self.model =
|
| 1503 |
self.lm_head = nn.Linear(config.text_config.hidden_size, config.text_config.vocab_size, bias=False)
|
| 1504 |
self.post_init()
|
| 1505 |
|
|
@@ -1558,7 +1558,7 @@ class LlavaOnevision2ForConditionalGeneration(LlavaOnevision2PreTrainedModel, Ge
|
|
| 1558 |
logits_to_keep: Union[int, torch.Tensor] = 0,
|
| 1559 |
mm_token_type_ids: torch.Tensor | None = None, # emitted by Qwen2.5-VL-style processors; accepted and ignored
|
| 1560 |
**kwargs: Unpack[TransformersKwargs],
|
| 1561 |
-
) -> Union[tuple,
|
| 1562 |
r"""
|
| 1563 |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 1564 |
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
|
@@ -1580,7 +1580,7 @@ class LlavaOnevision2ForConditionalGeneration(LlavaOnevision2PreTrainedModel, Ge
|
|
| 1580 |
`position_ids`, this tensor is not affected by padding.
|
| 1581 |
|
| 1582 |
Note (P0 native-video alias):
|
| 1583 |
-
The companion ``
|
| 1584 |
pass ``pixel_values_videos`` / ``video_grid_thw`` / ``second_per_grid_ts``
|
| 1585 |
to this forward. Instead it aliases the video patch tensor as
|
| 1586 |
``pixel_values=`` and ``image_grid_thw=``, so video inputs share the
|
|
@@ -1596,9 +1596,9 @@ class LlavaOnevision2ForConditionalGeneration(LlavaOnevision2PreTrainedModel, Ge
|
|
| 1596 |
```python
|
| 1597 |
>>> from PIL import Image
|
| 1598 |
>>> import requests
|
| 1599 |
-
>>> from transformers import AutoProcessor,
|
| 1600 |
|
| 1601 |
-
>>> model =
|
| 1602 |
>>> processor = AutoProcessor.from_pretrained("lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct", trust_remote_code=True)
|
| 1603 |
|
| 1604 |
>>> messages = [
|
|
@@ -1657,7 +1657,7 @@ class LlavaOnevision2ForConditionalGeneration(LlavaOnevision2PreTrainedModel, Ge
|
|
| 1657 |
logits=logits, labels=labels, vocab_size=self.config.text_config.vocab_size, **kwargs
|
| 1658 |
)
|
| 1659 |
|
| 1660 |
-
return
|
| 1661 |
loss=loss,
|
| 1662 |
logits=logits,
|
| 1663 |
past_key_values=outputs.past_key_values,
|
|
@@ -1873,7 +1873,7 @@ class LlavaOnevision2ForConditionalGeneration(LlavaOnevision2PreTrainedModel, Ge
|
|
| 1873 |
|
| 1874 |
|
| 1875 |
__all__ = [
|
| 1876 |
-
"
|
| 1877 |
-
"
|
| 1878 |
-
"
|
| 1879 |
]
|
|
|
|
| 22 |
)
|
| 23 |
from transformers.utils.generic import is_flash_attention_requested
|
| 24 |
|
| 25 |
+
from .configuration_llava_onevision2_5 import LlavaOnevision2_5Config, LlavaOnevision2_5VisionConfig
|
| 26 |
|
| 27 |
|
| 28 |
def _default_patch_positions_from_grid(grid_thw, spatial_merge_size, device):
|
|
|
|
| 168 |
Base class for Llava-Onevision-1.5 outputs, with hidden states and attentions.
|
| 169 |
"""
|
| 170 |
)
|
| 171 |
+
class LlavaOnevision2_5ModelOutputWithPast(ModelOutput):
|
| 172 |
r"""
|
| 173 |
past_key_values (`Cache`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
|
| 174 |
It is a [`~cache_utils.Cache`] instance. For more details, see our [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache).
|
|
|
|
| 189 |
Base class for Llava-Onevision-1.5 causal language model (or autoregressive) outputs.
|
| 190 |
"""
|
| 191 |
)
|
| 192 |
+
class LlavaOnevision2_5CausalLMOutputWithPast(ModelOutput):
|
| 193 |
r"""
|
| 194 |
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
|
| 195 |
Language modeling loss (for next-token prediction).
|
|
|
|
| 220 |
Supports both grid_thw-based and explicit position-based RoPE computation.
|
| 221 |
"""
|
| 222 |
|
| 223 |
+
def __init__(self, config: LlavaOnevision2_5VisionConfig):
|
| 224 |
super().__init__()
|
| 225 |
head_dim = config.hidden_size // config.num_attention_heads
|
| 226 |
base = config.rope_theta
|
|
|
|
| 364 |
Output format: [total_patches, embed_dim]
|
| 365 |
"""
|
| 366 |
|
| 367 |
+
def __init__(self, config: LlavaOnevision2_5VisionConfig):
|
| 368 |
super().__init__()
|
| 369 |
self.config = config
|
| 370 |
self.embed_dim = config.hidden_size
|
|
|
|
| 393 |
# ---------------------------------------------------------------------------
|
| 394 |
|
| 395 |
|
| 396 |
+
class LlavaOnevision2_5VisionPatchMerger(nn.Module):
|
| 397 |
"""
|
| 398 |
Patch merger that merges spatial_merge_size x spatial_merge_size patches into one.
|
| 399 |
|
|
|
|
| 488 |
based on ``config._attn_implementation``.
|
| 489 |
"""
|
| 490 |
|
| 491 |
+
def __init__(self, config: LlavaOnevision2_5VisionConfig):
|
| 492 |
super().__init__()
|
| 493 |
self.config = config
|
| 494 |
self.embed_dim = config.hidden_size
|
|
|
|
| 608 |
class OneVisionEncoderEncoderLayer(nn.Module):
|
| 609 |
"""Vision encoder layer with pre-norm and Flash Attention 2."""
|
| 610 |
|
| 611 |
+
def __init__(self, config: LlavaOnevision2_5VisionConfig):
|
| 612 |
super().__init__()
|
| 613 |
self.embed_dim = config.hidden_size
|
| 614 |
self.self_attn = OneVisionEncoderAttention(config)
|
|
|
|
| 648 |
|
| 649 |
|
| 650 |
class OneVisionEncoderEncoder(nn.Module):
|
| 651 |
+
def __init__(self, config: LlavaOnevision2_5VisionConfig):
|
| 652 |
super().__init__()
|
| 653 |
self.config = config
|
| 654 |
self.layers = nn.ModuleList([OneVisionEncoderEncoderLayer(config) for _ in range(config.num_hidden_layers)])
|
|
|
|
| 711 |
)
|
| 712 |
|
| 713 |
|
| 714 |
+
class LlavaOnevision2_5PreTrainedModel(PreTrainedModel):
|
| 715 |
+
config_class = LlavaOnevision2_5Config
|
| 716 |
base_model_prefix = "model"
|
| 717 |
input_modalities = ("image", "video", "text")
|
| 718 |
supports_gradient_checkpointing = True
|
|
|
|
| 744 |
Multi-Head Attention Pooling with a learned probe (PMA-style).
|
| 745 |
"""
|
| 746 |
|
| 747 |
+
def __init__(self, config: LlavaOnevision2_5VisionConfig):
|
| 748 |
super().__init__()
|
| 749 |
self.embed_dim = config.hidden_size
|
| 750 |
self.probe = nn.Parameter(torch.randn(1, 1, config.hidden_size))
|
|
|
|
| 770 |
# ---------------------------------------------------------------------------
|
| 771 |
|
| 772 |
|
| 773 |
+
class LlavaOnevision2_5VisionPretrainedModel(LlavaOnevision2_5PreTrainedModel):
|
| 774 |
"""
|
| 775 |
LLaVA-OneVision-2.5 Vision Model.
|
| 776 |
|
|
|
|
| 784 |
grid_thw: [num_samples, 3] with [t, h, w] for each sample
|
| 785 |
"""
|
| 786 |
|
| 787 |
+
def __init__(self, config: LlavaOnevision2_5VisionConfig):
|
| 788 |
super().__init__(config)
|
| 789 |
self.config = config
|
| 790 |
self.spatial_merge_size = config.spatial_merge_size
|
|
|
|
| 802 |
self.layernorm_post = None
|
| 803 |
self.head = None
|
| 804 |
|
| 805 |
+
self.merger = LlavaOnevision2_5VisionPatchMerger(
|
| 806 |
dim=config.out_hidden_size,
|
| 807 |
context_dim=config.hidden_size,
|
| 808 |
spatial_merge_size=config.spatial_merge_size,
|
|
|
|
| 926 |
|
| 927 |
return attn_mask
|
| 928 |
|
| 929 |
+
@replace_return_docstrings(output_type=BaseModelOutputWithPooling, config_class=LlavaOnevision2_5VisionConfig)
|
| 930 |
def forward(
|
| 931 |
self,
|
| 932 |
hidden_state: torch.Tensor,
|
|
|
|
| 1175 |
|
| 1176 |
|
| 1177 |
@auto_docstring
|
| 1178 |
+
class LlavaOnevision2_5Model(LlavaOnevision2_5PreTrainedModel):
|
| 1179 |
base_model_prefix = ""
|
| 1180 |
# Reference: fix gemma3 grad acc #37208
|
| 1181 |
accepts_loss_kwargs = False
|
| 1182 |
+
config: LlavaOnevision2_5Config
|
| 1183 |
_no_split_modules = ["OneVisionEncoderEncoderLayer", "Qwen3DecoderLayer"]
|
| 1184 |
|
| 1185 |
+
def __init__(self, config: LlavaOnevision2_5Config):
|
| 1186 |
super().__init__(config)
|
| 1187 |
+
self.visual = LlavaOnevision2_5VisionPretrainedModel._from_config(config.vision_config)
|
| 1188 |
self.language_model = AutoModel.from_config(config.text_config)
|
| 1189 |
|
| 1190 |
# Initialize weights and apply final processing
|
|
|
|
| 1353 |
second_per_grid_ts: Optional[torch.Tensor] = None,
|
| 1354 |
mm_token_type_ids: torch.Tensor | None = None, # emitted by Qwen2.5-VL-style processors; accepted and ignored
|
| 1355 |
**kwargs: Unpack[TransformersKwargs],
|
| 1356 |
+
) -> Union[tuple, LlavaOnevision2_5ModelOutputWithPast]:
|
| 1357 |
r"""
|
| 1358 |
image_grid_thw (`torch.LongTensor` of shape `(num_images, 3)`, *optional*):
|
| 1359 |
The temporal, height and width of feature shape of each image in LLM.
|
|
|
|
| 1370 |
Indices depicting the position of the input sequence tokens in the sequence. Contrarily to
|
| 1371 |
`position_ids`, this tensor is not affected by padding.
|
| 1372 |
|
| 1373 |
+
Note: see the top-level ``LlavaOnevision2_5ForConditionalGeneration.forward``
|
| 1374 |
docstring; in P0 video flows in via the ``image_grid_thw`` / ``pixel_values``
|
| 1375 |
alias, so ``pixel_values_videos`` / ``video_grid_thw`` /
|
| 1376 |
``second_per_grid_ts`` are unused at this layer.
|
|
|
|
| 1482 |
**kwargs,
|
| 1483 |
)
|
| 1484 |
|
| 1485 |
+
output = LlavaOnevision2_5ModelOutputWithPast(
|
| 1486 |
last_hidden_state=outputs.last_hidden_state,
|
| 1487 |
past_key_values=outputs.past_key_values,
|
| 1488 |
hidden_states=outputs.hidden_states,
|
|
|
|
| 1492 |
|
| 1493 |
|
| 1494 |
@auto_docstring
|
| 1495 |
+
class LlavaOnevision2_5ForConditionalGeneration(LlavaOnevision2_5PreTrainedModel, GenerationMixin):
|
| 1496 |
_tied_weights_keys = {"lm_head.weight": "model.language_model.embed_tokens.weight"}
|
| 1497 |
# Reference: fix gemma3 grad acc #37208
|
| 1498 |
accepts_loss_kwargs = False
|
| 1499 |
|
| 1500 |
def __init__(self, config):
|
| 1501 |
super().__init__(config)
|
| 1502 |
+
self.model = LlavaOnevision2_5Model(config)
|
| 1503 |
self.lm_head = nn.Linear(config.text_config.hidden_size, config.text_config.vocab_size, bias=False)
|
| 1504 |
self.post_init()
|
| 1505 |
|
|
|
|
| 1558 |
logits_to_keep: Union[int, torch.Tensor] = 0,
|
| 1559 |
mm_token_type_ids: torch.Tensor | None = None, # emitted by Qwen2.5-VL-style processors; accepted and ignored
|
| 1560 |
**kwargs: Unpack[TransformersKwargs],
|
| 1561 |
+
) -> Union[tuple, LlavaOnevision2_5CausalLMOutputWithPast]:
|
| 1562 |
r"""
|
| 1563 |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 1564 |
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
|
|
|
| 1580 |
`position_ids`, this tensor is not affected by padding.
|
| 1581 |
|
| 1582 |
Note (P0 native-video alias):
|
| 1583 |
+
The companion ``LlavaOnevision2_5Processor.__call__(videos=...)`` does NOT
|
| 1584 |
pass ``pixel_values_videos`` / ``video_grid_thw`` / ``second_per_grid_ts``
|
| 1585 |
to this forward. Instead it aliases the video patch tensor as
|
| 1586 |
``pixel_values=`` and ``image_grid_thw=``, so video inputs share the
|
|
|
|
| 1596 |
```python
|
| 1597 |
>>> from PIL import Image
|
| 1598 |
>>> import requests
|
| 1599 |
+
>>> from transformers import AutoProcessor, LlavaOnevision2_5ForConditionalGeneration
|
| 1600 |
|
| 1601 |
+
>>> model = LlavaOnevision2_5ForConditionalGeneration.from_pretrained("lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct", trust_remote_code=True)
|
| 1602 |
>>> processor = AutoProcessor.from_pretrained("lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct", trust_remote_code=True)
|
| 1603 |
|
| 1604 |
>>> messages = [
|
|
|
|
| 1657 |
logits=logits, labels=labels, vocab_size=self.config.text_config.vocab_size, **kwargs
|
| 1658 |
)
|
| 1659 |
|
| 1660 |
+
return LlavaOnevision2_5CausalLMOutputWithPast(
|
| 1661 |
loss=loss,
|
| 1662 |
logits=logits,
|
| 1663 |
past_key_values=outputs.past_key_values,
|
|
|
|
| 1873 |
|
| 1874 |
|
| 1875 |
__all__ = [
|
| 1876 |
+
"LlavaOnevision2_5ForConditionalGeneration",
|
| 1877 |
+
"LlavaOnevision2_5Model",
|
| 1878 |
+
"LlavaOnevision2_5PreTrainedModel",
|
| 1879 |
]
|
preprocessor_config.json
CHANGED
|
@@ -20,10 +20,10 @@
|
|
| 20 |
"min_pixels": 3136,
|
| 21 |
"merge_size": 3,
|
| 22 |
"patch_size": 16,
|
| 23 |
-
"processor_class": "
|
| 24 |
"auto_map": {
|
| 25 |
-
"AutoProcessor": "processing_llava_onevision2_5.
|
| 26 |
-
"AutoVideoProcessor": "video_processing_llava_onevision2_5.
|
| 27 |
},
|
| 28 |
"resample": 3,
|
| 29 |
"rescale_factor": 0.00392156862745098,
|
|
|
|
| 20 |
"min_pixels": 3136,
|
| 21 |
"merge_size": 3,
|
| 22 |
"patch_size": 16,
|
| 23 |
+
"processor_class": "LlavaOnevision2_5Processor",
|
| 24 |
"auto_map": {
|
| 25 |
+
"AutoProcessor": "processing_llava_onevision2_5.LlavaOnevision2_5Processor",
|
| 26 |
+
"AutoVideoProcessor": "video_processing_llava_onevision2_5.LlavaOnevision2_5VideoProcessor"
|
| 27 |
},
|
| 28 |
"resample": 3,
|
| 29 |
"rescale_factor": 0.00392156862745098,
|
processing_llava_onevision2_5.py
CHANGED
|
@@ -1,13 +1,13 @@
|
|
| 1 |
-
"""
|
| 2 |
|
| 3 |
Combines:
|
| 4 |
- ``Qwen2VLImageProcessor[Fast]`` (existing in checkpoint preprocessor_config)
|
| 5 |
-
- ``
|
| 6 |
- ``AutoTokenizer`` (existing tokenizer.json)
|
| 7 |
- ``chat_template.jinja`` (existing, emits <|video_pad|>)
|
| 8 |
|
| 9 |
Public API:
|
| 10 |
-
proc =
|
| 11 |
text = proc.apply_chat_template(messages, add_generation_prompt=True)
|
| 12 |
inputs = proc(text=[text], videos=[mp4_or_frames], return_tensors="pt")
|
| 13 |
out = model.generate(**inputs)
|
|
@@ -64,8 +64,8 @@ def _expand_video_block_for_frames(
|
|
| 64 |
return "".join(parts)
|
| 65 |
|
| 66 |
|
| 67 |
-
class
|
| 68 |
-
"""Native multi-modal processor for
|
| 69 |
|
| 70 |
NOTE: We deliberately do NOT inherit ``transformers.ProcessorMixin``.
|
| 71 |
This class is registered via ``auto_map`` so
|
|
@@ -132,11 +132,11 @@ class LlavaOnevision2Processor:
|
|
| 132 |
# ``get_class_from_dynamic_module``, which places sibling files on
|
| 133 |
# ``sys.path``).
|
| 134 |
try:
|
| 135 |
-
from .video_processing_llava_onevision2_5 import
|
| 136 |
except ImportError:
|
| 137 |
-
from video_processing_llava_onevision2_5 import
|
| 138 |
|
| 139 |
-
video_processor =
|
| 140 |
image_processor=image_processor,
|
| 141 |
min_pixels=getattr(image_processor, "min_pixels", 256 * 28 * 28),
|
| 142 |
max_pixels=getattr(image_processor, "max_pixels", 1605632),
|
|
@@ -533,7 +533,7 @@ class LlavaOnevision2Processor:
|
|
| 533 |
|
| 534 |
|
| 535 |
__all__ = [
|
| 536 |
-
"
|
| 537 |
"VISION_START",
|
| 538 |
"VISION_END",
|
| 539 |
"IMAGE_PAD",
|
|
|
|
| 1 |
+
"""LlavaOnevision2_5 multi-modal processor.
|
| 2 |
|
| 3 |
Combines:
|
| 4 |
- ``Qwen2VLImageProcessor[Fast]`` (existing in checkpoint preprocessor_config)
|
| 5 |
+
- ``LlavaOnevision2_5VideoProcessor`` (this checkpoint, video_processing_*)
|
| 6 |
- ``AutoTokenizer`` (existing tokenizer.json)
|
| 7 |
- ``chat_template.jinja`` (existing, emits <|video_pad|>)
|
| 8 |
|
| 9 |
Public API:
|
| 10 |
+
proc = LlavaOnevision2_5Processor(image_processor, tokenizer, video_processor)
|
| 11 |
text = proc.apply_chat_template(messages, add_generation_prompt=True)
|
| 12 |
inputs = proc(text=[text], videos=[mp4_or_frames], return_tensors="pt")
|
| 13 |
out = model.generate(**inputs)
|
|
|
|
| 64 |
return "".join(parts)
|
| 65 |
|
| 66 |
|
| 67 |
+
class LlavaOnevision2_5Processor:
|
| 68 |
+
"""Native multi-modal processor for LlavaOnevision2_5.
|
| 69 |
|
| 70 |
NOTE: We deliberately do NOT inherit ``transformers.ProcessorMixin``.
|
| 71 |
This class is registered via ``auto_map`` so
|
|
|
|
| 132 |
# ``get_class_from_dynamic_module``, which places sibling files on
|
| 133 |
# ``sys.path``).
|
| 134 |
try:
|
| 135 |
+
from .video_processing_llava_onevision2_5 import LlavaOnevision2_5VideoProcessor
|
| 136 |
except ImportError:
|
| 137 |
+
from video_processing_llava_onevision2_5 import LlavaOnevision2_5VideoProcessor
|
| 138 |
|
| 139 |
+
video_processor = LlavaOnevision2_5VideoProcessor(
|
| 140 |
image_processor=image_processor,
|
| 141 |
min_pixels=getattr(image_processor, "min_pixels", 256 * 28 * 28),
|
| 142 |
max_pixels=getattr(image_processor, "max_pixels", 1605632),
|
|
|
|
| 533 |
|
| 534 |
|
| 535 |
__all__ = [
|
| 536 |
+
"LlavaOnevision2_5Processor",
|
| 537 |
"VISION_START",
|
| 538 |
"VISION_END",
|
| 539 |
"IMAGE_PAD",
|
processor_config.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
{
|
| 2 |
-
"processor_class": "
|
| 3 |
"auto_map": {
|
| 4 |
-
"AutoProcessor": "processing_llava_onevision2_5.
|
| 5 |
-
"AutoVideoProcessor": "video_processing_llava_onevision2_5.
|
| 6 |
},
|
| 7 |
"image_processor": {
|
| 8 |
"do_convert_rgb": true,
|
|
@@ -32,8 +32,8 @@
|
|
| 32 |
"temporal_patch_size": 1
|
| 33 |
},
|
| 34 |
"video_processor": {
|
| 35 |
-
"video_processor_type": "
|
| 36 |
-
"processor_class": "
|
| 37 |
"max_frames": 768,
|
| 38 |
"fixed_num_frames": null,
|
| 39 |
"target_fps": null,
|
|
|
|
| 1 |
{
|
| 2 |
+
"processor_class": "LlavaOnevision2_5Processor",
|
| 3 |
"auto_map": {
|
| 4 |
+
"AutoProcessor": "processing_llava_onevision2_5.LlavaOnevision2_5Processor",
|
| 5 |
+
"AutoVideoProcessor": "video_processing_llava_onevision2_5.LlavaOnevision2_5VideoProcessor"
|
| 6 |
},
|
| 7 |
"image_processor": {
|
| 8 |
"do_convert_rgb": true,
|
|
|
|
| 32 |
"temporal_patch_size": 1
|
| 33 |
},
|
| 34 |
"video_processor": {
|
| 35 |
+
"video_processor_type": "LlavaOnevision2_5VideoProcessor",
|
| 36 |
+
"processor_class": "LlavaOnevision2_5Processor",
|
| 37 |
"max_frames": 768,
|
| 38 |
"fixed_num_frames": null,
|
| 39 |
"target_fps": null,
|
video_preprocessor_config.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
-
"video_processor_type": "
|
| 3 |
-
"processor_class": "
|
| 4 |
"max_frames": 768,
|
| 5 |
"fixed_num_frames": null,
|
| 6 |
"target_fps": null,
|
|
@@ -11,7 +11,7 @@
|
|
| 11 |
"temporal_patch_size": 1,
|
| 12 |
"resize_frames": true,
|
| 13 |
"auto_map": {
|
| 14 |
-
"AutoProcessor": "processing_llava_onevision2_5.
|
| 15 |
-
"AutoVideoProcessor": "video_processing_llava_onevision2_5.
|
| 16 |
}
|
| 17 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"video_processor_type": "LlavaOnevision2_5VideoProcessor",
|
| 3 |
+
"processor_class": "LlavaOnevision2_5Processor",
|
| 4 |
"max_frames": 768,
|
| 5 |
"fixed_num_frames": null,
|
| 6 |
"target_fps": null,
|
|
|
|
| 11 |
"temporal_patch_size": 1,
|
| 12 |
"resize_frames": true,
|
| 13 |
"auto_map": {
|
| 14 |
+
"AutoProcessor": "processing_llava_onevision2_5.LlavaOnevision2_5Processor",
|
| 15 |
+
"AutoVideoProcessor": "video_processing_llava_onevision2_5.LlavaOnevision2_5VideoProcessor"
|
| 16 |
}
|
| 17 |
}
|
video_processing_llava_onevision2_5.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
-
"""Video frame extraction helpers for
|
| 2 |
|
| 3 |
Helpers (decord-first / opencv-fallback decoding) are used by
|
| 4 |
-
``
|
| 5 |
|
| 6 |
The helpers were ported from the training pipeline with minor cleanups:
|
| 7 |
- dropped wrapper-only imports
|
|
@@ -405,11 +405,11 @@ def build_patch_positions(
|
|
| 405 |
|
| 406 |
|
| 407 |
# =============================================================================
|
| 408 |
-
#
|
| 409 |
# =============================================================================
|
| 410 |
# A thin processor that wraps `Qwen2VLImageProcessor` to convert raw video
|
| 411 |
# files (or pre-decoded frame lists) into the tensor bundle needed by the
|
| 412 |
-
#
|
| 413 |
#
|
| 414 |
# Output (BatchFeature):
|
| 415 |
# - pixel_values_videos : [sum(T*H_p*W_p), C, P, P] patch tensor
|
|
@@ -420,8 +420,8 @@ def build_patch_positions(
|
|
| 420 |
# Aligned with the modeling code, we deliberately
|
| 421 |
# DO NOT emit `second_per_grid_ts`.
|
| 422 |
|
| 423 |
-
class
|
| 424 |
-
"""Decode + sample + patch-ify videos for
|
| 425 |
|
| 426 |
Designed to be standalone (does not inherit ``transformers.ProcessorMixin``)
|
| 427 |
so it can be unit-tested without the full Processor stack.
|
|
@@ -779,5 +779,5 @@ __all__ = [
|
|
| 779 |
"extract_video_frames",
|
| 780 |
"extract_video_frames_to_pil",
|
| 781 |
"build_patch_positions",
|
| 782 |
-
"
|
| 783 |
]
|
|
|
|
| 1 |
+
"""Video frame extraction helpers for LlavaOnevision2_5 native video input.
|
| 2 |
|
| 3 |
Helpers (decord-first / opencv-fallback decoding) are used by
|
| 4 |
+
``LlavaOnevision2_5VideoProcessor`` defined below.
|
| 5 |
|
| 6 |
The helpers were ported from the training pipeline with minor cleanups:
|
| 7 |
- dropped wrapper-only imports
|
|
|
|
| 405 |
|
| 406 |
|
| 407 |
# =============================================================================
|
| 408 |
+
# LlavaOnevision2_5VideoProcessor
|
| 409 |
# =============================================================================
|
| 410 |
# A thin processor that wraps `Qwen2VLImageProcessor` to convert raw video
|
| 411 |
# files (or pre-decoded frame lists) into the tensor bundle needed by the
|
| 412 |
+
# LlavaOnevision2_5 model.
|
| 413 |
#
|
| 414 |
# Output (BatchFeature):
|
| 415 |
# - pixel_values_videos : [sum(T*H_p*W_p), C, P, P] patch tensor
|
|
|
|
| 420 |
# Aligned with the modeling code, we deliberately
|
| 421 |
# DO NOT emit `second_per_grid_ts`.
|
| 422 |
|
| 423 |
+
class LlavaOnevision2_5VideoProcessor:
|
| 424 |
+
"""Decode + sample + patch-ify videos for LlavaOnevision2_5.
|
| 425 |
|
| 426 |
Designed to be standalone (does not inherit ``transformers.ProcessorMixin``)
|
| 427 |
so it can be unit-tested without the full Processor stack.
|
|
|
|
| 779 |
"extract_video_frames",
|
| 780 |
"extract_video_frames_to_pil",
|
| 781 |
"build_patch_positions",
|
| 782 |
+
"LlavaOnevision2_5VideoProcessor",
|
| 783 |
]
|