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
4 changes: 4 additions & 0 deletions paddleformers/transformers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@
"paddleocr_vl.modeling": ["PaddleOCRVLForConditionalGeneration"],
"paddleocr_vl.image_processor": ["PaddleOCRVLImageProcessor"],
"paddleocr_vl.processor": ["PaddleOCRVLProcessor"],
"internvl3_5.configuration": ["InternVisionConfig", "InternVLChatConfig"],
"internvl3_5.modeling": ["InternVisionModel", "InternVLChatModel"],
"internvl3_5.image_processor": ["InternVLImageProcessor"],
"internvl3_5.processor": ["InternVLProcessor"],
"gpt_oss.configuration": ["GptOssConfig"],
"gpt_oss.modeling": ["GptOssModel", "GptOssForCausalLM", "GptOssForCausalLMPipe"],
"granite.configuration": ["GraniteConfig"],
Expand Down
5 changes: 5 additions & 0 deletions paddleformers/transformers/auto/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
("shieldgemma2", "ShieldGemma2Config"),
("glm4v_moe", "Glm4vMoeConfig"),
("glm_ocr", "GlmOcrConfig"),
("internvl_chat", "InternVLChatConfig"),
("intern_vit_6b", "InternVisionConfig"),
("qwen3_5", "Qwen3_5Config"),
("qwen3_5_moe", "Qwen3_5MoEConfig"),
("olmo2", "Olmo2Config"),
Expand Down Expand Up @@ -114,6 +116,7 @@
("gemma3", "Gemma3ForConditionalGeneration"),
("gemma3_text", "Gemma3TextModel"),
("shieldgemma2", "ShieldGemma2ForImageClassification"),
("internvl_chat", "InternVLChat"),
("qwen3_5_moe", "Qwen3_5MoEForConditionalGeneration"),
("qwen3_5", "Qwen3_5ForConditionalGeneration"),
("olmo2", "Olmo2ForCausalLM"),
Expand All @@ -139,6 +142,8 @@
("qwen2_5_vl_text", "qwen2_5_vl"),
("qwen3_vl_text", "qwen3_vl"),
("qwen3_vl_moe_text", "qwen3_vl_moe"),
("internvl_chat", "internvl3_5"),
("intern_vit_6b", "internvl3_5"),
("internlm3", "intern_lm3"),
("internlm2", "intern"),
# TODO(VL): Remove these when Gemma4 VL module (gemma4/) is created
Expand Down
8 changes: 8 additions & 0 deletions paddleformers/transformers/auto/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
"qwen3_vl": ("Qwen3VLImageProcessor", "Qwen3VLImageProcessorFast"),
"glm_ocr": ("Glm46VImageProcessor"),
"paligemma": ("PaliGemmaImageProcessor"),
"internvl_chat": ("InternVLImageProcessor"),
"intern_vit_6b": ("InternVLImageProcessor"),
}
)

Expand Down Expand Up @@ -309,6 +311,12 @@ def from_pretrained(cls, pretrained_model_name_or_path, *inputs, **kwargs):
and config_dict.get("processor_class") == "PaliGemmaProcessor"
):
image_processor_type = "PaliGemmaImageProcessor"
if (
image_processor_type in {"GotOcr2ImageProcessor", "GotOcr2ImageProcessorFast"}
and config_dict.get("processor_class") == "InternVLProcessor"
):
image_processor_type = "InternVLImageProcessor"
use_fast = False
image_processor_auto_map = None
if "AutoImageProcessor" in config_dict.get("auto_map", {}):
image_processor_auto_map = config_dict["auto_map"]["AutoImageProcessor"]
Expand Down
1 change: 1 addition & 0 deletions paddleformers/transformers/auto/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
("Olmo2", "olmo2"),
("InternLM3", "intern_lm3"),
("InternLM2", "intern"),
("InternVLChat", "internvl3_5"),
]
)

Expand Down
1 change: 1 addition & 0 deletions paddleformers/transformers/auto/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
("glm4v_moe", "Glm4vProcessor"),
("glm_ocr", "Glm46VProcessor"),
("paligemma2", "PaliGemmaProcessor"),
("internvl_chat", "InternVLProcessor"),
]
)

Expand Down
28 changes: 28 additions & 0 deletions paddleformers/transformers/internvl3_5/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");

import sys
from typing import TYPE_CHECKING

from ...utils.lazy_import import _LazyModule

import_structure = {
"configuration": ["InternVisionConfig", "InternVLChatConfig"],
"image_processor": ["InternVLImageProcessor"],
"modeling": ["InternVisionModel", "InternVLChatModel"],
"processor": ["InternVLProcessor"],
}

