{"record":{"id":"eedb0ceb605a1062","repo":"sgl-project/sglang","slug":"kernelspec-target-must-be-module-attr-got-self","errorCode":null,"errorMessage":"KernelSpec.target must be 'module:attr', got {self.target!r}","messagePattern":"KernelSpec\\.target must be 'module:attr', got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/spec.py","lineNumber":258,"sourceCode":"\n    @property\n    def name(self) -> str:\n        return self.op.split(\".\", 1)[1] if \".\" in self.op else self.op\n\n    def is_available(self, platform: PlatformInfo) -> bool:\n        \"\"\"Whether this backend can run on ``platform`` (metadata-only check).\"\"\"\n        return capabilities_satisfied(self.capabilities, platform)\n\n    def load(self) -> Callable:\n        \"\"\"Import and return the backing callable.\n\n        Raises the underlying ``ImportError`` / ``AttributeError`` if the\n        backend is not installed on this platform — call sites decide how to\n        handle that.\n        \"\"\"\n        module_path, sep, attr = self.target.partition(\":\")\n        if not sep or not attr:\n            raise ValueError(\n                f\"KernelSpec.target must be 'module:attr', got {self.target!r}\"\n            )\n        obj = importlib.import_module(module_path)\n        for part in attr.split(\".\"):\n            obj = getattr(obj, part)\n        return obj\n","sourceCodeStart":240,"sourceCodeEnd":265,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/spec.py#L240-L265","documentation":"KernelSpec.load() parses the spec's target string as 'module.path:attr.path' using partition(':'). If the target has no colon or nothing after it, the format is invalid and this ValueError is raised before any import is attempted. This is an authoring bug in the KernelSpec, not a runtime environment issue.","triggerScenarios":"Registering a KernelSpec with target='mymodule.my_kernel' (missing ':attr') or target='mymodule:' (empty attr); triggered when _resolve() -> load() runs for that op.","commonSituations":"Hand-writing kernel registrations or porting specs from another format; copy-paste errors that drop the colon; typos in the attr half.","solutions":["Fix the target string to the exact 'module:attr' form, e.g. 'sglang.srt.layers.moe.fused_moe_triton:fused_experts'.","For nested attributes use dotted attr path: 'pkg.mod:obj.method'.","Add a unit test asserting each registered spec parses (call load() or partition check) at registration time."],"exampleFix":"# before\nKernelSpec(target=\"sglang.srt.layers.mykernel\")\n\n# after\nKernelSpec(target=\"sglang.srt.layers.mykernel:my_kernel_fn\")","handlingStrategy":"validation","validationCode":"def valid_target(t: str) -> bool:\n    mod, sep, attr = t.partition(\":\")\n    return bool(sep and mod and attr)\n\nassert valid_target(spec.target), f\"bad target {spec.target!r}\"","typeGuard":"def is_valid_target(target: object) -> bool:\n    if not isinstance(target, str):\n        return False\n    mod, sep, attr = target.partition(\":\")\n    return bool(sep and mod and attr and all(part.isidentifier() for part in attr.split(\".\")))","tryCatchPattern":"try:\n    fn = spec.load()\nexcept ValueError as e:\n    raise RuntimeError(f\"Misconfigured KernelSpec {spec!r}: fix target format\") from e","preventionTips":["Unit-test that every registered spec's target parses and imports.","Keep target strings next to their kernel modules and construct them programmatically."],"tags":["kernels","spec-validation","configuration","sglang"],"backgroundTag":"invalid-spec-target-format","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}