optimum-intel 2.1.0__tar.gz → 2.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. {optimum_intel-2.1.0/optimum_intel.egg-info → optimum_intel-2.2.0}/PKG-INFO +3 -3
  2. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/commands/export/openvino.py +1 -0
  3. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/exporters/openvino/__main__.py +26 -7
  4. optimum_intel-2.2.0/optimum/exporters/openvino/_ov_ops.py +268 -0
  5. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/exporters/openvino/base.py +3 -1
  6. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/exporters/openvino/convert.py +378 -3
  7. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/exporters/openvino/input_generators.py +533 -3
  8. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/exporters/openvino/model_configs.py +1065 -12
  9. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/exporters/openvino/model_patcher.py +2540 -146
  10. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/exporters/openvino/patching_utils.py +17 -0
  11. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/exporters/openvino/utils.py +34 -0
  12. optimum_intel-2.2.0/optimum/exporters/openvino/utils_annotations.py +238 -0
  13. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/__init__.py +30 -0
  14. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/openvino/__init__.py +8 -0
  15. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/openvino/configuration.py +33 -0
  16. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/openvino/modeling_decoder.py +28 -7
  17. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/openvino/modeling_diffusion.py +1000 -32
  18. optimum_intel-2.2.0/optimum/intel/openvino/modeling_funasr.py +443 -0
  19. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/openvino/modeling_seq2seq.py +40 -7
  20. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/openvino/modeling_visual_language.py +530 -15
  21. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/openvino/quantization.py +7 -1
  22. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/openvino/utils.py +2 -0
  23. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/utils/dummy_openvino_and_diffusers_objects.py +88 -0
  24. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/utils/import_utils.py +12 -0
  25. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/utils/modeling_utils.py +6 -0
  26. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/version.py +1 -1
  27. {optimum_intel-2.1.0 → optimum_intel-2.2.0/optimum_intel.egg-info}/PKG-INFO +3 -3
  28. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum_intel.egg-info/SOURCES.txt +2 -0
  29. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum_intel.egg-info/requires.txt +2 -2
  30. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/setup.py +2 -2
  31. optimum_intel-2.1.0/optimum/exporters/openvino/_ov_ops.py +0 -113
  32. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/LICENSE +0 -0
  33. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/MANIFEST.in +0 -0
  34. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/README.md +0 -0
  35. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/commands/register/register_openvino.py +0 -0
  36. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/exporters/openvino/__init__.py +0 -0
  37. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/exporters/openvino/_traceable_cache.py +0 -0
  38. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/exporters/openvino/_traceable_decorator.py +0 -0
  39. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/exporters/openvino/config.py +0 -0
  40. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/exporters/openvino/stateful.py +0 -0
  41. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/openvino/loaders.py +0 -0
  42. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/openvino/modeling.py +0 -0
  43. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/openvino/modeling_base.py +0 -0
  44. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/openvino/modeling_open_clip.py +0 -0
  45. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/openvino/modeling_sam.py +0 -0
  46. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/openvino/modeling_sentence_transformers.py +0 -0
  47. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/openvino/modeling_text2speech.py +0 -0
  48. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/openvino/modeling_timm.py +0 -0
  49. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/pipelines/__init__.py +0 -0
  50. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/pipelines/accelerator_utils.py +0 -0
  51. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/pipelines/pipeline_base.py +0 -0
  52. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/utils/__init__.py +0 -0
  53. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/utils/constant.py +0 -0
  54. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/utils/dummy_openvino_and_nncf_objects.py +0 -0
  55. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum/intel/utils/dummy_openvino_and_sentence_transformers_objects.py +0 -0
  56. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum_intel.egg-info/dependency_links.txt +0 -0
  57. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum_intel.egg-info/entry_points.txt +0 -0
  58. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum_intel.egg-info/not-zip-safe +0 -0
  59. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/optimum_intel.egg-info/top_level.txt +0 -0
  60. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/pyproject.toml +0 -0
  61. {optimum_intel-2.1.0 → optimum_intel-2.2.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: optimum-intel
3
- Version: 2.1.0
3
+ Version: 2.2.0
4
4
  Summary: Optimum Library is an extension of the Hugging Face Transformers library, providing a framework to integrate third-party libraries from Hardware Partners and interface with their specific functionality.
5
5
  Home-page: https://www.intel.com
6
6
  Author: HuggingFace Inc. Special Ops Team
@@ -20,15 +20,15 @@ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
20
  Description-Content-Type: text/markdown
21
21
  License-File: LICENSE
22
22
  Requires-Dist: torch>=2.1
23
- Requires-Dist: safetensors<0.8.0
24
23
  Requires-Dist: optimum~=2.3.0
25
24
  Requires-Dist: transformers<5.6,>=4.51
26
25
  Requires-Dist: setuptools
27
26
  Requires-Dist: huggingface-hub<1.22,>=0.23.2
28
- Requires-Dist: nncf>=2.19.0
27
+ Requires-Dist: nncf>=3.3.0
29
28
  Requires-Dist: openvino>=2026.0
30
29
  Requires-Dist: openvino-tokenizers>=2026.0
31
30
  Requires-Dist: requests<3.0,>=2.33
31
+ Requires-Dist: torchvision
32
32
  Provides-Extra: nncf
33
33
  Requires-Dist: nncf>=2.19.0; extra == "nncf"
34
34
  Provides-Extra: openvino
@@ -314,6 +314,7 @@ def no_compression_parameter_provided(args):
314
314
  args.lora_correction,
315
315
  args.sensitivity_metric,
316
316
  args.backup_precision,
317
+ args.group_size_fallback,
317
318
  )
