Skip to content

Commit

Permalink
update requirements and warning messages
Browse files Browse the repository at this point in the history
  • Loading branch information
eaidova committed Jan 15, 2024
1 parent 7006264 commit 2fb9032
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
4 changes: 3 additions & 1 deletion optimum/exporters/openvino/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ class StoreAttr(object):

synonyms_for_task = TasksManager.synonyms_for_task(task)
synonyms_for_task.add(task)
if stateful and not ensure_export_task_support_stateful(task):

task_support_stateful = ensure_export_task_support_stateful(task)
if stateful and not task_support_stateful:
stateful = False

preprocessors = maybe_load_preprocessors(
Expand Down
5 changes: 3 additions & 2 deletions optimum/exporters/openvino/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def export_pytorch(
`int4_sym_g64` - INT4 symmetric weights w/ group size 64, "int4_asym_g64" - as previous but asymmetric w/ zero-point.
compression_ratio (`Optional[float]`, defaults to `None`):
Compression ratio between primary and backup precision (only relevant to INT4).
stateful (`Optional[bool]`, defaults to `True`):
stateful (`Optional[bool]`, defaults to `False`):
Produce stateful model where all kv-cache inputs and outputs are hidden in the model and are not exposed as model inputs and outputs
Returns:
Expand Down Expand Up @@ -413,7 +413,8 @@ def ts_patched_forward(*args, **kwargs):
# cannot raise because stateful is enabled by default and it would break backward compatibility for models that couldn't convert to OV directly
# TODO: Implement stateful for ONNX path as well, not doing it right now because of lack of validation
logger.warn(
"[ WARNING ] Making stateful models is not supported when exporting to ONNX as an intermediate step. A stateless model will be exported instead. It may result in sub-optimal inference performance."
"[ WARNING ] Making stateful models is not supported when exporting to ONNX as an intermediate step. "
"A stateless model will be exported instead. It may result in sub-optimal inference performance."
"Provide a model that can be converted to OpenVINO without fallback to ONNX conversion path."
)
return export_pytorch_via_onnx(
Expand Down
3 changes: 2 additions & 1 deletion optimum/exporters/openvino/stateful.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ def ensure_stateful_is_available(warn=True):
if is_openvino_version("<", "2023.3"):
if warn:
log.warn(
f"Could not create or use stateful model when using old version of openvino=={_openvino_version}. Install openvino>=2023.3.0."
f"Could not create or use stateful model when using old version of openvino=={_openvino_version}. It may result in sub-optimal inference performance."
"Install openvino>=2023.3.0."
)
return False
return True
Expand Down
9 changes: 8 additions & 1 deletion optimum/intel/openvino/modeling_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,16 @@ def __init__(
self.update_pkv_precision()
if self.is_dynamic:
self.model = self._reshape(self.model, -1, -1)
is_stateful_supported = ensure_stateful_is_available(warn=False)

if self.use_cache and not self.stateful:
logger.warn(
"Provided model does not contain state. It may lead to sub-optimal performance."
"Please reexport model with updated OpenVINO version >= 2023.3.0 calling the `from_pretrained` method with original model "
"and `export=True` parameter"
)

if self.stateful:
is_stateful_supported = ensure_stateful_is_available()
if stateful is None:
stateful = is_stateful_supported
if model_has_sinks and not is_stateful_supported:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"onnxruntime<1.15.0",
"transformers>=4.34.0",
],
"openvino": ["openvino>=2023.2", "onnx", "onnxruntime", "transformers>=4.34.0"],
"openvino": ["openvino>=2023.2", "onnx", "onnxruntime", "transformers>=4.36.0", "optimum>=1.16.1"],
"nncf": ["nncf>=2.7.0"],
"ipex": ["transformers<4.32.0", "intel-extension-for-pytorch", "onnx"],
"diffusers": ["diffusers"],
Expand Down

0 comments on commit 2fb9032

Please sign in to comment.