Skip to content
Open
Show file tree
Hide file tree
Changes from 199 commits
Commits
Show all changes
203 commits
Select commit Hold shift + click to select a range
53d19b9
Transformers v5
echarlaix Jan 19, 2026
5205434
fix loading for llava_next_video
echarlaix Jan 19, 2026
e8feb0c
Remove deprecated transformers.onnx
echarlaix Jan 20, 2026
55e4b3d
Merge branch 'main' into transformers-v5
echarlaix Jan 23, 2026
bb54f64
remove deprecated transformers.onnx from tests
echarlaix Jan 23, 2026
71aa34e
remove huggingface_hub deprecated
echarlaix Jan 23, 2026
0954015
relative to absolute import
echarlaix Jan 23, 2026
1ba9789
update workflow to v5
echarlaix Jan 26, 2026
f158656
remove redundant
echarlaix Jan 26, 2026
9345143
update loading given transformers version
echarlaix Jan 26, 2026
b290ae3
remove deprecated AutoModelForVision2Seq
echarlaix Jan 26, 2026
a4d1dc0
update workflow
echarlaix Jan 26, 2026
ac953ba
style
echarlaix Jan 26, 2026
8001884
update setup
echarlaix Jan 26, 2026
5f2a007
deprecated is_offline_mode
echarlaix Jan 26, 2026
ad477fe
remove incompatible neural-compressor installation
echarlaix Jan 26, 2026
42e98b8
remove documentation reference
echarlaix Jan 26, 2026
4ee3f51
add install transformers step
echarlaix Jan 26, 2026
64c2022
Merge branch 'main' into transformers-v5
echarlaix Jan 27, 2026
8204264
transformers v5
echarlaix Jan 27, 2026
b319d19
install diffusers from source for v5
echarlaix Jan 27, 2026
42300e4
remove deprecated CLIPFeatureExtractor
echarlaix Jan 27, 2026
2a76102
openvino 2025.3.0
echarlaix Jan 28, 2026
f38703a
add ov cache classes
echarlaix Jan 29, 2026
46144d1
merge main in branch
echarlaix Jan 29, 2026
2d3c734
openvino nightly for modeling tests
echarlaix Jan 29, 2026
b6dcefd
openvino 2025.3 for modeling tests
echarlaix Jan 29, 2026
ea24727
stop moving misplaced parameters from config to generation_config
echarlaix Jan 29, 2026
07ff06b
fix transformers version for doc building
echarlaix Jan 29, 2026
1270db0
fix transformers version for doc building
echarlaix Jan 29, 2026
eb045ce
Use model.get_image_features
echarlaix Jan 29, 2026
f2f352d
Use model.get_image_features
echarlaix Jan 29, 2026
1db8fb9
only add codegen remote code models when transformers < v5
echarlaix Jan 29, 2026
0c72bc5
Fix pipelines
echarlaix Jan 30, 2026
08ebe2b
fix pipelines
echarlaix Jan 30, 2026
33f8c24
replace with OV cache
echarlaix Jan 30, 2026
9809e7e
style
echarlaix Jan 30, 2026
621e2bf
Use AutoProcessor instead of AutoFeatureExtractor
echarlaix Jan 30, 2026
30f6285
remove afmoe from models to be tested list
echarlaix Jan 30, 2026
6cd7b1c
fix pipeline saving tests
echarlaix Jan 30, 2026
4f2970b
merge main in branch
echarlaix Feb 2, 2026
85a0418
fix seq2seq pipeline tests loading
echarlaix Feb 2, 2026
08d1480
disable pipelines tests when transformers >= v5 since summarization/…
echarlaix Feb 2, 2026
7bc714c
fix MixtralModelPatcher
echarlaix Feb 2, 2026
8b374c7
fix moe patching
echarlaix Feb 2, 2026
a4cfc55
gptj fix
echarlaix Feb 3, 2026
5bab458
fix granitemoehybrid patcher
echarlaix Feb 3, 2026
daf7ec8
typo
echarlaix Feb 3, 2026
a45f5ab
add exaone max_transformers_version as incompatible with v5
echarlaix Feb 3, 2026
342dc59
add decilm max_transformers_version as incompatible with v5
echarlaix Feb 4, 2026
2a28fe7
fix llama4 patcher
echarlaix Feb 4, 2026
b9a3cbe
make OV DynamicCache backward compatible
echarlaix Feb 4, 2026
1687e35
remove incompatible models aquila2 orion internlm2
echarlaix Feb 4, 2026
961c1d3
add jais max_transformers_version as incompatible with v5
echarlaix Feb 4, 2026
e8e6c18
dbrx
echarlaix Feb 5, 2026
c6640d6
set float32 dtype
echarlaix Feb 5, 2026
1e0c06f
baichuan2 not compatible with v5
echarlaix Feb 5, 2026
b4910fc
gpt oss set experts_implementation batched mm
echarlaix Feb 5, 2026
e19da56
bitnet
echarlaix Feb 5, 2026
fde5ac9
qwenvl
echarlaix Feb 6, 2026
0d3b656
maira2 remote code
echarlaix Feb 6, 2026
b8797e3
gemma3 and got_ocr2
echarlaix Feb 6, 2026
9dfb666
llava next
echarlaix Feb 6, 2026
3386c64
llava next video
echarlaix Feb 6, 2026
e5fc9ef
merge main in branch
echarlaix Feb 9, 2026
bc4a84d
use ONNXCache
echarlaix Feb 10, 2026
0e41943
style
echarlaix Feb 10, 2026
bc9665d
fix seq2seq stateless export
echarlaix Feb 10, 2026
3188b09
merge main in branch
echarlaix Feb 10, 2026
fceb151
cache depending on transformers version
echarlaix Feb 10, 2026
5133a4a
pix2struct patcher
echarlaix Feb 11, 2026
0c4a89c
fix
echarlaix Feb 11, 2026
d8a4829
remove internvl_chat, minicpmv in tests
echarlaix Feb 11, 2026
e477044
set max transformers version for internvl_chat minicpmv
echarlaix Feb 11, 2026
e0b2b46
style
echarlaix Feb 11, 2026
50fe590
fix textual inversion
echarlaix Feb 13, 2026
e9ff083
add back inc
echarlaix Feb 13, 2026
49f020f
style
echarlaix Feb 13, 2026
31e8c44
skip text2text generation pipeline when >= v5
echarlaix Feb 13, 2026
4e43429
fix perceiver vision preprocessor loading
echarlaix Feb 13, 2026
3565637
fix question answering pipeline
echarlaix Feb 13, 2026
2d1929d
only install diffusers when compatible
echarlaix Feb 13, 2026
a8b08a4
fix diffusers mapping
echarlaix Feb 13, 2026
83ae846
style
echarlaix Feb 13, 2026
cad085b
update diffusers extra
echarlaix Feb 13, 2026
5dbe3c8
add transformers version workflow
echarlaix Feb 16, 2026
b7ce98b
set transformers 4.57.6 for tests
echarlaix Feb 16, 2026
d692d44
batch_encode_plus was deprecated in v5
echarlaix Feb 16, 2026
93679e9
fix sam
echarlaix Feb 16, 2026
b2ef418
install librosa for tests
echarlaix Feb 16, 2026
3fb0172
rename OVDynamicCache
echarlaix Feb 16, 2026
3d2286c
qwenvl3 fix
echarlaix Feb 16, 2026
46fa8a7
fix qwen2vl
echarlaix Feb 16, 2026
20bb596
github workflow librosa
echarlaix Feb 17, 2026
a091dad
Update MAX_TRANSFORMERS_VERSION for incompatible models
echarlaix Feb 17, 2026
847c98d
style
echarlaix Feb 17, 2026
4bc2768
pkv fix
echarlaix Feb 17, 2026
6799e93
transformers-v5 branch
echarlaix Feb 17, 2026
a2cd48e
use_model_defaults arg was deprecated in v5
echarlaix Feb 17, 2026
850c1ce
style
echarlaix Feb 17, 2026
af4a605
baichuan remote code models incompatible with v5
echarlaix Feb 17, 2026
4da53e8
remove tests for modelsf for models that needs fixes
echarlaix Feb 17, 2026
5a74781
fix decoder tests untested_architectures
echarlaix Feb 17, 2026
e634d77
fix untested architecture
echarlaix Feb 17, 2026
f89d0de
fix pkv patching
echarlaix Feb 17, 2026
6070155
fix test
echarlaix Feb 17, 2026
26d5c44
fix expcted int8 tests
echarlaix Feb 17, 2026
9d84f3a
tests transformers v5
echarlaix Feb 18, 2026
4b5f83d
pix2struct
echarlaix Feb 18, 2026
14e1b52
fix num expected int8
echarlaix Feb 18, 2026
0dbe96c
use_model_defaults deprecated in v5
echarlaix Feb 18, 2026
af3fba3
rename
echarlaix Feb 18, 2026
546127b
style
echarlaix Feb 18, 2026
3eeeb4d
install diffusers from source for v5
echarlaix Feb 18, 2026
2b61bd3
qwen2vl
echarlaix Feb 18, 2026
bbe65bb
remove tests for v5
echarlaix Feb 18, 2026
7ba6fd1
disable tests for transformers v5
echarlaix Feb 18, 2026
928fb50
remove non needed
echarlaix Feb 18, 2026
ef320b3
disable tests
echarlaix Feb 18, 2026
8beb8d8
fix
echarlaix Feb 18, 2026
e4eba92
add stable diffusion 3 tests when diffusers compatible with v5
echarlaix Feb 19, 2026
dc2823d
use xlm-roberta with max_position_embeddings 514
echarlaix Feb 19, 2026
5967be3
add missing import
echarlaix Feb 19, 2026
699b0b7
granitemoe fix
echarlaix Feb 19, 2026
389f818
filtered test
echarlaix Feb 19, 2026
ffe2d27
add back granitemoe model support
echarlaix Feb 19, 2026
c649bdf
udpate setup
echarlaix Feb 19, 2026
4c74aeb
update workflows
echarlaix Feb 19, 2026
c7184e1
update setup
echarlaix Feb 19, 2026
7b0806e
fix
echarlaix Feb 19, 2026
50e30b7
update setup
echarlaix Feb 19, 2026
e7878e1
remove diffusers
echarlaix Feb 19, 2026
467dcad
fix offline workflow
echarlaix Feb 19, 2026
c14f2e5
exclude openclip from offline tests
echarlaix Feb 19, 2026
69c16bf
workflow slow
echarlaix Feb 20, 2026
3f8dfb4
fix question answering pipeline
echarlaix Feb 20, 2026
975da72
encode_plus deprecated
echarlaix Feb 20, 2026
31989eb
automatic-speech pipeline for whisper incompatible with v5
echarlaix Feb 20, 2026
7adb810
style
echarlaix Feb 20, 2026
6a93224
image-to-text pipeline deprecated
echarlaix Feb 20, 2026
c8e9488
update MAX_TRANSFORMERS_VERSION for gemma3 exaone4 and llama4
echarlaix Feb 20, 2026
28e2e24
remove from test when not supported
echarlaix Feb 20, 2026
f061f2c
decoder tests
echarlaix Feb 20, 2026
8820fb3
test filtered architectures update with exaone4
echarlaix Feb 20, 2026
290b7b3
change gptoss model
echarlaix Feb 20, 2026
64223a8
style
echarlaix Feb 23, 2026
f40bcb3
set num beam to 5
echarlaix Feb 23, 2026
86767c7
add llava support for v5
echarlaix Feb 25, 2026
c523617
maira
echarlaix Feb 25, 2026
d49a895
extend tests disabled for marian for openvino v2026
echarlaix Feb 25, 2026
6f608fd
style
echarlaix Feb 25, 2026
02a2ccd
style
echarlaix Feb 25, 2026
710c5bc
include openvino 2026
echarlaix Feb 25, 2026
64dc198
add gemma3 text
echarlaix Feb 25, 2026
d3bdb29
llava tests
echarlaix Feb 25, 2026
ea761a7
exclude marian for transformers v5 or higher
echarlaix Feb 26, 2026
5e5bdfc
merge main in branch
echarlaix Feb 26, 2026
a33065e
fix gemma3
echarlaix Feb 26, 2026
16c2c94
merge main in branch
echarlaix Mar 2, 2026
bf51329
add comment
echarlaix Mar 3, 2026
4a27862
replace gpt_oss_mxfp4 test to gpt_oss for v5
echarlaix Mar 4, 2026
4a8644d
include Qwen3VLOpenVINOConfig min version
echarlaix Mar 4, 2026
9881475
add phi4_multimodal for transformers < v5
echarlaix Mar 4, 2026
2d764ef
set dtype for beam_search tests for gemma3 text model
echarlaix Mar 6, 2026
8574954
Add _ov_ops.py with RecurrentAttentionCellOp conversion rule
Copilot Mar 8, 2026
050d14f
Add initial Qwen3.5 model support with VLM and hybrid text model
Copilot Mar 8, 2026
4cbb25e
Fix Qwen3.5 model patcher and config for VLM text embeddings access
Copilot Mar 8, 2026
b660200
Fix comment grammar in test_decoder.py
Copilot Mar 8, 2026
e47b7bd
Merge branch 'main' into transformers-v5
echarlaix Mar 9, 2026
f901a66
diffusers latest release now compatible with transformers v5
echarlaix Mar 9, 2026
7879da8
set qwen3_next max transformers version
echarlaix Mar 9, 2026
d5f2244
Fix doc building
echarlaix Mar 9, 2026
43ed617
add qwen3_next to list of untested architectures
echarlaix Mar 9, 2026
87cc3f9
comment for zamba2
echarlaix Mar 10, 2026
07d943d
Use Qwen3VLOpenVINOConfig
rkazants Mar 11, 2026
9a91793
Merge remote-tracking branch 'upstream/transformers-v5' into add-supp…
rkazants Mar 11, 2026
d8864c4
Remove redundant functions
rkazants Mar 11, 2026
96d47b0
Fix eagle3 compatibility with v5
echarlaix Mar 11, 2026
db80561
set dtype in tests when loading sd3 model
echarlaix Mar 11, 2026
3e5a2b2
trigger tests for transformers v5.3
echarlaix Mar 11, 2026
10add8c
update setup
echarlaix Mar 12, 2026
501b523
update setup
echarlaix Mar 12, 2026
15548fc
update setup
echarlaix Mar 12, 2026
7907878
fix bf16 model export
echarlaix Mar 17, 2026
c026dd9
question answering pipeline deprecated in v5.3
echarlaix Mar 18, 2026
61d85b3
ix mamba expected int8
echarlaix Mar 18, 2026
55c0d46
Fix _DEFAULT_IGNORED_SCOPE_CONFIGS for __make_16bit_traceable patched…
echarlaix Mar 18, 2026
2f38fd8
add test to ensure dtype
echarlaix Mar 18, 2026
c925a79
style
echarlaix Mar 18, 2026
057ce12
Merge remote-tracking branch 'upstream/transformers-v5' into support_…
rkazants Mar 18, 2026
934b32e
Correct patching for vlm
rkazants Mar 18, 2026
bf1f377
check openvino model expected dtype in test_export_dtype
echarlaix Mar 19, 2026
e1f8c28
Fix bf16 patching
rkazants Mar 20, 2026
5033df2
fix qwen3vl vision embeddings pos
echarlaix Mar 20, 2026
ea94354
Merge remote-tracking branch 'upstream/transformers-v5' into support_…
rkazants Mar 22, 2026
4602e00
Support Qwen3.5-MoE
rkazants Mar 22, 2026
cbe127e
Add position_ids input and its preparation for inference
rkazants Apr 14, 2026
8eef963
Merge remote-tracking branch 'upstream/main' into support_qwen3_5
rkazants Apr 15, 2026
c7a19db
Apply suggestion from @rkazants
rkazants Apr 15, 2026
c036d9c
Apply suggestion from @rkazants
rkazants Apr 15, 2026
7b63cd3
Apply suggestion from @rkazants
rkazants Apr 15, 2026
f7276ce
Apply suggestions from code review
rkazants Apr 15, 2026
c656558
Apply code formatting
rkazants Apr 15, 2026
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
1 change: 1 addition & 0 deletions docs/source/openvino/models.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ Here is the list of the supported architectures :
- Qwen3
- Qwen3MoE
- Qwen3-VL
- Qwen3.5
- Qwen3-Next
- RemBERT
- ResNet
Expand Down
10 changes: 10 additions & 0 deletions optimum/exporters/openvino/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,16 @@ def ts_patched_forward(*args, **kwargs):
extension=conversion_extensions,
)

