From 1f60771c744811e027f1309b9093cded7521d953 Mon Sep 17 00:00:00 2001 From: Yufeng He <40085740+he-yufeng@users.noreply.github.com> Date: Thu, 11 Jun 2026 20:43:31 +0800 Subject: [PATCH] fix: guard flash-attn rotary import (#42679) Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com> Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com> --- .../model_executor/layers/rotary_embedding/common.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/vllm/model_executor/layers/rotary_embedding/common.py b/vllm/model_executor/layers/rotary_embedding/common.py index 7d7d4907cec..17cf66b0257 100644 --- a/vllm/model_executor/layers/rotary_embedding/common.py +++ b/vllm/model_executor/layers/rotary_embedding/common.py @@ -2,7 +2,8 @@ # SPDX-FileCopyrightText: Copyright contributors to the vLLM project import math -from importlib.util import find_spec +from contextlib import suppress +from importlib import import_module import torch @@ -135,10 +136,11 @@ class ApplyRotaryEmb(CustomOp): self.enable_fp32_compute = enable_fp32_compute self.apply_rotary_emb_flash_attn = None - if not current_platform.is_cpu() and find_spec("flash_attn") is not None: - from flash_attn.ops.triton.rotary import apply_rotary - - self.apply_rotary_emb_flash_attn = apply_rotary + if not current_platform.is_cpu(): + with suppress(ModuleNotFoundError): + self.apply_rotary_emb_flash_attn = import_module( + "flash_attn.ops.triton.rotary" + ).apply_rotary @staticmethod def forward_static(