From 80e5812b39bd3b19efa8a6af65658f599bd6cae0 Mon Sep 17 00:00:00 2001 From: GoCHug <93277779+GoCHug@users.noreply.github.com> Date: Mon, 9 Feb 2026 17:17:52 +0800 Subject: [PATCH] [BugFix] Add support for rotary_dim parameter when using partial rope in rotary_embedding (#6581) ### What this PR does / why we need it? Issue: If a model such as Ling-1T adopts partial rotary position embedding (partial RoPE), but config.json uses the rotary_dim parameter instead of partial_rotary_factor, it will trigger a RuntimeError: The expanded size of the tensor (128) must match the existing size (64) at non-singleton dimension 3. image This PR addresses an issue where models using partial rotary position embedding (partial RoPE) with the `rotary_dim` parameter in `config.json` (instead of `partial_rotary_factor`) would encounter a `RuntimeError`. This change adds support for the `rotary_dim` parameter in `vllm_ascend/ops/rotary_embedding.py` to correctly calculate the `rope_dim`, resolving the tensor size mismatch error. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? The patch was tested successfully with the Ling-1T model, which previously triggered the error. - vLLM version: v0.15.0 - vLLM main: https://github.com/vllm-project/vllm/commit/d7e17aaacd5ed1b4b4be6bcfef3a1b7cbc84fc9a Signed-off-by: GoCHug <93277779+GoCHug@users.noreply.github.com> --- vllm_ascend/ops/rotary_embedding.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vllm_ascend/ops/rotary_embedding.py b/vllm_ascend/ops/rotary_embedding.py index cb7538d5..15bda163 100644 --- a/vllm_ascend/ops/rotary_embedding.py +++ b/vllm_ascend/ops/rotary_embedding.py @@ -76,6 +76,8 @@ def set_cos_and_sin(vllm_config, max_num_reqs, decode_token_per_req, dtype, devi # For models using partial rope like Qwen3-Next. if hasattr(model_config.hf_text_config, "partial_rotary_factor"): rope_dim = int(rope_dim * model_config.hf_text_config.partial_rotary_factor) + elif hasattr(model_config.hf_text_config, "rotary_dim"): + rope_dim = int(model_config.hf_text_config.rotary_dim) _cos = torch.ones(1, max_num_batched_tokens, 1, rope_dim, dtype=dtype, device=device) _sin = torch.zeros(1, max_num_batched_tokens, 1, rope_dim, dtype=dtype, device=device)