bigdl-core-npu 2.6.0b20241120__cp310-cp310-win_amd64.whl → 2.6.0b20241121__cp310-cp310-win_amd64.whl

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 (81) hide show
  1. bigdl-core-npu/npu_llm.dll +0 -0
  2. {bigdl_core_npu-2.6.0b20241120.dist-info → bigdl_core_npu-2.6.0b20241121.dist-info}/METADATA +1 -1
  3. {bigdl_core_npu-2.6.0b20241120.dist-info → bigdl_core_npu-2.6.0b20241121.dist-info}/RECORD +75 -79
  4. intel_npu_acceleration_library/_version.py +1 -1
  5. intel_npu_acceleration_library/external/openvino/__init__.py +1 -0
  6. intel_npu_acceleration_library/external/openvino/_pyopenvino.cp310-win_amd64.pyd +0 -0
  7. intel_npu_acceleration_library/external/openvino/_pyopenvino.cp311-win_amd64.pyd +0 -0
  8. intel_npu_acceleration_library/external/openvino/_pyopenvino.cp312-win_amd64.pyd +0 -0
  9. intel_npu_acceleration_library/external/openvino/_pyopenvino.cp38-win_amd64.pyd +0 -0
  10. intel_npu_acceleration_library/external/openvino/_pyopenvino.cp39-win_amd64.pyd +0 -0
  11. intel_npu_acceleration_library/external/openvino/experimental/__init__.py +14 -0
  12. intel_npu_acceleration_library/external/openvino/frontend/jax/jaxpr_decoder.py +15 -5
  13. intel_npu_acceleration_library/external/openvino/frontend/jax/passes.py +65 -0
  14. intel_npu_acceleration_library/external/openvino/frontend/jax/utils.py +66 -13
  15. intel_npu_acceleration_library/external/openvino/frontend/onnx/py_onnx_frontend.cp310-win_amd64.pyd +0 -0
  16. intel_npu_acceleration_library/external/openvino/frontend/onnx/py_onnx_frontend.cp311-win_amd64.pyd +0 -0
  17. intel_npu_acceleration_library/external/openvino/frontend/onnx/py_onnx_frontend.cp312-win_amd64.pyd +0 -0
  18. intel_npu_acceleration_library/external/openvino/frontend/onnx/py_onnx_frontend.cp38-win_amd64.pyd +0 -0
  19. intel_npu_acceleration_library/external/openvino/frontend/onnx/py_onnx_frontend.cp39-win_amd64.pyd +0 -0
  20. intel_npu_acceleration_library/external/openvino/frontend/paddle/py_paddle_frontend.cp310-win_amd64.pyd +0 -0
  21. intel_npu_acceleration_library/external/openvino/frontend/paddle/py_paddle_frontend.cp311-win_amd64.pyd +0 -0
  22. intel_npu_acceleration_library/external/openvino/frontend/paddle/py_paddle_frontend.cp312-win_amd64.pyd +0 -0
  23. intel_npu_acceleration_library/external/openvino/frontend/paddle/py_paddle_frontend.cp38-win_amd64.pyd +0 -0
  24. intel_npu_acceleration_library/external/openvino/frontend/paddle/py_paddle_frontend.cp39-win_amd64.pyd +0 -0
  25. intel_npu_acceleration_library/external/openvino/frontend/pytorch/fx_decoder.py +29 -19
  26. intel_npu_acceleration_library/external/openvino/frontend/pytorch/gptq.py +46 -5
  27. intel_npu_acceleration_library/external/openvino/frontend/pytorch/py_pytorch_frontend.cp310-win_amd64.pyd +0 -0
  28. intel_npu_acceleration_library/external/openvino/frontend/pytorch/py_pytorch_frontend.cp311-win_amd64.pyd +0 -0
  29. intel_npu_acceleration_library/external/openvino/frontend/pytorch/py_pytorch_frontend.cp312-win_amd64.pyd +0 -0
  30. intel_npu_acceleration_library/external/openvino/frontend/pytorch/py_pytorch_frontend.cp38-win_amd64.pyd +0 -0
  31. intel_npu_acceleration_library/external/openvino/frontend/pytorch/py_pytorch_frontend.cp39-win_amd64.pyd +0 -0
  32. intel_npu_acceleration_library/external/openvino/frontend/pytorch/torchdynamo/backend.py +17 -5
  33. intel_npu_acceleration_library/external/openvino/frontend/pytorch/torchdynamo/partition.py +55 -47
  34. intel_npu_acceleration_library/external/openvino/frontend/pytorch/ts_decoder.py +92 -63
  35. intel_npu_acceleration_library/external/openvino/frontend/pytorch/utils.py +12 -10
  36. intel_npu_acceleration_library/external/openvino/frontend/tensorflow/py_tensorflow_frontend.cp310-win_amd64.pyd +0 -0
  37. intel_npu_acceleration_library/external/openvino/frontend/tensorflow/py_tensorflow_frontend.cp311-win_amd64.pyd +0 -0
  38. intel_npu_acceleration_library/external/openvino/frontend/tensorflow/py_tensorflow_frontend.cp312-win_amd64.pyd +0 -0
  39. intel_npu_acceleration_library/external/openvino/frontend/tensorflow/py_tensorflow_frontend.cp38-win_amd64.pyd +0 -0
  40. intel_npu_acceleration_library/external/openvino/frontend/tensorflow/py_tensorflow_frontend.cp39-win_amd64.pyd +0 -0
  41. intel_npu_acceleration_library/external/openvino/frontend/tensorflow/utils.py +31 -10
  42. intel_npu_acceleration_library/external/openvino/runtime/ie_api.py +1 -1
  43. intel_npu_acceleration_library/external/openvino/runtime/opset15/__init__.py +5 -0
  44. intel_npu_acceleration_library/external/openvino/runtime/opset15/ops.py +131 -1
  45. intel_npu_acceleration_library/external/openvino/runtime/opset6/ops.py +13 -4
  46. intel_npu_acceleration_library/external/openvino/runtime/opset8/ops.py +1 -1
  47. intel_npu_acceleration_library/external/openvino/runtime/properties/__init__.py +1 -0
  48. intel_npu_acceleration_library/external/openvino/runtime/utils/data_helpers/data_dispatcher.py +21 -3
  49. intel_npu_acceleration_library/external/openvino/runtime/utils/decorators.py +29 -9
  50. intel_npu_acceleration_library/external/openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.py +0 -1
  51. intel_npu_acceleration_library/lib/Release/intel_npu_acceleration_library.dll +0 -0
  52. intel_npu_acceleration_library/lib/Release/openvino.dll +0 -0
  53. intel_npu_acceleration_library/lib/Release/openvino_auto_batch_plugin.dll +0 -0
  54. intel_npu_acceleration_library/lib/Release/openvino_auto_plugin.dll +0 -0
  55. intel_npu_acceleration_library/lib/Release/openvino_c.dll +0 -0
  56. intel_npu_acceleration_library/lib/Release/openvino_hetero_plugin.dll +0 -0
  57. intel_npu_acceleration_library/lib/Release/openvino_intel_cpu_plugin.dll +0 -0
  58. intel_npu_acceleration_library/lib/Release/openvino_intel_gpu_plugin.dll +0 -0
  59. intel_npu_acceleration_library/lib/Release/openvino_intel_npu_plugin.dll +0 -0
  60. intel_npu_acceleration_library/lib/Release/openvino_ir_frontend.dll +0 -0
  61. intel_npu_acceleration_library/lib/Release/openvino_onnx_frontend.dll +0 -0
  62. intel_npu_acceleration_library/lib/Release/openvino_paddle_frontend.dll +0 -0
  63. intel_npu_acceleration_library/lib/Release/openvino_pytorch_frontend.dll +0 -0
  64. intel_npu_acceleration_library/lib/Release/openvino_tensorflow_frontend.dll +0 -0
  65. intel_npu_acceleration_library/lib/Release/openvino_tensorflow_lite_frontend.dll +0 -0
  66. intel_npu_acceleration_library/lib/Release/tbb12.dll +0 -0
  67. intel_npu_acceleration_library/lib/Release/tbb12_debug.dll +0 -0
  68. intel_npu_acceleration_library/lib/Release/tbbbind_2_5.dll +0 -0
  69. intel_npu_acceleration_library/lib/Release/tbbbind_2_5_debug.dll +0 -0
  70. intel_npu_acceleration_library/lib/Release/tbbmalloc.dll +0 -0
  71. intel_npu_acceleration_library/lib/Release/tbbmalloc_debug.dll +0 -0
  72. intel_npu_acceleration_library/lib/Release/tbbmalloc_proxy.dll +0 -0
  73. intel_npu_acceleration_library/lib/Release/tbbmalloc_proxy_debug.dll +0 -0
  74. intel_npu_acceleration_library/external/openvino/frontend/jax/py_jax_frontend.cp310-win_amd64.pyd +0 -0
  75. intel_npu_acceleration_library/external/openvino/frontend/jax/py_jax_frontend.cp311-win_amd64.pyd +0 -0
  76. intel_npu_acceleration_library/external/openvino/frontend/jax/py_jax_frontend.cp312-win_amd64.pyd +0 -0
  77. intel_npu_acceleration_library/external/openvino/frontend/jax/py_jax_frontend.cp38-win_amd64.pyd +0 -0
  78. intel_npu_acceleration_library/external/openvino/frontend/jax/py_jax_frontend.cp39-win_amd64.pyd +0 -0
  79. intel_npu_acceleration_library/lib/Release/openvino_jax_frontend.dll +0 -0
  80. {bigdl_core_npu-2.6.0b20241120.dist-info → bigdl_core_npu-2.6.0b20241121.dist-info}/WHEEL +0 -0
  81. {bigdl_core_npu-2.6.0b20241120.dist-info → bigdl_core_npu-2.6.0b20241121.dist-info}/top_level.txt +0 -0
