Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 docs/source/en/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,8 @@
title: InstructBlipVideo
- local: model_doc/internvl
title: InternVL
- local: model_doc/internvl_flash
title: InternVLFlash
- local: model_doc/janus
title: Janus
- local: model_doc/kosmos-2
Expand Down
74 changes: 74 additions & 0 deletions docs/source/en/model_doc/internvl_flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!--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 released on {release_date} and added to Hugging Face Transformers on 2025-11-25.*


# [InternVLFlash]

## Overview

The [InternVLFlash] model was proposed in [<INSERT PAPER NAME HERE>](<INSERT PAPER LINK HERE>) by <INSERT AUTHORS HERE>.
<INSERT SHORT SUMMARY HERE>

The abstract from the paper is the following:

<INSERT PAPER ABSTRACT HERE>

Tips:

<INSERT TIPS ABOUT MODEL HERE>

This model was contributed by [INSERT YOUR HF USERNAME HERE](https://huggingface.co/<INSERT YOUR HF USERNAME HERE>).
The original code can be found [here](<INSERT LINK TO GITHUB REPO HERE>).

## Usage examples

<INSERT SOME NICE EXAMPLES HERE>

## InternvlFlashVisionConfig

[[autodoc]] InternvlFlashVisionConfig

## InternvlFlashConfig

[[autodoc]] InternvlFlashConfig

## InternvlFlashVisionPreTrainedModel

[[autodoc]] InternvlFlashVisionPreTrainedModel
- forward

## InternvlFlashVisionModel

[[autodoc]] InternvlFlashVisionModel
- forward

## InternvlFlashPreTrainedModel

[[autodoc]] InternvlFlashPreTrainedModel
- forward

## InternvlFlashModel

[[autodoc]] InternvlFlashModel
- forward

## InternvlFlashForConditionalGeneration

[[autodoc]] InternvlFlashForConditionalGeneration
1 change: 1 addition & 0 deletions src/transformers/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
from .instructblip import *
from .instructblipvideo import *
from .internvl import *
from .internvl_flash import *
from .jamba import *
from .janus import *
from .jetmoe import *
Expand Down
5 changes: 5 additions & 0 deletions src/transformers/models/auto/configuration_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@
("instructblip", "InstructBlipConfig"),
("instructblipvideo", "InstructBlipVideoConfig"),
("internvl", "InternVLConfig"),
("internvl_flash", "InternvlFlashConfig"),
("internvl_flash_vision", "InternvlFlashVisionConfig"),
("internvl_vision", "InternVLVisionConfig"),
("jamba", "JambaConfig"),
("janus", "JanusConfig"),
Expand Down Expand Up @@ -663,6 +665,8 @@
("instructblip", "InstructBLIP"),
("instructblipvideo", "InstructBlipVideo"),
("internvl", "InternVL"),
("internvl_flash", "InternVLFlash"),
("internvl_flash_vision", "InternVLFlashVision"),
("internvl_vision", "InternVLVision"),
("jamba", "Jamba"),
("janus", "Janus"),
Expand Down Expand Up @@ -994,6 +998,7 @@
("rt_detr_resnet", "rt_detr"),
("granitevision", "llava_next"),
("internvl_vision", "internvl"),
("internvl_flash_vision", "internvl_flash"),
("qwen2_5_vl_text", "qwen2_5_vl"),
("qwen2_vl_text", "qwen2_vl"),
("qwen3_vl_text", "qwen3_vl"),
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 @@ -215,6 +215,8 @@ class _BaseModelWithGenerate(PreTrainedModel, GenerationMixin):
("instructblip", "InstructBlipModel"),
("instructblipvideo", "InstructBlipVideoModel"),
("internvl", "InternVLModel"),
("internvl_flash", "InternvlFlashModel"),
("internvl_flash_vision", "InternvlFlashVisionModel"),
("internvl_vision", "InternVLVisionModel"),
("jamba", "JambaModel"),
("janus", "JanusModel"),
Expand Down Expand Up @@ -1040,6 +1042,7 @@ class _BaseModelWithGenerate(PreTrainedModel, GenerationMixin):
("idefics3", "Idefics3ForConditionalGeneration"),
("instructblip", "InstructBlipForConditionalGeneration"),
("internvl", "InternVLForConditionalGeneration"),
("internvl_flash", "InternvlFlashForConditionalGeneration"),
("janus", "JanusForConditionalGeneration"),
("kosmos-2", "Kosmos2ForConditionalGeneration"),
("kosmos-2.5", "Kosmos2_5ForConditionalGeneration"),
Expand Down
29 changes: 29 additions & 0 deletions src/transformers/models/internvl_flash/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# coding=utf-8
# 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.

from typing import TYPE_CHECKING

from ...utils import _LazyModule
from ...utils.import_utils import define_import_structure


if TYPE_CHECKING:
from .configuration_internvl_flash import *
from .modeling_internvl_flash import *
else:
import sys

_file = globals()["__file__"]
sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__)
230 changes: 230 additions & 0 deletions src/transformers/models/internvl_flash/configuration_internvl_flash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
# This file was automatically generated from src/transformers/models/internvl_flash/modular_internvl_flash.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_internvl_flash.py file directly. One of our CI enforces this.
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
# coding=utf-8
# 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.

