Skip to content

Commit

Permalink
force precision using --weight-format
Browse files Browse the repository at this point in the history
  • Loading branch information
eaidova committed Jul 29, 2024
1 parent 0791c4c commit 8625e36
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions optimum/exporters/openvino/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,11 @@ def main_export(
and task.startswith("text-generation")
and getattr(config, "torch_dtype", torch.float32) in [torch.float16, torch.bfloat16]
):
if is_openvino_version(">=", "2024.2") and config.torch_dtype == torch.float16:
if ov_config is not None and ov_config.dtype in {"fp16", "fp32"}:
dtype = torch.float16 if ov_config.dtype == "fp16" else torch.float32
elif is_openvino_version(">=", "2024.2") and config.torch_dtype == torch.float16:
dtype = torch.float16
if is_openvino_version(">=", "2024.3") and config.torch_dtype == torch.bfloat16:
elif is_openvino_version(">=", "2024.3") and config.torch_dtype == torch.bfloat16:
dtype = torch.bfloat16

if dtype is not None:
Expand Down
2 changes: 1 addition & 1 deletion optimum/intel/openvino/modeling_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def _from_transformers(
if load_in_8bit is None and not quantization_config:
ov_export_config = None
else:
ov_export_config = OVConfig(dtype="fp32")
ov_export_config = OVConfig(dtype="auto")

stateful = kwargs.pop("stateful", ensure_stateful_is_available(warn=False) and use_cache)

Expand Down

0 comments on commit 8625e36

Please sign in to comment.