{"record":{"id":"be3464a0c601fd9f","repo":"hiyouga/LlamaFactory","slug":"flashlinearattentionkernel-requires-cuda-or-npu-c","errorCode":null,"errorMessage":"FlashLinearAttentionKernel requires CUDA or NPU, current accelerator is {current}.","messagePattern":"FlashLinearAttentionKernel requires CUDA or NPU, current accelerator is (.+?)\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/v1/plugins/model_plugins/kernels/ops/linear_attention/fla.py","lineNumber":48,"sourceCode":"    CHUNK_GATED_DELTA_RULE,\n    FUSED_RECURRENT_GATED_DELTA_RULE,\n)\nFLA_MODULE_ATTRIBUTES = {\n    CHUNK_GATED_DELTA_RULE: \"chunk_gated_delta_rule\",\n    FUSED_RECURRENT_GATED_DELTA_RULE: \"recurrent_gated_delta_rule\",\n}\nSUPPORTED_CHUNK_SIZES = (16, 32, 64)\n\n\n@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","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/v1/plugins/model_plugins/kernels/ops/linear_attention/fla.py#L30-L66","documentation":"FlashLinearAttentionKernel.check_device() restricts the FLA kernel to CUDA or NPU, mirroring the Liger gate. On CPU/XPU/MPS or a misdetected accelerator it raises RuntimeError with the current device type.","triggerScenarios":"kernel_config.name includes 'flash-linear-attention' while the detected accelerator type is not CUDA/NPU — e.g. CPU dev runs, MPS, or NPU setups where torch_npu failed to init so the type fell back to CPU.","commonSituations":"Shared training YAMLs run across heterogeneous nodes; linear-attention (gated delta rule) models configured globally; NPU images missing proper accelerator initialization.","solutions":["Run on a CUDA/NPU node for FLA kernels.","Drop 'flash-linear-attention' from kernel_config.name on other devices, or use \"auto\" selection which filters by device_type.","On NPU, verify torch_npu is imported and the accelerator registers as NPU before training."],"exampleFix":"# before\nname: \"flash-linear-attention\"  # on CPU runner\n\n# after\nname: \"auto\"  # device-appropriate kernels only","handlingStrategy":"validation","validationCode":"from llamafactory.v1.core.accelerator import get_current_accelerator\nt = get_current_accelerator().type\nassert t in ('cuda', 'npu'), f'FLA kernel needs CUDA/NPU, got {t}'","typeGuard":"def fla_supported() -> bool:\n    \"\"\"True on CUDA or NPU accelerators.\"\"\"\n    return get_current_accelerator().type in (DeviceType.CUDA, DeviceType.NPU)","tryCatchPattern":"try:\n    model = KernelPlugin('flash-linear-attention').apply(model=model)\nexcept RuntimeError as e:\n    if 'requires CUDA or NPU' in str(e):\n        logger.warning('skipping FLA kernel on %s', get_current_accelerator().type)\n    else:\n        raise","preventionTips":["Device-gate kernel names per node in orchestration.","Use 'auto' selection for portable configs.","Verify NPU detection (torch_npu) before assuming NPU support."],"tags":["kernels","device","fla","hardware"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}