@@ -7,7 +7,14 @@
7
7
  from openvino.frontend.pytorch.py_pytorch_frontend import _FrontEndPytorchDecoder as Decoder
8
8
  from openvino.frontend.pytorch.py_pytorch_frontend import _Type as DecoderType
9
9
  from openvino.runtime import op, PartialShape, Type as OVType, OVAny
10
- from openvino.frontend.pytorch.utils import ivalue_to_constant, get_value_from_getattr, pt_to_ov_type_map, prepare_example_inputs_and_model, convert_quantized_tensor, graph_has_ops
10
+ from openvino.frontend.pytorch.utils import (
11
+ ivalue_to_constant,
12
+ get_value_from_getattr,
13
+ pt_to_ov_type_map,
14
+ prepare_example_inputs_and_model,
15
+ convert_quantized_tensor,
16
+ graph_has_ops,
17
+ )
11
18
  from openvino.runtime import opset11 as ops
12
19
  from openvino.frontend.pytorch import gptq
13
20
  from openvino.frontend.pytorch import patch_model
@@ -15,20 +22,22 @@ from openvino.frontend.pytorch.module_extension import ModuleExtension
15
22
 
16
23
  import typing
17
24
  import torch
25
+ import inspect
18
26
 
19
27
 
20
- class TorchScriptPythonDecoder (Decoder):
28
+ class TorchScriptPythonDecoder(Decoder):
21
29
  def __init__(
22
- self,
23
- pt_module,
24
- graph_element=None,
25
- example_input=None,
26
- alias_db=None,
27
- shared_memory=True,
28
- skip_freeze=False,
29
- constant_cache=None,
30
- module_extensions=None):
31
- Decoder.__init__(self)
30
+ self,
31
+ pt_module,
32
+ graph_element=None,
33
+ example_input=None,
34
+ alias_db=None,
35
+ shared_memory=True,
36
+ skip_freeze=False,
37
+ constant_cache=None,
38
+ module_extensions=None,
39
+ ):
40
+ super().__init__()
32
41
  # We store every decoder created by this decoder so that all them are not deleted until the first decoder is deleted
