Skip to content

Commit

Permalink
Support internlm 2.5 (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
pdx1989 authored Aug 22, 2024
1 parent 0545c9f commit 51ec61c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lmdeploy/pytorch/kernels/ascend/apply_rotary_pos_emb.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ def apply_rotary_pos_emb(
query_states_reshaped = query_states.reshape(1, bs, head, dim)
key_states_reshaped = key_states.reshape(1, bs, num_kv_heads, dim)
if not (hasattr(context, 'cos') or hasattr(context, 'sin')):
cos = cos[position_ids_1d].view(1, bs, 1, -1)
sin = sin[position_ids_1d].view(1, bs, 1, -1)
if len(cos.shape) == 3 and len(sin.shape) == 3:
cos = cos[:, position_ids_1d].view(1, bs, 1, -1)
sin = sin[:, position_ids_1d].view(1, bs, 1, -1)
elif len(cos.shape) == 2 and len(sin.shape) == 2:
cos = cos[position_ids_1d].view(1, bs, 1, -1)
sin = sin[position_ids_1d].view(1, bs, 1, -1)
else:
raise RuntimeError("Cannot handle cos/sin shape dims!")

if context:
setattr(context, 'cos', cos)
setattr(context, 'sin', sin)
Expand Down

0 comments on commit 51ec61c

Please sign in to comment.