From a11acd8112a51c6bf6a4db4958c9f1deeed5fb20 Mon Sep 17 00:00:00 2001 From: eaidova Date: Thu, 6 Feb 2025 15:50:26 +0400 Subject: [PATCH] fix export phi3 with --trust-remote-code --- optimum/exporters/openvino/model_patcher.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/optimum/exporters/openvino/model_patcher.py b/optimum/exporters/openvino/model_patcher.py index df4b017b67..b524f91485 100644 --- a/optimum/exporters/openvino/model_patcher.py +++ b/optimum/exporters/openvino/model_patcher.py @@ -1587,8 +1587,13 @@ def __enter__(self): # https://github.com/huggingface/transformers/blob/30ee508c6c92a1c0aa0281d193c7c0fb815b8d2f/src/transformers/models/phi3/modeling_phi3.py#L113 # init inv_freq for torchscript tracing + # 4.48 transformers version phi3 fixed, but issue still visible with trust_remote_true=True (trust_remote_code has _support_sdpa = False) for layer in self._model.model.layers: - if is_torch_version(">=", "2.1.0") and is_transformers_version("<", "4.48.0"): + if ( + is_torch_version(">=", "2.1.0") + and is_transformers_version("<", "4.48.0") + or not getattr(self._model, "_supports_sdpa", False) + ): orig_self_attn_fwd = layer.self_attn.forward layer.self_attn.forward = types.MethodType(_phi3_self_attn_sdpa_forward, layer.self_attn) layer.self_attn._orig_forward = orig_self_attn_fwd