{"record":{"id":"bdb93c41f39d6457","repo":"hiyouga/LlamaFactory","slug":"flash-linear-attention-and-fsdpturbo-are-required","errorCode":null,"errorMessage":"Flash Linear Attention and FSDPTurbo are required for this kernel.","messagePattern":"Flash Linear Attention and FSDPTurbo are required for this kernel\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/v1/plugins/model_plugins/kernels/ops/linear_attention/fla.py","lineNumber":58,"sourceCode":"@KernelPlugin(\"flash-linear-attention\").register()\nclass FlashLinearAttentionKernel(BaseKernel):\n    \"\"\"Install selected FLA callables through FSDPTurbo's device operator registry.\"\"\"\n\n    @staticmethod\n    def check_device() -> None:\n        current = get_current_accelerator().type\n        if current not in (DeviceType.CUDA, DeviceType.NPU):\n            raise RuntimeError(f\"FlashLinearAttentionKernel requires CUDA or NPU, current accelerator is {current}.\")\n\n    @staticmethod\n    def check_deps() -> None:\n        try:\n            import fla.ops.gated_delta_rule  # noqa: F401\n            import fsdp_turbo.ops.fla  # noqa: F401\n            from fsdp_turbo.ops.registry import get_op  # noqa: F401\n            from fsdp_turbo.utils.patch import patch_model_members  # noqa: F401\n        except ImportError as exc:\n            raise RuntimeError(\"Flash Linear Attention and FSDPTurbo are required for this kernel.\") from exc\n\n    @staticmethod\n    def _apply(**kwargs) -> HFModel:\n        model = kwargs[\"model\"]\n        config = kwargs.get(\"config\") or {}\n        include_kernels = config.get(\"include_kernels\", \"auto\")\n        chunk_size = config.get(\"chunk_size\", 64)\n\n        if include_kernels == \"auto\" or include_kernels is True:\n            selected = list(FLASH_LINEAR_ATTENTION_KERNELS)\n        elif isinstance(include_kernels, str):\n            selected = [name.strip() for name in include_kernels.split(\",\") if name.strip()]\n        else:\n            raise TypeError(\"kernel_config.include_kernels must be 'auto' or a comma-separated string.\")\n\n        if not selected:\n            raise ValueError(\"kernel_config.include_kernels must select at least one FLA kernel.\")\n","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/v1/plugins/model_plugins/kernels/ops/linear_attention/fla.py#L40-L76","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"# before\n# missing deps, kernel_config.name: flash-linear-attention\n\n# after\npip install flash-linear-attention fsdp-turbo\npython -c \"import fsdp_turbo.ops.fla\"  # verify","handlingStrategy":"validation","validationCode":"import importlib.util\nrequired = ['fla.ops.gated_delta_rule', 'fsdp_turbo.ops.fla', 'fsdp_turbo.ops.registry', 'fsdp_turbo.utils.patch']\nmissing = [m for m in required if importlib.util.find_spec(m) is None]\nassert not missing, f'pip install flash-linear-attention fsdp-turbo (missing: {missing})'","typeGuard":"def fla_deps_installed() -> bool:\n    \"\"\"True when fla and fsdp_turbo modules the kernel needs are importable.\"\"\"\n    return not missing  # from validationCode's probe","tryCatchPattern":"try:\n    model = KernelPlugin('flash-linear-attention').apply(model=model)\nexcept RuntimeError as e:\n    if 'required for this kernel' in str(e) and e.__cause__ is not None:\n        raise SystemExit(f'pip install flash-linear-attention fsdp-turbo: {e.__cause__}') from None\n    raise","preventionTips":["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."],"tags":["kernels","fla","fsdp-turbo","dependencies","install"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}