Skip to content

Commit a11acd8

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

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

optimum/exporters/openvino/model_patcher.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1587,8 +1587,13 @@ 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 (
1593+
is_torch_version(">=", "2.1.0")
1594+
and is_transformers_version("<", "4.48.0")
1595+
or not getattr(self._model, "_supports_sdpa", False)
1596+
):
15921597
orig_self_attn_fwd = layer.self_attn.forward
15931598
layer.self_attn.forward = types.MethodType(_phi3_self_attn_sdpa_forward, layer.self_attn)
15941599
layer.self_attn._orig_forward = orig_self_attn_fwd

0 commit comments

Comments
 (0)