hiyouga/LlamaFactory · error · RuntimeError
Flash Linear Attention and FSDPTurbo are required for this k
Error message
Flash Linear Attention and FSDPTurbo are required for this kernel.
What it means
FlashLinearAttentionKernel.check_deps() tries importing fla.ops.gated_delta_rule, fsdp_turbo.ops.fla, the fsdp_turbo op registry, and its patch helper. If any is missing it raises RuntimeError, chaining the original ImportError so the exact missing module is visible.
Source
Thrown at src/llamafactory/v1/plugins/model_plugins/kernels/ops/linear_attention/fla.py:58
@KernelPlugin("flash-linear-attention").register()
class FlashLinearAttentionKernel(BaseKernel):
"""Install selected FLA callables through FSDPTurbo's device operator registry."""
@staticmethod
def check_device() -> None:
current = get_current_accelerator().type
if current not in (DeviceType.CUDA, DeviceType.NPU):
raise RuntimeError(f"FlashLinearAttentionKernel requires CUDA or NPU, current accelerator is {current}.")
@staticmethod
def check_deps() -> None:
try:
import fla.ops.gated_delta_rule # noqa: F401
import fsdp_turbo.ops.fla # noqa: F401
from fsdp_turbo.ops.registry import get_op # noqa: F401
from fsdp_turbo.utils.patch import patch_model_members # noqa: F401
except ImportError as exc:
raise RuntimeError("Flash Linear Attention and FSDPTurbo are required for this kernel.") from exc
@staticmethod
def _apply(**kwargs) -> HFModel:
model = kwargs["model"]
config = kwargs.get("config") or {}
include_kernels = config.get("include_kernels", "auto")
chunk_size = config.get("chunk_size", 64)
if include_kernels == "auto" or include_kernels is True:
selected = list(FLASH_LINEAR_ATTENTION_KERNELS)
elif isinstance(include_kernels, str):
selected = [name.strip() for name in include_kernels.split(",") if name.strip()]
else:
raise TypeError("kernel_config.include_kernels must be 'auto' or a comma-separated string.")
if not selected:
raise ValueError("kernel_config.include_kernels must select at least one FLA kernel.")
View on GitHub (pinned to f28afaf635)
Solutions
- Install both: `pip install flash-linear-attention fsdp-turbo`.
- Verify each import the check performs: `python -c "import fla.ops.gated_delta_rule, fsdp_turbo.ops.fla; from fsdp_turbo.ops.registry import get_op"`.
- Upgrade fsdp-turbo if the fla submodule is missing in your version.
- Remove the kernel from config if it was unintended.
Example fix
# before # missing deps, kernel_config.name: flash-linear-attention # after pip install flash-linear-attention fsdp-turbo python -c "import fsdp_turbo.ops.fla" # verify
Defensive patterns
Strategy: validation
Validate before calling
import importlib.util
required = ['fla.ops.gated_delta_rule', 'fsdp_turbo.ops.fla', 'fsdp_turbo.ops.registry', 'fsdp_turbo.utils.patch']
missing = [m for m in required if importlib.util.find_spec(m) is None]
assert not missing, f'pip install flash-linear-attention fsdp-turbo (missing: {missing})' Type guard
def fla_deps_installed() -> bool:
"""True when fla and fsdp_turbo modules the kernel needs are importable."""
return not missing # from validationCode's probe Try / catch
try:
model = KernelPlugin('flash-linear-attention').apply(model=model)
except RuntimeError as e:
if 'required for this kernel' in str(e) and e.__cause__ is not None:
raise SystemExit(f'pip install flash-linear-attention fsdp-turbo: {e.__cause__}') from None
raise Prevention
- Preflight-check optional kernel deps in a pretrain script.
- Pin fsdp-turbo to a version that ships fsdp_turbo.ops.fla.
- Group kernel selections with their dependency installs in environment files.
When it happens
Trigger: Selecting 'flash-linear-attention' without installing both optional packages flash-linear-attention and fsdp-turbo (or with incompatible versions where fsdp_turbo.ops.fla is absent).
Common situations: Optional-extras not installed in the base env; pip resolving an old fsdp-turbo without the fla ops module; reinstalling the env without kernel extras.
Related errors
- Liger kernel is not installed.
- FlashLinearAttentionKernel requires CUDA or NPU, current acc
- The installed Transformers-KT does not provide `TrainingArgu
- The installed Transformers-KT does not provide `configure_kt
- HFModel instance is required for {cls.__name__}.
AI-assisted analysis of hiyouga/LlamaFactory@f28afaf635 (2026-08-14).
Data as JSON: /api/errors/bdb93c41f39d6457.
Report an issue: GitHub.