Skip to content

Commit e07b38b

Browse files
committed
fix(ascend): fall back for unsupported RoPE dtype
1 parent 93c38ab commit e07b38b

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) 2026 BAAI. All rights reserved.
2+
3+
"""Tests for the Ascend rotary embedding implementation."""
4+
5+
import torch
6+
7+
from vllm_fl.dispatch.backends.reference.impl.rotary import rotary_embedding_torch
8+
from vllm_fl.dispatch.backends.vendor.ascend.impl.rotary import rotary_embedding_ascend
9+
10+
11+
def test_ascend_rotary_falls_back_for_float32():
12+
num_tokens = 4
13+
num_heads = 2
14+
head_size = 8
15+
16+
query = torch.randn(num_tokens, num_heads, head_size)
17+
key = torch.randn_like(query)
18+
positions = torch.arange(num_tokens)
19+
frequencies = torch.randn(16, head_size // 2)
20+
cos = frequencies.cos()
21+
sin = frequencies.sin()
22+
23+
actual_query, actual_key = rotary_embedding_ascend(
24+
None, query, key, cos, sin, positions, inplace=False
25+
)
26+
expected_query, expected_key = rotary_embedding_torch(
27+
None, query, key, cos, sin, positions, inplace=False
28+
)
29+
30+
torch.testing.assert_close(actual_query, expected_query)
31+
torch.testing.assert_close(actual_key, expected_key)

vllm_fl/dispatch/backends/vendor/ascend/impl/rotary.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@ def rotary_embedding_ascend(
3636
Returns:
3737
Tuple of (embedded_query, embedded_key)
3838
"""
39+
# The ATB rotary kernel used by torch-npu does not support FP32 inputs.
40+
# Launch failures are reported asynchronously and otherwise surface in a
41+
# later, unrelated operator. Keep the optimized path for model dtypes and
42+
# use the reference implementation for unsupported dtypes.
43+
if query.dtype not in (torch.float16, torch.bfloat16):
44+
from vllm_fl.dispatch.backends.reference.impl.rotary import (
45+
rotary_embedding_torch,
46+
)
47+
48+
return rotary_embedding_torch(
49+
obj,
50+
query,
51+
key,
52+
cos,
53+
sin,
54+
position_ids,
55+
rotary_interleaved=rotary_interleaved,
56+
inplace=inplace,
57+
)
58+
3959
import torch_npu
4060

4161
# query/key shape: [num_tokens, num_heads, rotary_dim]

0 commit comments

Comments
 (0)