318
319
  )
319
320
  )
@@ -90,6 +90,11 @@ def infer_task(
90
90
  task = "zero-shot-image-classification"
91
91
  elif library_name == "kokoro":
92
92
  task = "text-to-audio"
93
+ elif library_name == "funasr":
94
+ # Use the with-past task so the encoder-decoder export is stateful (KV cache hidden in
95
+ # OpenVINO state). Without the `-with-past` suffix the decoder is exported stateless and
96
+ # incremental generation breaks (only the first token is correct).
97
+ task = "automatic-speech-recognition-with-past"
93
98
  else:
94
99
  try:
95
100
  task = TasksManager._infer_task_from_model_name_or_path(
@@ -209,14 +214,23 @@ def _ensure_qwen3_omni_rope_scaling(config):
209
214
  return config
210
215
 
211
216
 
212
- def update_config_for_eagle3(config):
217
+ # Maps config.architectures[0] to the (AutoModel, AutoModelForCausalLM) classes in
218
+ # model_patcher used to load custom draft models for speculative decoding.
219
+ _CUSTOM_DRAFT_MODEL_MAP = {
220
+ "LlamaForCausalLMEagle3": ("LlamaEagle3Model", "LlamaEagle3ForCausalLM"),
221
+ "Eagle3LlamaForCausalLM": ("LlamaEagle3Model", "LlamaEagle3ForCausalLM"),
222
+ "DFlashDraftModel": ("Qwen3DFlashDraftModel", "Qwen3DFlashForCausalLM"),
223
+ }
224
+
225
+
226
+ def update_config_for_custom_draft_model(config, auto_model, auto_model_for_causal_lm):
213
227
  moduler_name = "optimum.exporters.openvino.model_patcher"
214
228
  spec = importlib.util.find_spec(moduler_name)
215
229
  if spec and spec.origin:
216
230
  moduler_path = os.path.dirname(spec.origin)
217
231
  config.auto_map = {
218
- "AutoModel": moduler_path + "--model_patcher.LlamaEagle3Model",
219
- "AutoModelForCausalLM": moduler_path + "--model_patcher.LlamaEagle3ForCausalLM",
232
+ "AutoModel": f"{moduler_path}--model_patcher.{auto_model}",
233
+ "AutoModelForCausalLM": f"{moduler_path}--model_patcher.{auto_model_for_causal_lm}",
220
234
  }
221
235
  config.tie_word_embeddings = False
222
236
  return config
@@ -386,11 +400,12 @@ def main_export(
386
400
  quantization_config = getattr(config, "quantization_config", None)
387
401
  quant_method = quantization_config.get("quant_method", None) if quantization_config else None
388
402
 
389
- # update config to load eagle3 models (both text-only and VLM variants)
403
+ # update config to load custom draft models (eagle3 text-only/VLM variants, dflash)
390
404
  archs = getattr(config, "architectures", None)
391
- _eagle3_archs = {"LlamaForCausalLMEagle3", "Eagle3LlamaForCausalLM"}
392
- if isinstance(archs, list) and len(archs) > 0 and archs[0] in _eagle3_archs:
393
- loading_kwargs["config"] = update_config_for_eagle3(config)
405
+ if isinstance(archs, list) and archs:
406
+ draft_classes = _CUSTOM_DRAFT_MODEL_MAP.get(archs[0])
407
+ if draft_classes is not None:
408
+ loading_kwargs["config"] = update_config_for_custom_draft_model(config, *draft_classes)
394
409
 
395
410
  # mxfp4 quantized model will be dequantized to bf16
396
411
  if quant_method == "mxfp4" and is_transformers_version(">=", "4.55"):
@@ -565,6 +580,10 @@ def main_export(
565
580
  model = _OpenClipForZeroShotImageClassification.from_pretrained(model_name_or_path, cache_dir=cache_dir)
566
581
  elif library_name == "kokoro":
567
582
  model = _KokoroForTextToSpeech.from_pretrained(model_name_or_path, cache_dir=cache_dir, token=token)
583
+ elif library_name == "funasr":
584
+ from optimum.intel.openvino.modeling_funasr import _FunASRForSpeechSeq2Seq
585
+
586
+ model = _FunASRForSpeechSeq2Seq.from_pretrained(model_name_or_path, cache_dir=cache_dir, token=token)
568
587
  else:
569
588
  # remote code models like phi3_v internvl2, minicpmv, internvl2, nanollava, maira2 should be loaded using AutoModelForCausalLM and not AutoModelForImageTextToText
570
589
  # TODO: use config.auto_map to load remote code models instead (for other models we can directly use config.architectures)
@@ -0,0 +1,268 @@
1
+ # Copyright 2026 The HuggingFace Team. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # Conversion rule for the `RecurrentAttentionCellOp` operation in a Torch graph.
16
+ # The `RecurrentAttentionCellOp` appears in the Torch graph as a result of replacing
17
+ # the `torch.nn.Module` block `RecurrentAttentionCell` via a registered
18
+ # `ModuleExtension` for `RecurrentAttentionCell` in the OpenVINO PyTorch frontend.
19
+ import numpy as np
20
+
21
+ import openvino as ov
22
+ import openvino.opset14 as ops
23
+
24
+
25
+ def convert_recurrent_attention_cell(context):
26
+ query = context.get_input(0)
27
+ key = context.get_input(1)
28
+ value = context.get_input(2)
29
+ g = context.get_input(3)
30
+ beta = context.get_input(4)
31
+ last_recurrent_state_old = context.get_input(5)
32
+
33
+ value_shape = ops.shape_of(value)
34
+ const_zero = ops.constant(0, dtype=np.float32)
35
+ core_attn_out = ops.broadcast(const_zero, value_shape)
36
+ const_two_out = ops.constant(2, dtype=np.int32)
37
+ const_zero_out = ops.constant(0, dtype=np.int32)
38
+ seq_len = ops.gather(value_shape, const_two_out, const_zero_out)
39
+
40
+ timestep_param = ops.parameter([], np.int32, "timestep")
41
+ q_t_param = ops.parameter([-1, -1, 1, -1], np.float32, "q_t")
42
+ k_t_param = ops.parameter([-1, -1, 1, -1], np.float32, "k_t")
43
+ v_t_param = ops.parameter([-1, -1, 1, -1], np.float32, "v_t")
44
+ g_t_param = ops.parameter([-1, -1, 1], np.float32, "g_t")
45
+ beta_t_param = ops.parameter([-1, -1, 1], np.float32, "beta_t")
46
+ last_recurrent_state_t = ops.parameter([-1, -1, -1, -1], np.float32, "last_recurrent_state_t")
47
+ core_attn_out_t = ops.parameter([-1, -1, -1, -1], np.float32, "core_attn_out_t")
48
+
49
+ const_two = ops.constant(2, dtype=np.int32)
50
+ q_t = ops.squeeze(q_t_param, const_two)
51
+ k_t = ops.squeeze(k_t_param, const_two)
52
+ v_t = ops.squeeze(v_t_param, const_two)
53
+ const_minus_one = ops.constant(-1, dtype=np.int32)
54
+ g_t = ops.unsqueeze(ops.exp(g_t_param), const_minus_one)
55
+ beta_t = beta_t_param
56
+
57
+ last_recurrent_state_in = ops.multiply(last_recurrent_state_t, g_t)
58
+ const_minus_two = ops.constant(-2, dtype=np.int32)
59
+ kv_mem = ops.multiply(last_recurrent_state_in, ops.unsqueeze(k_t, const_minus_one))
60
+ kv_mem = ops.reduce_sum(kv_mem, const_minus_two, False)
61
+ delta = ops.multiply(ops.subtract(v_t, kv_mem), beta_t)
62
+ last_recurrent_state_delta = ops.multiply(
63
+ ops.unsqueeze(k_t, const_minus_one), ops.unsqueeze(delta, const_minus_two)
64
+ )
65
+ last_recurrent_state_in = ops.add(last_recurrent_state_in, last_recurrent_state_delta)
66
+ core_attn_update = ops.multiply(last_recurrent_state_in, ops.unsqueeze(q_t, const_minus_one))
67
+ core_attn_update = ops.reduce_sum(core_attn_update, const_minus_two, True)
68
+ const_zero = ops.constant(0, dtype=np.int32)
69
+ timestep = ops.unsqueeze(timestep_param, const_zero)
70
+
71
+ core_attn_out_res = ops.scatter_update(core_attn_out_t, timestep, core_attn_update, const_two)
72
+ last_recurrent_state_res = last_recurrent_state_in
73
+
74
+ body_cond = ops.constant([True], dtype=bool)
75
+
76
+ body_model = ov.Model(
77
+ [body_cond, last_recurrent_state_res, core_attn_out_res],
78
+ [
79
+ timestep_param,
80
+ q_t_param,
81
+ k_t_param,
82
+ v_t_param,
83
+ g_t_param,
84
+ beta_t_param,
85
+ last_recurrent_state_t,
86
+ core_attn_out_t,
87
+ ],
88
+ "body_model",
89
+ )
90
+
91
+ seq_len = ops.convert(seq_len, "i32")
92
+ loop = ops.loop(seq_len, ops.constant(True, dtype="bool"))
93
+ loop.set_function(body_model)
94
+
95
+ loop.set_sliced_input(q_t_param, query, 0, 1, 1, -1, 2)
96
+ loop.set_sliced_input(k_t_param, key, 0, 1, 1, -1, 2)
97
+ loop.set_sliced_input(v_t_param, value, 0, 1, 1, -1, 2)
98
+ loop.set_sliced_input(g_t_param, g, 0, 1, 1, -1, 2)
99
+ loop.set_sliced_input(beta_t_param, beta, 0, 1, 1, -1, 2)
100
+ loop.set_merged_input(last_recurrent_state_t, last_recurrent_state_old, last_recurrent_state_res.output(0))
101
+ loop.set_merged_input(core_attn_out_t, core_attn_out.output(0), core_attn_out_res.output(0))
102
+ loop.set_special_body_ports([0, 0])
103
+
104
+ core_attn_out_new = loop.get_iter_value(core_attn_out_res.output(0), -1)
105
+ last_recurrent_state_new = loop.get_iter_value(last_recurrent_state_res.output(0), -1)
106
+
107
+ flatten_shape = ops.constant([-1], dtype=np.int32)
108
+ core_attn_out_new = ops.reshape(core_attn_out_new, flatten_shape, False)
109
+ last_recurrent_state_new = ops.reshape(last_recurrent_state_new, flatten_shape, False)
110
+
111
+ final_output = ops.concat([core_attn_out_new, last_recurrent_state_new], 0)
112
+
113
+ return [final_output.output(0)]
114
+
115
+
116
+ # Conversion rule for the `SelectiveSSMRecurrentCellOp` operation in a Torch graph.
117
+ #
118
+ # This generalizes the recurrent-cell-to-`ov::Loop` approach (originally introduced for the
119
+ # GatedDeltaNet block, see `convert_recurrent_attention_cell` above) to the Mamba2 selective
120
+ # state-space recurrence used by hybrid Mamba2 models such as GraniteMoeHybrid (Granite-4.0).
121
+ #
122
+ # The Mamba2 single-step recurrence follows the standard Mamba-2 discretization:
123
+ # state_t = state_{t-1} * dA_t + dBx_t # [B, H, P, N]
124
+ # y_t = reduce_sum(state_t * C_t, axis=N) # [B, H, P]
125
+ #
126
+ # All the heavy discretization tensors are computed vectorized over the whole sequence BEFORE
127
+ # the loop, so the loop body stays as simple as possible. This mirrors the torch reference:
128
+ # dA = exp(A * dt).reshape(B, T, H, 1, 1) # [B, T, H, 1, 1]
129
+ # dB = dt.reshape(B, T, H, 1) * B # [B, T, H, N]
130
+ # dBx = dB.reshape(B, T, H, 1, N) * x.reshape(B, T, H, P, 1) # [B, T, H, P, N]
131
+ # C = C.reshape(B, T, H, 1, N) # [B, T, H, 1, N]
132
+ # The loop then simply slices dA/dBx/C along dim 1 (T) and runs the two-line recurrence.
133
+ # Inputs are in [B, T, H, ...] layout; the skip connection `x_t * D` does not depend on the
134
+ # recurrent state and is added outside.
135
+ #
136
+ # The `SelectiveSSMRecurrentCellOp` appears in the Torch graph as a result of replacing the
137
+ # `SelectiveSSMRecurrentCell` `torch.nn.Module` via a registered `ModuleExtension` in the OpenVINO
138
+ # PyTorch frontend; OpenVINO then applies this conversion rule to the resulting operation.
139
+ def convert_recurrent_selective_ssm_cell(context):
140
+ # Inputs match the forward signature of `SelectiveSSMRecurrentCell`:
141
+ # A [H] — negative log-decay rates
142
+ # dt [B, T, H] — time steps
143
+ # B [B, T, G, N] — input matrix (G groups, expanded to H before the loop)
144
+ # x [B, T, H, P] — input hidden states
145
+ # C [B, T, G, N] — output matrix (G groups, expanded to H before the loop)
146
+ # recurrent_state [B, H, P, N] — initial recurrent state
147
+ A = context.get_input(0) # [H]
148
+ dt = context.get_input(1) # [B, T, H]
149
+ B = context.get_input(2) # [B, T, G, N]
150
+ x = context.get_input(3) # [B, T, H, P]
151
+ C = context.get_input(4) # [B, T, G, N]
152
+ recurrent_state = context.get_input(5) # [B, H, P, N]
153
+
154
+ const_zero_axis = ops.constant(0, dtype=np.int32)
155
+ const_one = ops.constant(1, dtype=np.int32)
156
+ const_minus_one = ops.constant(-1, dtype=np.int32)
157
+ const_minus_two = ops.constant(-2, dtype=np.int32)
158
+
159
+ # Compute heads_per_group = H / G from the shapes of dt and B.
160
+ dt_shape = ops.shape_of(dt)
161
+ B_shape = ops.shape_of(B)
162
+ const_two = ops.constant(2, dtype=np.int32)
163
+ num_heads = ops.gather(dt_shape, const_two, const_zero_axis) # H
164
+ num_groups = ops.gather(B_shape, const_two, const_zero_axis) # G
165
+ heads_per_group = ops.convert(ops.divide(num_heads, num_groups), "i64")
166
+
167
+ # Expand grouped B/C from [B, T, G, N] → [B, T, H, N] via repeat_interleave along dim 2:
168
+ # reshape to [B, T, G, 1, N] → tile [1, 1, 1, heads_per_group, 1] → reshape [B, T, H, N]
169
+ B_5d = ops.unsqueeze(B, ops.constant(3, dtype=np.int32)) # [B, T, G, 1, N]
170
+ C_5d = ops.unsqueeze(C, ops.constant(3, dtype=np.int32)) # [B, T, G, 1, N]
171
+ tile_shape = ops.concat(
172
+ [
173
+ ops.constant([1, 1, 1], dtype=np.int64),
174
+ ops.unsqueeze(heads_per_group, const_zero_axis),
175
+ ops.constant([1], dtype=np.int64),
176
+ ],
177
+ 0,
178
+ )
179
+ B_tiled = ops.tile(B_5d, tile_shape) # [B, T, G, H/G, N]
180
+ C_tiled = ops.tile(C_5d, tile_shape) # [B, T, G, H/G, N]
181
+
182
+ # Reshape [B, T, G, H/G, N] → [B, T, H, N]
183
+ x_shape = ops.shape_of(x)
184
+ N = ops.gather(B_shape, ops.constant(3, dtype=np.int32), const_zero_axis)
185
+ BC_shape = ops.concat([ops.constant([0, 0, -1], dtype=np.int64), ops.unsqueeze(N, const_zero_axis)], 0)
186
+ B = ops.reshape(B_tiled, BC_shape, True) # [B, T, H, N]
187
+ C = ops.reshape(C_tiled, BC_shape, True) # [B, T, H, N]
188
+
189
+ # Vectorized discretization over the whole sequence, before the loop (mirrors torch):
190
+ # dA = exp(A * dt).reshape(B, T, H, 1, 1)
191
+ # dB = dt.reshape(B, T, H, 1) * B
192
+ # dBx = dB.reshape(B, T, H, 1, N) * x.reshape(B, T, H, P, 1) → [B, T, H, P, N]
193
+ # C = C.reshape(B, T, H, 1, N)
194
+ dA = ops.exp(ops.multiply(A, dt)) # [B, T, H]
195
+ dA = ops.reshape(dA, ops.constant([0, 0, 0, 1, 1], dtype=np.int64), True) # [B, T, H, 1, 1]
196
+ dB = ops.multiply(ops.unsqueeze(dt, const_minus_one), B) # [B, T, H, N]
197
+ dBx = ops.multiply(
198
+ ops.unsqueeze(dB, const_minus_two), # [B, T, H, 1, N]
199
+ ops.unsqueeze(x, const_minus_one), # [B, T, H, P, 1]
200
+ ) # [B, T, H, P, N]
201
+ C = ops.unsqueeze(C, const_minus_two) # [B, T, H, 1, N]
202
+
203
+ # Build the zero-initialized output accumulator with shape [B, T, H, P].
204
+ const_zero_f32 = ops.constant(0, dtype=np.float32)
205
+ output = ops.broadcast(const_zero_f32, x_shape)
206
+
207
+ # Trip count for the loop equals the sequence length (dim 1 of x).
208
+ seq_len = ops.gather(x_shape, const_one, const_zero_axis)
209
+ seq_len = ops.convert(seq_len, "i32")
210
+
211
+ # Body parameters (one timestep slice each along dim 1). All tensors are already discretized.
212
+ timestep_param = ops.parameter([], np.int32, "timestep")
213
+ dA_t_param = ops.parameter([-1, 1, -1, 1, 1], np.float32, "dA_t") # [B, 1, H, 1, 1]
214
+ dBx_t_param = ops.parameter([-1, 1, -1, -1, -1], np.float32, "dBx_t") # [B, 1, H, P, N]
215
+ C_t_param = ops.parameter([-1, 1, -1, 1, -1], np.float32, "C_t") # [B, 1, H, 1, N]
216
+ recurrent_state_t = ops.parameter([-1, -1, -1, -1], np.float32, "recurrent_state_t") # [B, H, P, N]
217
+ output_t = ops.parameter([-1, -1, -1, -1], np.float32, "output_t") # [B, T, H, P]
218
+
219
+ # Drop the singleton sequence dimension introduced by slicing.
220
+ dA_t = ops.squeeze(dA_t_param, const_one) # [B, H, 1, 1]
221
+ dBx_t = ops.squeeze(dBx_t_param, const_one) # [B, H, P, N]
222
+ C_t = ops.squeeze(C_t_param, const_one) # [B, H, 1, N]
223
+
224
+ # output_recurrent_state = output_recurrent_state * dA[:, t] + dBx[:, t]
225
+ recurrent_state_new = ops.add(ops.multiply(recurrent_state_t, dA_t), dBx_t) # [B, H, P, N]
226
+
227
+ # output[:, t] = (output_recurrent_state * C[:, t]).sum(dim=-1)
228
+ y_t = ops.reduce_sum(ops.multiply(recurrent_state_new, C_t), const_minus_one, False) # [B, H, P]
229
+ y_t = ops.unsqueeze(y_t, const_one) # [B, 1, H, P]
230
+
231
+ timestep = ops.unsqueeze(timestep_param, const_zero_axis)
232
+ output_res = ops.scatter_update(output_t, timestep, y_t, const_one)
233
+ recurrent_state_res = recurrent_state_new
234
+
235
+ body_cond = ops.constant([True], dtype=bool)
236
+ body_model = ov.Model(
237
+ [body_cond, recurrent_state_res, output_res],
238
+ [
239
+ timestep_param,
240
+ dA_t_param,
241
+ dBx_t_param,
242
+ C_t_param,
243
+ recurrent_state_t,
244
+ output_t,
245
+ ],
246
+ "selective_ssm_body_model",
247
+ )
248
+
249
+ loop = ops.loop(seq_len, ops.constant(True, dtype="bool"))
250
+ loop.set_function(body_model)
251
+
252
+ loop.set_sliced_input(dA_t_param, dA.output(0), 0, 1, 1, -1, 1)
253
+ loop.set_sliced_input(dBx_t_param, dBx.output(0), 0, 1, 1, -1, 1)
254
+ loop.set_sliced_input(C_t_param, C.output(0), 0, 1, 1, -1, 1)
255
+ loop.set_merged_input(recurrent_state_t, recurrent_state, recurrent_state_res.output(0))
256
+ loop.set_merged_input(output_t, output.output(0), output_res.output(0))
257
+ loop.set_special_body_ports([0, 0])
258
+
259
+ output_new = loop.get_iter_value(output_res.output(0), -1)
260
+ output_recurrent_state_new = loop.get_iter_value(recurrent_state_res.output(0), -1)
261
+
262
+ flatten_shape = ops.constant([-1], dtype=np.int32)
263
+ output_new = ops.reshape(output_new, flatten_shape, False)
264
+ output_recurrent_state_new = ops.reshape(output_recurrent_state_new, flatten_shape, False)
265
+
266
+ final_output = ops.concat([output_new, output_recurrent_state_new], 0)
267
+
268
+ return [final_output.output(0)]
@@ -354,7 +354,9 @@ class OpenVINOConfigWithPast(OpenVINOConfig, ABC):
354
354
  and "attention_mask" in dummy_inputs
355
355
  and self.task == "text-generation"
356
356
  ):
357
- seq_len = dummy_inputs["input_ids"].shape[1]
357
+ # VLM Eagle3 uses inputs_embeds instead of input_ids
358
+ main_input = dummy_inputs.get("input_ids", dummy_inputs.get("inputs_embeds"))
359
+ seq_len = main_input.shape[1]
358
360
  past_seq_len = dummy_inputs["past_key_values"][0][1].shape[-2]
359
361
  dummy_inputs["attention_mask"] = DummyInputGenerator.pad_input_on_dim(
360
362
  dummy_inputs["attention_mask"], desired_length=past_seq_len + seq_len, dim=1