Skip to content

Commit 070ffbc

Browse files
committed
fix inv_freq tracing based on latest changes in model
1 parent e0bb9ca commit 070ffbc

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

optimum/exporters/openvino/model_patcher.py

+13
Original file line numberDiff line numberDiff line change
@@ -623,3 +623,16 @@ def __init__(
623623
# model has first inference buffers initialization
624624
if hasattr(self._model.lm_head, "first_flag"):
625625
self._model(torch.ones((1, 10), dtype=torch.int64), torch.ones((1, 10), dtype=torch.int64))
626+
627+
628+
class Phi3ModelPatcher(DecoderModelPatcher):
629+
def __enter__(self):
630+
super().__enter__()
631+
632+
# init inv_freq for torchscript tracing
633+
for layer in self._model.model.layers:
634+
if layer.self_attn.rotary_emb.inv_freq is None:
635+
rotary_emb = layer.self_attn.rotary_emb
636+
layer.self_attn.rotary_emb.inv_freq = 1.0 / (
637+
rotary_emb.base ** (torch.arange(0, rotary_emb.dim, 2, dtype=torch.int64).float() / rotary_emb.dim)
638+
)

0 commit comments

Comments
 (0)