if TYPE_CHECKING:
from .configuration import *
from .image_processor import *
from .modeling import *
from .processor import *
else:
sys.modules[__name__] = _LazyModule(
__name__,
globals()["__file__"],
import_structure,
module_spec=__spec__,
)
129 changes: 129 additions & 0 deletions paddleformers/transformers/internvl3_5/configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
# Copyright 2024 OpenGVLab. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");

import copy

from ..configuration_utils import PretrainedConfig
from ..qwen3.configuration import Qwen3Config
from ..qwen3_moe.configuration import Qwen3MoeConfig

__all__ = ["InternVisionConfig", "InternVLChatConfig"]


def _get_llm_config_class(llm_config):
if isinstance(llm_config, (Qwen3Config, Qwen3MoeConfig)):
return llm_config.__class__
model_type = llm_config.get("model_type") if isinstance(llm_config, dict) else None
architectures = llm_config.get("architectures", []) if isinstance(llm_config, dict) else []
if model_type == "qwen3_moe" or any(architecture.startswith("Qwen3Moe") for architecture in architectures):
return Qwen3MoeConfig
return Qwen3Config


class InternVisionConfig(PretrainedConfig):
model_type = "intern_vit_6b"
base_config_key = "vision_config"

def __init__(
self,
num_channels=3,
patch_size=14,
image_size=224,
qkv_bias=False,
hidden_size=3200,
num_attention_heads=25,
intermediate_size=12800,
qk_normalization=True,
num_hidden_layers=48,
use_flash_attn=True,
hidden_act="gelu",
norm_type="rms_norm",
layer_norm_eps=1e-6,
dropout=0.0,
drop_path_rate=0.0,
attention_dropout=0.0,
initializer_range=0.02,
initializer_factor=0.1,
**kwargs,
):
super().__init__(**kwargs)
self.hidden_size = hidden_size
self.intermediate_size = intermediate_size
self.dropout = dropout
self.drop_path_rate = drop_path_rate
self.num_hidden_layers = num_hidden_layers
self.num_attention_heads = num_attention_heads
self.num_channels = num_channels
self.patch_size = patch_size
self.image_size = image_size
self.initializer_range = initializer_range
self.initializer_factor = initializer_factor
self.attention_dropout = attention_dropout
self.layer_norm_eps = layer_norm_eps
self.hidden_act = hidden_act
self.norm_type = norm_type
self.qkv_bias = qkv_bias
self.qk_normalization = qk_normalization
self.use_flash_attn = use_flash_attn


class InternVLChatConfig(PretrainedConfig):
model_type = "internvl_chat"
is_composition = True
sub_configs = {"vision_config": InternVisionConfig, "llm_config": Qwen3Config}

def __init__(
self,
vision_config=None,
llm_config=None,
use_backbone_lora=0,
use_llm_lora=0,
select_layer=-1,
force_image_size=None,
downsample_ratio=0.5,
template=None,
dynamic_image_size=False,
use_thumbnail=False,
ps_version="v1",
min_dynamic_patch=1,
max_dynamic_patch=6,
img_context_token_id=151671,
**kwargs,
):
super().__init__(**kwargs)
if vision_config is None:
vision_config = {"architectures": ["InternVisionModel"]}
if llm_config is None:
llm_config = {"architectures": ["Qwen3ForCausalLM"]}

self.vision_config = InternVisionConfig(**vision_config) if isinstance(vision_config, dict) else vision_config
llm_config_class = _get_llm_config_class(llm_config)
self.llm_config = llm_config_class(**llm_config) if isinstance(llm_config, dict) else llm_config

self.use_backbone_lora = use_backbone_lora
self.use_llm_lora = use_llm_lora
self.select_layer = select_layer
self.force_image_size = force_image_size
self.downsample_ratio = downsample_ratio
self.template = template
self.dynamic_image_size = dynamic_image_size
self.use_thumbnail = use_thumbnail
self.ps_version = ps_version
self.min_dynamic_patch = min_dynamic_patch
self.max_dynamic_patch = max_dynamic_patch
self.img_context_token_id = img_context_token_id
self.tie_word_embeddings = self.llm_config.tie_word_embeddings
self.vocab_size = self.llm_config.vocab_size
self.hidden_size = self.llm_config.hidden_size
self.pad_token_id = getattr(self.llm_config, "pad_token_id", getattr(self, "pad_token_id", None))
self.eos_token_id = getattr(self.llm_config, "eos_token_id", getattr(self, "eos_token_id", None))
self.bos_token_id = getattr(self.llm_config, "bos_token_id", getattr(self, "bos_token_id", None))

def to_dict(self, *args, **kwargs):
output = copy.deepcopy(self.__dict__)
output["vision_config"] = self.vision_config.to_dict()
output["llm_config"] = self.llm_config.to_dict()
output["model_type"] = self.__class__.model_type
return output
Loading
Loading