Skip to content

[Bugfix]: Correct handling of cos_sin_cache length #1900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions tests/ut/ops/test_rotary_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,12 @@ def test_native_rope_deepseek_forward_cache_handling(

mock_rope_forward_oot.return_value = (query, key)

q_pe, k_pe = native_rope_deepseek_forward(module,
positions,
query,
key,
max_seq_len=2048)

assert q_pe.shape == query.shape
assert k_pe.shape == key.shape
with self.assertRaises(ValueError):
native_rope_deepseek_forward(module,
positions,
query,
key,
max_seq_len=2048)

@patch('vllm_ascend.ops.rotary_embedding.rope_forward_oot')
def test_native_rope_deepseek_forward_key_reshaping(
Expand Down
7 changes: 4 additions & 3 deletions vllm_ascend/ops/rotary_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def native_rope_deepseek_forward(self,
offsets: Optional[torch.Tensor] = None,
max_seq_len: Optional[int] = None):
if max_seq_len is not None and max_seq_len > self.max_seq_len:
_set_cos_sin_cache(self, max_seq_len, query.device, query.dtype)
raise ValueError(f"Unable to reach here, max_seq_len {max_seq_len} "
"exceeds the maximum sequence length "
f"{self.max_seq_len} for rotary embedding.")
if len(key.shape) == 2:
key = key[:, None, :]
# Note: we implement the non neox_style method with shuffle the last dim and neox style
Expand Down Expand Up @@ -209,7 +211,7 @@ def apply_rotary_pos_emb(q, k, cos, sin, position_ids, unsqueeze_dim=1):


def _set_cos_sin_cache(self, seq_len, device, dtype):
self.max_seq_len_cached = seq_len
self.max_seq_len = seq_len * self.scaling_factor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no problem in v0.9.1. what happens.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1551 fixed this problem in v0.9.1-dev

dim = self.rotary_dim

freq_extra = 1.0 / (self.base**(
Expand Down Expand Up @@ -276,7 +278,6 @@ def deepseek_rope_init_func(
super(DeepseekScalingRotaryEmbedding,
self).__init__(head_size, rotary_dim, max_position_embeddings, base,
is_neox_style, dtype)
self.max_seq_len = max_position_embeddings
_set_cos_sin_cache(self,
max_position_embeddings,
dtype=dtype,
Expand Down
Loading