Skip to content

Commit 51ec61c

Browse files
authored
Support internlm 2.5 (#14)
1 parent 0545c9f commit 51ec61c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lmdeploy/pytorch/kernels/ascend/apply_rotary_pos_emb.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ def apply_rotary_pos_emb(
1919
query_states_reshaped = query_states.reshape(1, bs, head, dim)
2020
key_states_reshaped = key_states.reshape(1, bs, num_kv_heads, dim)
2121
if not (hasattr(context, 'cos') or hasattr(context, 'sin')):
22-
cos = cos[position_ids_1d].view(1, bs, 1, -1)
23-
sin = sin[position_ids_1d].view(1, bs, 1, -1)
22+
if len(cos.shape) == 3 and len(sin.shape) == 3:
23+
cos = cos[:, position_ids_1d].view(1, bs, 1, -1)
24+
sin = sin[:, position_ids_1d].view(1, bs, 1, -1)
25+
elif len(cos.shape) == 2 and len(sin.shape) == 2:
26+
cos = cos[position_ids_1d].view(1, bs, 1, -1)
27+
sin = sin[position_ids_1d].view(1, bs, 1, -1)
28+
else:
29+
raise RuntimeError("Cannot handle cos/sin shape dims!")
30+
2431
if context:
2532
setattr(context, 'cos', cos)
2633
setattr(context, 'sin', sin)

0 commit comments

Comments
 (0)