sgl-project/sglang · error · AttributeError
module {__name__!r} has no attribute {name!r}
Error message
module {__name__!r} has no attribute {name!r} What it means
This module uses a lazy attribute hook: only FlashAttentionForwardSm90 is importable on demand; any other attribute access on the module raises AttributeError. This avoids importing the heavy Sm90 kernel (and its CUTLASS DSL compilation machinery) unless actually needed.
Source
Thrown at python/sglang/kernels/ops/attention/flash_attn/cute/flash_fwd.py:1538
self.score_vec_size,
self.qk_acc_dtype,
aux_data,
fastdiv_mods,
seqlen_info=seqlen,
constant_q_idx=None,
qhead_per_kvhead=self.qhead_per_kvhead if const_expr(self.pack_gqa) else 1,
)
# SM90 forward pass moved to flash_fwd_sm90.py; re-export for backward compatibility
def __getattr__(name):
if name == "FlashAttentionForwardSm90":
from sglang.kernels.ops.attention.flash_attn.cute.flash_fwd_sm90 import (
FlashAttentionForwardSm90,
)
return FlashAttentionForwardSm90
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
View on GitHub (pinned to 0132848349)
Solutions
- Import the correct symbol: from sglang.kernels.ops.attention.flash_attn.cute.flash_fwd_sm90 import FlashAttentionForwardSm90, or getattr(module, 'FlashAttentionForwardSm90')
- Find the new home of the moved symbol with grep in python/sglang/kernels/ops/attention/flash_attn/cute/
- Update mock.patch targets to the defining module, not this lazy facade
Example fix
// before from sglang.kernels.ops.attention.flash_attn.cute.flash_fwd import FlashAttentionForward // after from sglang.kernels.ops.attention.flash_attn.cute.flash_fwd import FlashAttentionForwardSm90
Defensive patterns
Strategy: try-catch
Validate before calling
ALLOWED = ('FlashAttentionForwardSm90',)
if name not in ALLOWED:
raise ImportError(f'{name} is not exported by flash_fwd; allowed: {ALLOWED}') Type guard
def has_attr(mod, name) -> bool:
return name == 'FlashAttentionForwardSm90' Try / catch
try:
cls = getattr(flash_fwd_module, name)
except AttributeError:
raise ImportError(f'{name} moved; import from flash_fwd_sm90 directly') from None Prevention
- Import symbols from their defining module (flash_fwd_sm90), not the lazy facade
- After file splits, grep for old import paths before assuming they work
- Pin mock.patch targets to defining modules
When it happens
Trigger: Doing from ...flash_fwd import FlashAttentionForward or accessing any name other than FlashAttentionForwardSm90 on the module, e.g. via importlib, getattr(module, name), or tab-completion-driven code. Also triggered by tools like mock.patch('...flash_fwd.Something') or hasattr probes.
Common situations: Refactoring imports after a file split where older names lived in this module; test frameworks patching module attributes; static-analysis or dynamic-import code enumerating module members.
Related errors
- could not create an import spec for {module_name} at {path}
- module {__name__!r} has no attribute {name!r}
- Expected a string in the format `<module>:<class>`
- Please install diso via `pip install diso`, or set mc_algo t
- Unsupported mc_algo {mc_algo}, available: {list(SurfaceExtra
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/dd5be80236f24cbf.
Report an issue: GitHub.