33
42
  self.m_decoders = []
34
43
  self._input_signature = None
@@ -36,7 +45,12 @@ class TorchScriptPythonDecoder (Decoder):
36
45
  self._input_is_list = False
37
46
  self.constant_cache = constant_cache if constant_cache is not None else dict()
38
47
  self.module_extensions = module_extensions
48
+ self.config = None
49
+ self.out_debug_name_overwrites = {}
39
50
  if graph_element is None:
51
+ if hasattr(pt_module, "config"):
52
+ self.config = pt_module.config.to_dict() if not isinstance(
53
+ pt_module.config, dict) else pt_module.config
40
54
  try:
41
55
  pt_module = self._get_scripted_model(
42
56
  pt_module, example_input, skip_freeze)
@@ -53,7 +67,8 @@ class TorchScriptPythonDecoder (Decoder):
53
67
  f"Couldn't get TorchScript module by {msg}. With exception:\n{e}\n{help_msg} "
54
68
  "You can also provide TorchScript module that you obtained"
55
69
  " yourself, please refer to PyTorch documentation: "
56
- "https://pytorch.org/tutorials/beginner/Intro_to_TorchScript_tutorial.html.")
70
+ "https://pytorch.org/tutorials/beginner/Intro_to_TorchScript_tutorial.html."
71
+ )
57
72
  self.graph_element = pt_module.inlined_graph
58
73
  self.alias_db = self.graph_element.alias_db()
59
74
  else:
@@ -77,27 +92,27 @@ class TorchScriptPythonDecoder (Decoder):
77
92
  self._transform_tensor_list_constants_to_listconstruct(
78
93
  self.graph_element)
79
94
  self._transform_optional_constants(self.graph_element)
80
- self.out_debug_name_overwrites = {}
81
95
 
82
96
  @staticmethod
83
97
  def _get_preserved_attributes(model) -> list:
84
98
  preserved_attributes = []
85
99
  for name, module in model.named_modules():
86
- if hasattr(module, "weight"):
87
- if module.weight is not None and getattr(module.weight, "dtype", None) in [torch.int8, torch.uint8, torch.float16, torch.bfloat16]:
88
- preserved_attributes.append(name)
100
+ compressed_types = [torch.int8, torch.uint8,
101
+ torch.float16, torch.bfloat16]
102
+ if hasattr(module, "weight") and getattr(module.weight, "dtype", None) in compressed_types:
103
+ preserved_attributes.append(name)
89
104
  return preserved_attributes
90
105
 
91
106
  def _get_scripted_model(self, pt_module, example_inputs=None, skip_freeze=False):
92
- import torch
93
- import inspect
94
-
95
107
  freeze_by_default = False
96
108
  if isinstance(pt_module, torch.nn.Module):
97
109
  pt_module.eval()
98
110
  input_signature = None
99
111
  input_parameters = None
100
- if isinstance(pt_module, torch.nn.Module) and not isinstance(pt_module, (torch.jit._trace.TopLevelTracedModule, torch.jit._script.RecursiveScriptModule)):
112
+ if isinstance(pt_module, torch.nn.Module) and not isinstance(
113
+ pt_module, (torch.jit._trace.TopLevelTracedModule,
114
+ torch.jit._script.RecursiveScriptModule)
115
+ ):
101
116
  # input params is dictionary contains input names and their signature values (type hints and default values if any)
102
117
  input_params = inspect.signature(pt_module.forward if hasattr(
103
118
  pt_module, "forward") else pt_module.__call__).parameters
