Skip to content

Commit 65f52a7

Browse files
committed
fix export phi3 with --trust-remote-code
1 parent f601b8b commit 65f52a7

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

optimum/exporters/openvino/model_patcher.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1587,8 +1587,9 @@ def __enter__(self):
15871587

15881588
# https://github.com/huggingface/transformers/blob/30ee508c6c92a1c0aa0281d193c7c0fb815b8d2f/src/transformers/models/phi3/modeling_phi3.py#L113
15891589
# init inv_freq for torchscript tracing
1590+
# 4.48 transformers version phi3 fixed, but issue still visible with trust_remote_true=True (trust_remote_code has _support_sdpa = False)
15901591
for layer in self._model.model.layers:
1591-
if is_torch_version(">=", "2.1.0") and is_transformers_version("<", "4.48.0"):
1592+
if is_torch_version(">=", "2.1.0") and is_transformers_version("<", "4.48.0") or not getattr(self._model, "_supports_sdpa", False):
15921593
orig_self_attn_fwd = layer.self_attn.forward
15931594
layer.self_attn.forward = types.MethodType(_phi3_self_attn_sdpa_forward, layer.self_attn)
15941595
layer.self_attn._orig_forward = orig_self_attn_fwd

0 commit comments

Comments
 (0)