if patch_16bit_model:
# Undo __make_16bit_traceable patching on sub-modules to avoid corrupting
# forward methods of modules shared across export behaviors (e.g. pos_embed
# Embedding in VLMs that is also exported separately as vision_embeddings_pos).
_orig_forward_attr = "_openvino_module_extension_patch_orig_forward"
for module in model.modules():
if hasattr(module, _orig_forward_attr):
module.forward = getattr(module, _orig_forward_attr)
delattr(module, _orig_forward_attr)

ov_model.validate_nodes_and_infer_types() # TODO: remove as unnecessary validation?

output_names = list(config.outputs.keys())
Expand Down
319 changes: 319 additions & 0 deletions optimum/exporters/openvino/model_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@
Qwen2MoEPatcher,
Qwen2VLLanguageModelPatcher,
Qwen2VLVisionEmbMergerPatcher,
Qwen3_5ModelPatcher,
Qwen3_5MoeModelPatcher,
Qwen3_5VisionEmbMergerPatcher,
Qwen3MoeModelPatcher,
Qwen3NextModelPatcher,
Qwen3VLLanguageModelPatcher,
Expand Down Expand Up @@ -1098,6 +1101,8 @@ class Phi3OpenVINOConfig(PhiOnnxConfig):
)
class PhiMoEOpenVINOConfig(Phi3OpenVINOConfig):
MIN_TRANSFORMERS_VERSION = "4.46.0"
# TODO (@echarlaix): add v5 support
MAX_TRANSFORMERS_VERSION = "4.57.6"
Comment thread
rkazants marked this conversation as resolved.
Outdated
_MODEL_PATCHER = PhiMoEModelPatcher