@@ -105,7 +120,8 @@ class TorchScriptPythonDecoder (Decoder):
105
120
 
106
121
  if example_inputs is None:
107
122
  if self.module_extensions:
108
- raise RuntimeError("ModuleExtension is not supported for scripting. Please provide valid example_input argument to run tracing.")
123
+ raise RuntimeError(
124
+ "ModuleExtension is not supported for scripting. Please provide valid example_input argument to run tracing.")
109
125
  scripted = torch.jit.script(pt_module)
110
126
  freeze_by_default = True
111
127
  else:
@@ -113,9 +129,10 @@ class TorchScriptPythonDecoder (Decoder):
113
129
  example_inputs, input_params, pt_module)
114
130
 
115
131
  # name of attribute in a patched module where the original forward method is kept
116
- orig_forward_name = '_openvino_module_extension_patch_orig_forward'
132
+ orig_forward_name = "_openvino_module_extension_patch_orig_forward"
117
133
  if self.module_extensions:
118
- patch_model.patch_model(pt_module, self.module_extensions, orig_forward_name)
134
+ patch_model.patch_model(
135
+ pt_module, self.module_extensions, orig_forward_name)
119
136
 
120
137
  gptq_patched = False
121
138
  if gptq.detect_gptq_model(pt_module):
@@ -124,9 +141,9 @@ class TorchScriptPythonDecoder (Decoder):
124
141
  gptq_patched = True
125
142
  except Exception as error:
126
143
  print(
127
- '[ WARNING ] Failed patching of AutoGPTQ model. Error message:\n', error)
144
+ "[ WARNING ] Failed patching of AutoGPTQ model. Error message:\n", error)
128
145
  print(
129
- '[ WARNING ] Tracing of the model will likely be unsuccessful or incorrect')
146
+ "[ WARNING ] Tracing of the model will likely be unsuccessful or incorrect")
130
147
  gptq.unpatch_model(pt_module)
131
148
  gptq_patched = False
132
149
 
@@ -139,10 +156,13 @@ class TorchScriptPythonDecoder (Decoder):
139
156
  if self.module_extensions:
140
157
  patch_model.unpatch_model(pt_module, orig_forward_name)
141
158
 
142
- if not freeze_by_default and graph_has_ops(scripted.inlined_graph, ["prim::Uninitialized", "prim::unchecked_cast", "aten::append"]):
159
+ have_to_freeze_ops = ["prim::Uninitialized",
160
+ "prim::unchecked_cast", "aten::append"]
161
+ if not freeze_by_default and graph_has_ops(scripted.inlined_graph, have_to_freeze_ops):
143
162
  # freeze models with unsupported ops
144
163
  freeze_by_default = True
145
- if freeze_by_default and graph_has_ops(scripted.inlined_graph, ["quantized", "aten::as_strided"]):
164
+ quantized_hint_ops = ["quantized", "aten::as_strided"]
165
+ if freeze_by_default and graph_has_ops(scripted.inlined_graph, quantized_hint_ops):
146
166
  # do not freeze quantized models and can't freeze for aten::as_strided it will result in incorrect inference
147
167
  freeze_by_default = False
148
168
  if freeze_by_default and not skip_freeze:
@@ -253,12 +273,14 @@ class TorchScriptPythonDecoder (Decoder):
253
273
  def visit_subgraph(self, node_visitor) -> None:
254
274
  # make sure topological order is satisfied
255
275
  for node in self.graph_element.nodes():
256
- decoder = TorchScriptPythonDecoder(self.pt_module,
257
- node,
258
- alias_db=self.alias_db,
259
- shared_memory=self._shared_memory,
260
- constant_cache=self.constant_cache,
261
- module_extensions=self.module_extensions)
276
+ decoder = TorchScriptPythonDecoder(
277
+ self.pt_module,
278
+ node,
279
+ alias_db=self.alias_db,
280
+ shared_memory=self._shared_memory,
281
+ constant_cache=self.constant_cache,
282
+ module_extensions=self.module_extensions,
283
+ )
262
284
  self.m_decoders.append(decoder)
263
285
  node_visitor(decoder)
264
286
 
@@ -278,31 +300,32 @@ class TorchScriptPythonDecoder (Decoder):
278
300
  return list(self.graph_element.blocks())
279
301
 
280
302
  def get_subgraph_decoder(self, index: int):
281
- decoder = TorchScriptPythonDecoder(self.pt_module,
282
- self.get_subgraphs()[index],
283
- alias_db=self.alias_db,
284
- shared_memory=self._shared_memory,
285
- module_extensions=self.module_extensions)
303
+ decoder = TorchScriptPythonDecoder(
304
+ self.pt_module, self.get_subgraphs(
305
+ )[index], alias_db=self.alias_db, shared_memory=self._shared_memory, module_extensions=self.module_extensions
306
+ )
286
307
  self.m_decoders.append(decoder)
287
308
  return decoder
288
309
 
289
310
  def get_op_type(self) -> str:
290
311
  assert isinstance(
291
312
  self.graph_element, torch.Node), "Function can be called only when self.graph_element is of type torch.Node"