from ...configuration_utils import PreTrainedConfig
from ..auto import CONFIG_MAPPING, AutoConfig


class InternvlFlashVisionConfig(PreTrainedConfig):
r"""
This is the configuration class to store the configuration of a [`InternvlFlashVisionModel`]. It is used to instantiate an InternvlFlashVisionModel
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the defaults will yield
a similar configuration to that of the InternvlFlash3-1B.
e.g. [OpenGVLab/InternvlFlash3-1B-hf](https://huggingface.co/OpenGVLab/InternvlFlash3-1B-hf)

Args:
hidden_size (`int`, *optional*, defaults to 1024):
Dimensionality of the encoder layers and the pooler layer.
num_hidden_layers (`int`, *optional*, defaults to 24):
Number of hidden layers in the Transformer encoder.
num_attention_heads (`int`, *optional*, defaults to 16):
Number of attention heads for each attention layer in the Transformer encoder.
attention_bias (`bool`, *optional*, defaults to `False`):
Whether to add a bias to the queries, keys and values.
use_qk_norm (`bool`, *optional*, defaults to `False`):
Whether to apply normalization to the queries and keys before the attention operation.
intermediate_size (`int`, *optional*, defaults to 4096):
Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
`"relu"`, `"selu"` and `"gelu_new"` are supported.
hidden_dropout_prob (`float`, *optional*, defaults to 0.0):
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
attention_dropout (`float`, *optional*, defaults to 0.0):
Dropout probability for attention weights.
projection_dropout (`float`, *optional*, defaults to 0.0):
Dropout probability for the projection layer.
initializer_range (`float`, *optional*, defaults to 0.02):
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
norm_type (`str`, *optional*, defaults to `"layer_norm"`):
The type of normalization to use in the encoder. Can be `"layer_norm"` or `"rms_norm"`.
layer_norm_eps (`float`, *optional*, defaults to 1e-06):
The epsilon used by the layer normalization layers.
image_size (`int` or `list[int]`, *optional*, defaults to `[448, 448]`):
The size (resolution) of each image.
patch_size (`int` or `list[int]`, *optional*, defaults to `[14, 14]`):
The size (resolution) of each patch.
num_channels (`int`, *optional*, defaults to 3):
The number of input channels.
use_mask_token (`bool`, *optional*, defaults to `False`):
Whether to use a mask token for masked image modeling.
use_absolute_position_embeddings (`bool`, *optional*, defaults to `True`):
Whether to use BERT-style absolute position embeddings.
layer_scale_init_value (`float`, *optional*, defaults to 0.1):
Scale to use in the self-attention layers. 0.1 for base, 1e-5 for large. Set 0 to disable layer scale.
use_mean_pooling (`bool`, *optional*, defaults to `True`):
Whether to mean pool the final hidden states of the patches instead of using the final hidden state of the
CLS token, before applying the classification head.

Example:

```python
>>> from transformers import InternvlFlashVisionConfig, InternvlFlashVisionModel

>>> # Initializing a InternvlFlashVisionModel OpenGVLab/InternvlFlash3-1B-hf style configuration
>>> configuration = InternvlFlashVisionConfig()

>>> # Initializing a model (with random weights) from the OpenGVLab/InternvlFlash3-1B-hf configuration
>>> model = InternvlFlashVisionModel(configuration)

>>> # Accessing the model configuration
>>> configuration = model.config
```"""

model_type = "internvl_flash_vision"
base_config_key = "vision_config"

def __init__(
self,
hidden_size=1024,
num_hidden_layers=24,
num_attention_heads=16,
attention_bias=False,
use_qk_norm=False,
intermediate_size=4096,
hidden_act="gelu",
hidden_dropout_prob=0.0,
attention_dropout=0.0,
projection_dropout=0.0,
initializer_range=0.02,
norm_type="layer_norm",
layer_norm_eps=1e-06,
image_size=[448, 448],
patch_size=[14, 14],
num_channels=3,
use_mask_token=False,
use_absolute_position_embeddings=True,
layer_scale_init_value=0.1,
use_mean_pooling=True,
**kwargs,
):
super().__init__(**kwargs)