Expand Down Expand Up @@ -3549,6 +3554,14 @@ def generate(self, input_name: str, framework: str = "pt", int_dtype: str = "int
return generated_input


class DummyQwen3_5LMInputGenerator(DummyTextInputGenerator):
def generate(self, input_name: str, framework: str = "pt", int_dtype: str = "int64", float_dtype: str = "fp32"):
generated_input = super().generate(input_name, framework, int_dtype, float_dtype)
if input_name == "position_ids":
return generated_input.unsqueeze(0).expand(4, -1, -1)
return generated_input


class DummyQwen2VLVisionEmbedInputGenerator(DummyVisionInputGenerator):
SUPPORTED_INPUT_NAMES = (
"hidden_states",
Expand Down Expand Up @@ -5496,3 +5509,309 @@ def generate_dummy_inputs(self, framework: str = "pt", **kwargs):
)

return dummy_inputs


class Qwen3_5DummyPastKeyValuesGenerator(DummyPastKeyValuesGenerator):
"""
Generates dummy cache_params inputs for Qwen3.5 architectures.
"""

SUPPORTED_INPUT_NAMES = ("cache_params",)

def __init__(
self,
task: str,
normalized_config,
batch_size: int = DEFAULT_DUMMY_SHAPES["batch_size"],
sequence_length: int = DEFAULT_DUMMY_SHAPES["sequence_length"],
**kwargs,
):
super().__init__(
task=task,
normalized_config=normalized_config,
batch_size=batch_size,
sequence_length=sequence_length,
**kwargs,
)

config = normalized_config.config
self.num_full_attn_layers = config.layer_types.count("full_attention")
self.num_linear_attn_layers = config.layer_types.count("linear_attention")
self.conv_kernel_size = config.linear_conv_kernel_dim
self.head_dim = getattr(config, "head_dim", config.hidden_size // config.num_attention_heads)
self.head_k_dim = config.linear_key_head_dim
self.head_v_dim = config.linear_value_head_dim
self.num_v_heads = config.linear_num_value_heads
self.num_k_heads = config.linear_num_key_heads
self.num_key_value_heads = config.num_key_value_heads

def generate(self, input_name: str, framework: str = "pt", int_dtype: str = "int64", float_dtype: str = "fp32"):
cache_params = []

for idx in range(self.num_linear_attn_layers):
d_inner = self.num_k_heads * (2 * self.head_k_dim + self.head_v_dim * self.num_v_heads // self.num_k_heads)
conv_state_shape = (
self.batch_size,
d_inner,
self.conv_kernel_size,
)
conv_state = self.random_float_tensor(conv_state_shape, framework=framework, dtype=float_dtype)
cache_params.append(conv_state)
num_heads = self.num_v_heads
recurrent_state_shape = (self.batch_size, num_heads, self.head_k_dim, self.head_v_dim)
recurrent_state = self.random_float_tensor(recurrent_state_shape, framework=framework, dtype=float_dtype)
cache_params.append(recurrent_state)

for idx in range(self.num_full_attn_layers):
kv_shape = (self.batch_size, self.num_key_value_heads, self.sequence_length, self.head_dim)
k = self.random_float_tensor(kv_shape, framework=framework, dtype=float_dtype)
v = self.random_float_tensor(kv_shape, framework=framework, dtype=float_dtype)
cache_params.append(k)
cache_params.append(v)

return cache_params


@register_in_tasks_manager(
"qwen3_5_text",
*["text-generation", "text-generation-with-past"],
library_name="transformers",
)
class Qwen3_5TextOpenVINOConfig(Qwen3VLTextOpenVINOConfig):
DUMMY_INPUT_GENERATOR_CLASSES = (DummyTextInputGenerator, Qwen3_5DummyPastKeyValuesGenerator)
DUMMY_PKV_GENERATOR_CLASS = Qwen3_5DummyPastKeyValuesGenerator
NORMALIZED_CONFIG_CLASS = NormalizedTextConfig
MIN_TRANSFORMERS_VERSION = "4.57.0"
_MODEL_PATCHER = Qwen3_5ModelPatcher

def add_past_key_values(self, inputs_or_outputs: Dict[str, Dict[int, str]], direction: str):
if direction not in ["inputs", "outputs"]:
raise ValueError(f'direction must either be "inputs" or "outputs", but {direction} was given')

if direction == "inputs":
decoder_sequence_name = "past_sequence_length"
cache_name_prefix = "cache_params.past"
else:
decoder_sequence_name = "past_sequence_length + sequence_length"
cache_name_prefix = "cache_params.present"

self.num_full_attn_layers = self._normalized_config.layer_types.count("full_attention")
self.num_linear_attn_layers = self._normalized_config.layer_types.count("linear_attention")

for i in range(self.num_linear_attn_layers):
inputs_or_outputs[f"{cache_name_prefix}.conv.{i}"] = {0: "batch_size"}
inputs_or_outputs[f"{cache_name_prefix}.ssm.{i}"] = {0: "batch_size"}

for i in range(self.num_full_attn_layers):
inputs_or_outputs[f"{cache_name_prefix}.key.{i}"] = {0: "batch_size", 2: decoder_sequence_name}
inputs_or_outputs[f"{cache_name_prefix}.value.{i}"] = {0: "batch_size", 2: decoder_sequence_name}

@property
def inputs(self) -> Dict[str, Dict[int, str]]:
common_inputs = {
"input_ids": {0: "batch_size", 1: "sequence_length"},
"attention_mask": {0: "batch_size", 1: "sequence_length"},
"position_ids": {0: "batch_size", 1: "sequence_length"},
}
if self.use_past_in_inputs:
self.add_past_key_values(common_inputs, direction="inputs")
return common_inputs

def generate_dummy_inputs(self, framework: str = "pt", **kwargs):
dummy_inputs_generators = self._create_dummy_input_generator_classes(**kwargs)

dummy_inputs = {}
input_names = [key for key in self.inputs.keys() if not key.startswith("cache_params")]
if self.use_past_in_inputs:
input_names.extend(["cache_params"])

for input_name in input_names:
input_was_inserted = False
for dummy_input_gen in dummy_inputs_generators:
if dummy_input_gen.supports_input(input_name):
dummy_inputs[input_name] = self.overwrite_shape_and_generate_input(
dummy_input_gen,
input_name,
framework,
input_shapes=kwargs,
)
input_was_inserted = True
break
if not input_was_inserted:
raise RuntimeError(
f'Could not generate dummy input for "{input_name}". Try adding a proper dummy input generator to the model ONNX config.'
)

return dummy_inputs


@register_in_tasks_manager(
"qwen3_5",
*["image-text-to-text"],
library_name="transformers",
)
class Qwen3_5OpenVINOConfig(Qwen3VLOpenVINOConfig):
SUPPORTED_BEHAVIORS = [model_type.value for model_type in QwenVLConfigBehavior]
DUMMY_INPUT_GENERATOR_CLASSES = (DummyQwen3VLVisionEmbedInputGenerator,)
MIN_TRANSFORMERS_VERSION = "4.57.0"

def __init__(
self,
config: "PretrainedConfig",
task: str = "feature-extraction",
int_dtype: str = "int64",
float_dtype: str = "fp32",
behavior: QwenVLConfigBehavior = QwenVLConfigBehavior.VISION_EMBEDDINGS,
preprocessors: Optional[List[Any]] = None,
):
super().__init__(
config=config,
task=task,
int_dtype=int_dtype,
float_dtype=float_dtype,
preprocessors=preprocessors,
behavior=behavior,
)
if self._behavior == QwenVLConfigBehavior.VISION_EMBEDDINGS_POS and hasattr(config, "vision_config"):
self._config = config.vision_config
self._normalized_config = self.NORMALIZED_CONFIG_CLASS(self._config)
self._normalized_config.use_embed_dim = True

def with_behavior(
self,
behavior: Union[str, QwenVLConfigBehavior],
):
"""
Creates a config for different behaviour.
Args:
behavior ([`ConfigBehavior`]):
The behavior to use for the new instance.
"""
if isinstance(behavior, str) and not isinstance(behavior, QwenVLConfigBehavior):
behavior = QwenVLConfigBehavior(behavior)

if behavior == QwenVLConfigBehavior.TEXT_EMBEDDINGS:
return get_vlm_text_embeddings_config(
"qwen3_5_text", self._orig_config.text_config, self.int_dtype, self.float_dtype
)

if behavior == QwenVLConfigBehavior.LANGUAGE:
return get_vlm_text_generation_config(
"qwen3_5_text",
self._orig_config.text_config,
self.int_dtype,
self.float_dtype,
model_patcher=Qwen3_5ModelPatcher,
dummy_input_generator=DummyQwen3_5LMInputGenerator,
inputs_update={"position_ids": {1: "batch_size", 2: "sequence_length"}},
)

if behavior in (
QwenVLConfigBehavior.VISION_EMBEDDINGS,
QwenVLConfigBehavior.VISION_EMBEDDINGS_MERGER,
QwenVLConfigBehavior.VISION_EMBEDDINGS_POS,
):
return self.__class__(
self._orig_config,
task=self.task,
int_dtype=self.int_dtype,
float_dtype=self.float_dtype,
behavior=behavior,
preprocessors=self._preprocessors,
)

def patch_model_for_export(self, model: Union["PreTrainedModel"], model_kwargs: Optional[Dict[str, Any]] = None):
model_kwargs = model_kwargs or {}
if self._behavior == QwenVLConfigBehavior.VISION_EMBEDDINGS_MERGER:
return Qwen3_5VisionEmbMergerPatcher(self, model, model_kwargs)
if (
self._behavior == QwenVLConfigBehavior.VISION_EMBEDDINGS
or self._behavior == QwenVLConfigBehavior.VISION_EMBEDDINGS_POS
):
return ModelPatcher(self, model, model_kwargs=model_kwargs)
return super().patch_model_for_export(model, model_kwargs)

@property
def inputs(self) -> Dict[str, Dict[int, str]]:
if self._behavior == QwenVLConfigBehavior.VISION_EMBEDDINGS_POS:
return {
"input": {1: "sequence_length"},
}
return super().inputs

@property
def outputs(self) -> Dict[str, Dict[int, str]]:
if self._behavior == QwenVLConfigBehavior.VISION_EMBEDDINGS:
return super().outputs
if self._behavior == QwenVLConfigBehavior.VISION_EMBEDDINGS_MERGER:
return {"last_hidden_state": {0: "seq_len"}}
if self._behavior == QwenVLConfigBehavior.VISION_EMBEDDINGS_POS:
return {"last_hidden_state": {0: "seq_len", 1: "seq_len"}}
if self._behavior == QwenVLConfigBehavior.TEXT_EMBEDDINGS:
return {"inputs_embeds": {0: "batch_size", 1: "sequence_length"}}
if self._behavior == QwenVLConfigBehavior.LANGUAGE:
return get_vlm_internal_text_generation_config(
"qwen3_5_text", self._orig_config.text_config, self.int_dtype, self.float_dtype
).outputs
raise Exception("Unknown Qwen3.5 behavior type.")


@register_in_tasks_manager(
"qwen3_5_moe_text",
*["text-generation", "text-generation-with-past"],
library_name="transformers",
)
class Qwen3_5MoeTextOpenVINOConfig(Qwen3_5TextOpenVINOConfig):
_MODEL_PATCHER = Qwen3_5MoeModelPatcher


@register_in_tasks_manager(
"qwen3_5_moe",
*["image-text-to-text"],
library_name="transformers",
)
class Qwen3_5MoeOpenVINOConfig(Qwen3_5OpenVINOConfig):
def with_behavior(
self,
behavior: Union[str, QwenVLConfigBehavior],
):
if isinstance(behavior, str) and not isinstance(behavior, QwenVLConfigBehavior):
behavior = QwenVLConfigBehavior(behavior)

if behavior == QwenVLConfigBehavior.TEXT_EMBEDDINGS:
return get_vlm_text_embeddings_config(
"qwen3_5_moe_text", self._orig_config.text_config, self.int_dtype, self.float_dtype
)

if behavior == QwenVLConfigBehavior.LANGUAGE:
return get_vlm_text_generation_config(
"qwen3_5_moe_text",
self._orig_config.text_config,
self.int_dtype,
self.float_dtype,
model_patcher=Qwen3_5MoeModelPatcher,
dummy_input_generator=DummyQwen3_5LMInputGenerator,
inputs_update={"position_ids": {1: "batch_size", 2: "sequence_length"}},
)

if behavior in (
QwenVLConfigBehavior.VISION_EMBEDDINGS,
QwenVLConfigBehavior.VISION_EMBEDDINGS_MERGER,
QwenVLConfigBehavior.VISION_EMBEDDINGS_POS,
):
return self.__class__(
self._orig_config,
task=self.task,
int_dtype=self.int_dtype,
float_dtype=self.float_dtype,
behavior=behavior,
preprocessors=self._preprocessors,
)

@property
def outputs(self) -> Dict[str, Dict[int, str]]:
if self._behavior == QwenVLConfigBehavior.LANGUAGE:
return get_vlm_internal_text_generation_config(
"qwen3_5_moe_text", self._orig_config.text_config, self.int_dtype, self.float_dtype
).outputs
return super().outputs
Loading
Loading