292
- if self.graph_element.kind() == "prim::PythonOp":
293
- if hasattr(self.graph_element, 'pyobj') and callable(self.graph_element.pyobj) and hasattr(self.graph_element.pyobj(), '__self__'):
294
- trampoline = self.graph_element.pyobj().__self__
295
- if hasattr(trampoline, 'target_extension') and isinstance(trampoline.target_extension, ModuleExtension):
296
- target_op = trampoline.target_extension.target_op
297
- if callable(target_op):
298
- target = target_op(trampoline.original_module)
299
- elif isinstance(target_op, str):
300
- target = target_op
301
- # TODO: Support target as a callable that will play a role of ConversionExtension for an entire module instead of a single op.
302
- # Without supporting target as a callable here, ConversionExtension functionality is still possible to implement
303
- # by combining two extensions: ModuleExtension that use temporary name as a target op and another extension of type ConversionExtension
304
- # that translates that particular temporary name to custom graph. But providing conversion code as a callable `target` is more convenient.
305
- return target
313
+ if self.graph_element.kind() == "prim::PythonOp" and callable(getattr(self.graph_element, "pyobj", None)):
314
+ pyobj = self.graph_element.pyobj()
315
+ trampoline = getattr(pyobj, "__self__", None)
316
+ target_extension = getattr(trampoline, "target_extension", None)
317
+
318
+ if isinstance(target_extension, ModuleExtension):
319
+ target_op = target_extension.target_op
320
+ if callable(target_op):
321
+ target = target_op(trampoline.original_module)
322
+ elif isinstance(target_op, str):
323
+ target = target_op
324
+ # TODO: Support target as a callable that will play a role of ConversionExtension for an entire module instead of a single op.
325
+ # Without supporting target as a callable here, ConversionExtension functionality is still possible to implement
326
+ # by combining two extensions: ModuleExtension that use temporary name as a target op and another extension of type ConversionExtension
327
+ # that translates that particular temporary name to custom graph. But providing conversion code as a callable `target` is more convenient.
328
+ return target
306
329
  return self.graph_element.kind()
307
330
 
308
331
  def get_schema(self) -> str:
@@ -342,8 +365,8 @@ class TorchScriptPythonDecoder (Decoder):
342
365
  self.constant_cache[name] = outputs
343
366
 
344
367
  def try_decode_get_attr(self):
345
- pt_value, name = get_value_from_getattr(self.graph_element,
346
- self.pt_module)
368
+ pt_value, name = get_value_from_getattr(
369
+ self.graph_element, self.pt_module)
347
370
  assert pt_value is not None, "Couldn't retrieve value from prim::GetAttr"
348
371
  if isinstance(pt_value, torch.ScriptObject):
349
372
  # We assume this is __torch__.torch.classes.quantized.Conv2dPackedParamsBase or __torch__.torch.classes.quantized.LinearPackedParamsBase
@@ -389,8 +412,8 @@ class TorchScriptPythonDecoder (Decoder):
389
412
  if name in self.constant_cache:
390
413
  const = self.constant_cache[name]
391
414
  else:
392
- const = ivalue_to_constant(pt_value,
393
- shared_memory=self._shared_memory)
415
+ const = ivalue_to_constant(
416
+ pt_value, shared_memory=self._shared_memory)
394
417
  self._add_name_to_const_and_cache(const, name)
395
418
  return const
396
419
  else:
@@ -404,12 +427,11 @@ class TorchScriptPythonDecoder (Decoder):
404
427
  pt_value = self._raw_output(0)
405
428
  pt_type = pt_value.type()
406
429
  if isinstance(pt_type, torch.TensorType):
407
- return ivalue_to_constant(pt_value.toIValue(),
408
- shared_memory=self._shared_memory)
430
+ return ivalue_to_constant(pt_value.toIValue(), shared_memory=self._shared_memory)
409
431
  if isinstance(pt_type, torch.ListType):
410
432
  return self._as_constant_list(pt_value)
411
- const = ivalue_to_constant(pt_value.toIValue(),
412
- shared_memory=self._shared_memory)
433
+ const = ivalue_to_constant(
434
+ pt_value.toIValue(), shared_memory=self._shared_memory)
413
435
  if len(const) > 0:
414
436
  # set name corresponding to state_dict name