self.hidden_size = hidden_size
self.num_hidden_layers = num_hidden_layers
self.num_attention_heads = num_attention_heads
self.attention_bias = attention_bias
self.use_qk_norm = use_qk_norm
self.intermediate_size = intermediate_size
self.hidden_act = hidden_act
self.hidden_dropout_prob = hidden_dropout_prob
self.attention_dropout = attention_dropout
self.projection_dropout = projection_dropout
self.initializer_range = initializer_range
self.norm_type = norm_type
self.layer_norm_eps = layer_norm_eps

image_size = image_size if isinstance(image_size, (list, tuple)) else (image_size, image_size)
patch_size = patch_size if isinstance(patch_size, (list, tuple)) else (patch_size, patch_size)
self.image_size = image_size
self.patch_size = patch_size

self.num_channels = num_channels
self.use_mask_token = use_mask_token
self.use_absolute_position_embeddings = use_absolute_position_embeddings
self.layer_scale_init_value = layer_scale_init_value
self.use_mean_pooling = use_mean_pooling


class InternvlFlashConfig(PreTrainedConfig):
r"""
This is the configuration class to store the configuration of a [`InternvlFlashForConditionalGeneration`]. It is used to instantiate a
InternvlFlash model according to the specified arguments, defining the model architecture. Instantiating a configuration
with the defaults will yield a similar configuration to that of InternvlFlash3-1B.
e.g. [OpenGVLab/InternvlFlash3-1B-hf](https://huggingface.co/OpenGVLab/InternvlFlash3-1B-hf)

Configuration objects inherit from [`PreTrainedConfig`] and can be used to control the model outputs. Read the
documentation from [`PreTrainedConfig`] for more information.


Args:
vision_config (`Union[AutoConfig, dict]`, *optional*, defaults to `InternVisonConfig`):
The config object or dictionary of the vision backbone.
text_config (`Union[AutoConfig, dict]`, *optional*, defaults to `Qwen2Config`):
The config object or dictionary of the text backbone.
image_token_id (`int`, *optional*, defaults to 151667):
The image token index to encode the image prompt.
image_seq_length (`int`, *optional*, defaults to 256):
Number of image tokens to use per image patch.
downsample_ratio (`float`, *optional*, defaults to 0.5):
Factor by which to downsample the image.
projector_hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
The non-linear activation function (function or string) in the projector.
vision_feature_layer (`int`, *optional*, defaults to -1):
The index of the layer to use as the image features.
vision_feature_select_strategy (`str`, *optional*, defaults to `"default"`):
The feature selection strategy used to select the vision feature from the vision backbone.
Can be one of `"default"` or `"full"`.

```python
>>> from transformers import InternvlFlashForConditionalGeneration, InternvlFlashConfig

>>> # Initializing a InternvlFlash style configuration
>>> configuration = InternvlFlashConfig()

>>> # Initializing a model (with random weights) from the OpenGVLab/InternvlFlash3-1B-hf configuration
>>> model = InternvlFlashForConditionalGeneration(configuration)

>>> # Accessing the model configuration
>>> configuration = model.config
```"""

model_type = "internvl_flash"
sub_configs = {"text_config": AutoConfig, "vision_config": InternvlFlashVisionConfig}

def __init__(
self,
vision_config=None,
text_config=None,
image_token_id=151667,
image_seq_length=256,
downsample_ratio=0.5,
projector_hidden_act="gelu",
vision_feature_layer=-1,
vision_feature_select_strategy="default",
**kwargs,
):
self.image_token_id = image_token_id
self.image_seq_length = image_seq_length
self.downsample_ratio = downsample_ratio
self.projector_hidden_act = projector_hidden_act
self.vision_feature_layer = vision_feature_layer
self.vision_feature_select_strategy = vision_feature_select_strategy

if isinstance(vision_config, dict):
self.vision_config = InternvlFlashVisionConfig(**vision_config)
elif isinstance(vision_config, InternvlFlashVisionConfig):
self.vision_config = vision_config
elif vision_config is None:
self.vision_config = InternvlFlashVisionConfig()

if isinstance(text_config, dict):
text_config["model_type"] = text_config.get("model_type", "qwen2")
text_config = CONFIG_MAPPING[text_config["model_type"]](**text_config)
elif text_config is None:
text_config = CONFIG_MAPPING["qwen2"]()

self.text_config = text_config

super().__init__(**kwargs)


__all__ = ["InternvlFlashConfig", "InternvlFlashVisionConfig"]
Loading