415
437
  const[0].get_node().set_friendly_name(
@@ -463,8 +485,8 @@ class TorchScriptPythonDecoder (Decoder):
463
485
  else:
464
486
  in_node = r_input.node()
465
487
  if in_node.kind() == "prim::GetAttr":
466
- pt_value, _ = get_value_from_getattr(in_node,
467
- self.pt_module)
488
+ pt_value, _ = get_value_from_getattr(
489
+ in_node, self.pt_module)
468
490
  return pt_value is None
469
491
  return False
470
492
 
@@ -490,6 +512,13 @@ class TorchScriptPythonDecoder (Decoder):
490
512
  def get_named_input(self, name):
491
513
  raise RuntimeError("There is no named inputs in TS graph")
492
514
 
515
+ def get_rt_info(self):
516
+ rt_info = {}
517
+ if self.config is not None and "quantization_config" in self.config and "sym" in self.config["quantization_config"]:
518
+ rt_info["symmetric_quantization"] = OVAny(
519
+ self.config["quantization_config"]["sym"])
520
+ return rt_info
521
+
493
522
  @staticmethod
494
523
  def _transform_tensor_list_constants_to_listconstruct(graph: torch.Graph):
495
524
  # Function replaces prim::Constant containing List of Tensors with
@@ -25,7 +25,7 @@ def fetch_attr(self_module, target: str):
25
25
  Return:
26
26
  Any: The value of the attribute.
27
27
  """
28
- target_atoms = target.split('.')
28
+ target_atoms = target.split(".")
29
29
  attr_itr = self_module
30
30
  for i, atom in enumerate(target_atoms):
31
31
  if not hasattr(attr_itr, atom):
@@ -91,12 +91,13 @@ def get_value_from_getattr(getattr_node, self_module):
91
91
  node = stack.pop()
92
92
  attr_name = node.s("name")
93
93
  assert hasattr(
94
- module, attr_name), f"No attribute with name \"{attr_name}\" found in module."
94
+ module, attr_name), f'No attribute with name "{attr_name}" found in module.'
95
95
  path_name = ".".join([path_name, attr_name])
96
96
  module = getattr(module, attr_name)
97
97
  return module, path_name
98
98
 
99
- def graph_has_ops(graph, op_types:list) -> bool:
99
+
100
+ def graph_has_ops(graph, op_types: list) -> bool:
100
101
  res = False
101
102
  for n in graph.nodes():
102
103
  if any(kind in n.kind() for kind in op_types):
@@ -106,7 +107,7 @@ def graph_has_ops(graph, op_types:list) -> bool:
106
107
  if res:
107
108
  return res
108
109
  return res
109
-
110
+
110
111
 
111
112
  pt_to_ov_type_map = {
112
113
  "float": OVType.f32,
@@ -134,7 +135,7 @@ pt_to_ov_type_map = {
134
135
  "torch.BoolTensor": OVType.boolean,
135
136
  "torch.quint8": OVType.u8,
136
137
  "torch.qint8": OVType.i8,
137
- "torch.qint32": OVType.i32
138
+ "torch.qint32": OVType.i32,
138
139
  }
139
140
 
140
141
 
@@ -159,7 +160,7 @@ def process_dict_inputs(inputs, input_params, model):
159
160
  ordered_inputs.append(input_name)
160
161
 
161
162
  input_signature = list(input_params)
162
- if ordered_inputs == input_signature[:len(ordered_inputs)]:
163
+ if ordered_inputs == input_signature[: len(ordered_inputs)]:
163
164
  example_inputs = [inputs[input_name] for input_name in ordered_inputs]
164
165
  if all([isinstance(inp, torch.Tensor) for inp in example_inputs]):
165
166
  return {"example_inputs": [inputs[name] for name in ordered_inputs]}, ordered_inputs, model
@@ -191,8 +192,8 @@ def process_dict_inputs(inputs, input_params, model):
191
192
  str(input_params[input_name]).replace("NoneType", "None"))
192
193
  input_params_str.append(f"{input_name}={input_name}")
193
194
 
194
- wrapper_class = wrapper_template.format(input_sign=', '.join(
195
- input_sign_str), example_input=', '.join(input_params_str))
195
+ wrapper_class = wrapper_template.format(input_sign=", ".join(
196
+ input_sign_str), example_input=", ".join(input_params_str))
196
197
  result = {}
197
198
  try:
198
199
  exec(wrapper_class, result)
@@ -210,7 +211,8 @@ def prepare_example_inputs_and_model(inputs, input_params, model):
210
211
  input_is_list = False
211
212
  input_signature = list(input_params)
212
213
  if isinstance(inputs, dict):
213
- examples, ordered, wrapped = process_dict_inputs(inputs, input_params, model)
214
+ examples, ordered, wrapped = process_dict_inputs(
215
+ inputs, input_params, model)
214
216
  return examples, ordered, wrapped, input_is_list
215
217
  if isinstance(inputs, list) and len(inputs) == 1 and isinstance(inputs[0], torch.Tensor):
216
218
  if "typing.List" in str(input_params[input_signature[0]].annotation):
@@ -219,7 +221,7 @@ def prepare_example_inputs_and_model(inputs, input_params, model):
219
221
 
220
222
  if isinstance(inputs, torch.Tensor):
221
223
  inputs = [inputs]
222
- input_signature = input_signature[:len(inputs)]
224
+ input_signature = input_signature[: len(inputs)]
223
225
  return {"example_inputs": inputs}, input_signature, model, input_is_list
224
226
 
225
227
 
@@ -6,13 +6,12 @@
6
6
 
7
7
 
8
8
  import logging as log
9
+ import numpy as np
9
10
  import sys
11
+ from openvino.runtime import PartialShape, Dimension, Type
10
12
  from packaging.version import parse, Version
11
13
  from typing import List, Dict, Union
12
14
 
13
- import numpy as np
14
- from openvino.runtime import PartialShape, Dimension, Type
15
-
16
15
 
17
16
  # TODO: reuse this method in ovc and remove duplication
18
17
  def get_static_shape(shape: [PartialShape, list, tuple], dynamic_value=None):
@@ -106,13 +105,32 @@ def trace_tf_model_if_needed(input_model, placeholder_shapes, placeholder_data_t
106
105
  return trace_tf_model(input_model, placeholder_shapes, placeholder_data_types, example_input)
107
106
 
108
107
 
109
- def get_input_spec_from_model(model):
108
+ def partial_shape_to_list(partial_shape: PartialShape):
109
+ if partial_shape.rank.is_dynamic:
110
+ return None
111
+ res_list = []
112
+ for dim in partial_shape:
113
+ if dim.is_static:
114
+ res_list.append(dim.get_length())
115
+ else:
116
+ res_list.append(None)
117
+ return res_list
118
+
119
+
120
+ def get_input_spec_from_model(model, input_shapes=None):
110
121
  import tensorflow as tf
111
122
  if hasattr(model, "_build_input_shape") and model._build_input_shape is not None:
112
123
  if isinstance(model._build_input_shape, list):
113
124
  input_spec = [[tf.TensorSpec(shape) for shape in model._build_input_shape]]
114
125
  else:
115
126
  input_spec = [tf.TensorSpec(model._build_input_shape)]
127
+ elif input_shapes and isinstance(input_shapes, list) and len(input_shapes) > 0:
128
+ input_spec = []
129
+ for input_shape in input_shapes:
130
+ if isinstance(input_shape, PartialShape):
131
+ input_spec.append(tf.TensorSpec(partial_shape_to_list(input_shape)))
132
+ else:
133
+ input_spec.append(tf.TensorSpec(None))
116
134
  else:
117
135
  input_spec = [tf.TensorSpec(None)]
118
136
  return input_spec
@@ -199,10 +217,13 @@ def create_generic_function_from_keras_model(keras_model):
199
217
  if tf_input_signature is not None:
200
218
  @tf.function(input_signature=tf_input_signature)
201
219
  def wrapper_function_dict(*args):
202
- input_dict = {}
203
- for ind, tensor_spec in enumerate(tf_input_signature):
204
- input_dict[tensor_spec.name] = args[ind]
205
- outputs = keras_model(input_dict)
220
+ if isinstance(keras_input_signature, list):
221
+ outputs = keras_model(args)
222
+ else:
223
+ input_dict = {}
224
+ for ind, tensor_spec in enumerate(tf_input_signature):
225
+ input_dict[tensor_spec.name] = args[ind]
226
+ outputs = keras_model(input_dict)
206
227
  # need to wrap the output into dictionary
207
228
  # it helps to preserve original keras tensor names
208
229
  post_outputs = {}
@@ -276,7 +297,7 @@ def trace_tf_model(model, input_shapes, input_types, example_input):
276
297
  "Could not trace the TF model with the following error: {}",
277
298
  use_example_input=False)
278
299
  else:
279
- input_spec = get_input_spec_from_model(model)
300
+ input_spec = get_input_spec_from_model(model, input_shapes)
280
301
  concrete_func = get_concrete_func(tf_function, input_spec, input_needs_packing,
281
302
  "Could not trace the TF model with the following error: {}.\n"
282
303
  "Please provide 'example_input'.")
@@ -457,4 +478,4 @@ def tf_type_to_ov_type(val):
457
478
  }
458
479
  if val not in tf_to_ov_type:
459
480
  raise Exception("The provided data type is not supported by OpenVino {}.".format(val))
460
- return tf_to_ov_type[val]
481
+ return tf_to_ov_type[val]
@@ -507,7 +507,7 @@ class Core(CoreBase):
507
507
  device_name: Optional[str] = None,
508
508
  config: Optional[dict] = None,
509
509
  *,
510
- weights: Optional[bytes] = None
510
+ weights: Optional[bytes] = None,
511
511
  ) -> CompiledModel:
512
512
  """Creates a compiled model.
513
513
 
@@ -10,3 +10,8 @@ from openvino.runtime.opset15.ops import col2im
10
10
  from openvino.runtime.opset15.ops import embedding_bag_offsets
11
11
  from openvino.runtime.opset15.ops import embedding_bag_packed
12
12
  from openvino.runtime.opset15.ops import scatter_nd_update
13
+ from openvino.runtime.opset15.ops import roi_align_rotated
14
+ from openvino.runtime.opset15.ops import string_tensor_pack
15
+ from openvino.runtime.opset15.ops import string_tensor_unpack
16
+ from openvino.runtime.opset15.ops import bitwise_left_shift
17
+ from openvino.runtime.opset15.ops import bitwise_right_shift
@@ -11,7 +11,7 @@ from openvino.runtime import Node, Type
11
11
  from openvino.runtime.opset1 import convert_like
12
12
  from openvino.runtime.opset14 import constant
13
13
  from openvino.runtime.opset_utils import _get_node_factory
14
- from openvino.runtime.utils.decorators import nameable_op
14
+ from openvino.runtime.utils.decorators import binary_op, nameable_op
15
15
  from openvino.runtime.utils.types import NodeInput, as_nodes
16
16
 
17
17
  _get_node_factory_opset15 = partial(_get_node_factory, "opset15")
@@ -144,3 +144,133 @@ def embedding_bag_packed(
144
144
  inputs.append(per_sample_weights)
145
145
 
146
146
  return _get_node_factory_opset15().create("EmbeddingBagPacked", as_nodes(*inputs, name=name), {"reduction": reduction})
147
+
148
+
149
+ @nameable_op
150
+ def roi_align_rotated(
151
+ data: NodeInput,
152
+ rois: NodeInput,
153
+ batch_indices: NodeInput,
154
+ pooled_h: int,
155
+ pooled_w: int,
156
+ sampling_ratio: int,
157
+ spatial_scale: float,
158
+ clockwise_mode: bool,
159
+ name: Optional[str] = None,
160
+ ) -> Node:
161
+ """Return a node which performs ROIAlignRotated operation.
162
+
163
+ :param data: Input data.
164
+ :param rois: RoIs (Regions of Interest) to pool over.
165
+ :param batch_indices: Tensor with each element denoting the index of
166
+ the corresponding image in the batch.
167
+ :param pooled_h: Height of the ROI output feature map.
168
+ :param pooled_w: Width of the ROI output feature map.
169
+ :param sampling_ratio: Number of bins over height and width to use to calculate
170
+ each output feature map element.
171
+ :param spatial_scale: Multiplicative spatial scale factor to translate ROI coordinates.
172
+ :param clockwise_mode: If true, rotation angle is interpreted as clockwise,
173
+ otherwise as counterclockwise
174
+ :param name: The optional name for the output node
175
+
176
+ :return: The new node which performs ROIAlignRotated
177
+ """
178
+ return _get_node_factory_opset15().create(
179
+ "ROIAlignRotated",
180
+ as_nodes(data, rois, batch_indices, name=name),
181
+ {
182
+ "pooled_h": pooled_h,
183
+ "pooled_w": pooled_w,
184
+ "sampling_ratio": sampling_ratio,
185
+ "spatial_scale": spatial_scale,
186
+ "clockwise_mode": clockwise_mode,
187
+ },
188
+ )
189
+
190
+
191
+ @nameable_op
192
+ def string_tensor_unpack(
193
+ data: NodeInput,
194
+ name: Optional[str] = None,
195
+ ) -> Node:
196
+ """Perform an operation which unpacks a batch of strings into three tensors.
197
+
198
+ :param data: The node providing input data.
199
+
200
+ :return: The new node performing StringTensorUnpack operation.
201
+ """
202
+ return _get_node_factory_opset15().create(
203
+ "StringTensorUnpack",
204
+ as_nodes(data, name=name)
205
+ )
206
+
207
+
208
+ @nameable_op
209
+ def string_tensor_pack(
210
+ begins: NodeInput,
211
+ ends: NodeInput,
212
+ symbols: NodeInput,
213
+ name: Optional[str] = None,
214
+ ) -> Node:
215
+ """Perform an operation which packs a concatenated batch of strings into a batched string tensor.
216
+
217
+ :param begins: ND tensor of non-negative integer numbers containing indices of each string's beginnings.
218
+ :param ends: ND tensor of non-negative integer numbers containing indices of each string's endings.
219
+ :param symbols: 1D tensor of concatenated strings data encoded in utf-8 bytes.
220
+
221
+ :return: The new node performing StringTensorPack operation.
222
+ """
223
+ return _get_node_factory_opset15().create(
224
+ "StringTensorPack",
225
+ as_nodes(begins, ends, symbols, name=name)
226
+ )
227
+
228
+
229
+ @binary_op
230
+ def bitwise_left_shift(
231
+ arg0: NodeInput,
232
+ arg1: NodeInput,
233
+ auto_broadcast: str = "NUMPY",
234
+ name: Optional[str] = None,
235
+ ) -> Node:
236
+ """Return node which performs BitwiseLeftShift operation on input nodes element-wise.
237
+
238
+ :param arg0: Node with data to be shifted.
239
+ :param arg1: Node with number of shifts.
240
+ :param auto_broadcast: The type of broadcasting specifies rules used for auto-broadcasting of input tensors.
241
+ Defaults to “NUMPY”.
242
+
243
+ :return: The new node performing BitwiseLeftShift operation.
244
+ """
245
+ return _get_node_factory_opset15().create(
246
+ "BitwiseLeftShift",
247
+ as_nodes(arg0, arg1, name=name),
248
+ {
249
+ "auto_broadcast": auto_broadcast.upper(),
250
+ },
251
+ )
252
+
253
+
254
+ @binary_op
255
+ def bitwise_right_shift(
256
+ arg0: NodeInput,
257
+ arg1: NodeInput,
258
+ auto_broadcast: str = "NUMPY",
259
+ name: Optional[str] = None,
260
+ ) -> Node:
261
+ """Return node which performs BitwiseRightShift operation on input nodes element-wise.
262
+
263
+ :param arg0: Tensor with data to be shifted.
264
+ :param arg1: Tensor with number of shifts.
265
+ :param auto_broadcast: The type of broadcasting specifies rules used for auto-broadcasting of input tensors.
266
+ Defaults to “NUMPY”.
267
+
268
+ :return: The new node performing BitwiseRightShift operation.
269
+ """
270
+ return _get_node_factory_opset15().create(
271
+ "BitwiseRightShift",
272
+ as_nodes(arg0, arg1, name=name),
273
+ {
274
+ "auto_broadcast": auto_broadcast.upper(),
275
+ },
276
+ )