{"record":{"id":"5f7924baae94ec54","repo":"huggingface/transformers","slug":"invalid-hub-repo-hub-repo-r-for-layer-layer-nam","errorCode":null,"errorMessage":"Invalid hub repo {hub_repo!r} for layer {layer_name!r}","messagePattern":"Invalid hub repo (.+?) for layer (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/integrations/hub_kernels.py","lineNumber":877,"sourceCode":"\n    patch_mapping: dict[str, type] = {}\n    new_mapping: dict = {}\n\n    # We might need to instantiate the model on meta device.\n    # We do it lazily, only if we encounter a fused kernel.\n    meta_model = None\n\n    for layer_name, hub_repo in kernel_config.kernel_mapping.items():\n        if isinstance(hub_repo, (str, tuple)):\n            hub_repo = {None: hub_repo}\n\n        if isinstance(hub_repo, dict):\n            if len(hub_repo.values()) != 1:\n                raise ValueError(\n                    f\"Expected exactly one kernel repo regardless of device/mode specificity, got {hub_repo}\"\n                )\n        else:\n            raise ValueError(f\"Invalid hub repo {hub_repo!r} for layer {layer_name!r}\")\n\n        hub_repo = next(iter(hub_repo.values()))\n\n        # Infer metadata (revision/version/trust_remote_code)\n        if isinstance(hub_repo, tuple):\n            repo_str, metadata = hub_repo\n\n            revision = metadata.get(\"revision\", None)\n            version = metadata.get(\"version\", None)\n            trust_remote_code = metadata.get(\"trust_remote_code\", False) or ALLOW_ALL_KERNELS\n            metadata = {\"version\": version} if version is not None else {\"revision\": revision}\n            metadata |= {\"trust_remote_code\": trust_remote_code}\n\n            final_repo = (repo_str, metadata)\n        else:\n            repo_str = hub_repo\n            metadata = {\"version\": 1, \"trust_remote_code\": ALLOW_ALL_KERNELS}\n            final_repo = (repo_str, metadata)","sourceCodeStart":859,"sourceCodeEnd":895,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/integrations/hub_kernels.py#L859-L895","documentation":"Thrown by register_kernel_replacements_and_fusions while walking a KernelConfig's kernel_mapping: each value must be a string, a (repo_str, metadata) tuple, or a dict wrapping one of those. If the value is any other type after the str/tuple-to-dict normalization (so it failed the isinstance(dict) branch), this ValueError fires. It is a user-configuration validation error raised before any hub download is attempted.","triggerScenarios":"Calling model loading with a kernel config whose JSON kernel_mapping contains a value that is neither a string ('repo_id:layer_name'), a [repo, {metadata}] pair, nor an object with exactly one such entry — e.g. a number, boolean, null, list of strings, or a dict holding 2+ device-specific entries would first hit the sibling 'exactly one kernel repo' error; a plain list or None hits this one.","commonSituations":"Hand-editing a kernel JSON config and using a list of repos ['a:k', 'b:k'] instead of a single string; passing YAML null for a layer; schema drift between the kernel-catalog format the user copied from docs and the one this transformers version expects.","solutions":["Fix the kernel_mapping entry for the named layer to a single 'repo_id:layer_name' string (or a one-element dict / [repo, metadata] tuple).","Remove stale or duplicated device/mode-specific variants from that entry's dict so exactly one repo remains.","Regenerate or re-download the kernel config from its hub repo instead of hand-editing, then verify with json.load that each value is a str, [str, dict], or 1-entry object."],"exampleFix":"// before (kernel.json)\n{\"model.layers.*.self_attn.q_proj\": [\"a:b\", \"c:d\"]}\n\n// after\n{\"model.layers.*.self_attn.q_proj\": \"a:b\"}","handlingStrategy":"validation","validationCode":"def validate_kernel_mapping(mapping):\n    for layer, repo in mapping.items():\n        if isinstance(repo, (str, tuple)):\n            repo = {None: repo}\n        if not isinstance(repo, dict) or len(repo.values()) != 1:\n            raise ValueError(f\"bad kernel_mapping entry for {layer!r}: {repo!r}\")\n    return True","typeGuard":"def is_valid_hub_repo(repo) -> bool:\n    if isinstance(repo, (str, tuple)):\n        return True\n    return isinstance(repo, dict) and len(repo.values()) == 1 and all(\n        isinstance(v, (str, tuple)) for v in repo.values()\n    )","tryCatchPattern":"try:\n    register_kernel_replacements_and_fusions(model_cls, config, kernel_config)\nexcept ValueError as e:\n    if \"Invalid hub repo\" in str(e):\n        fix_and_revalidate(kernel_config)  # repair mapping before retry\n    else:\n        raise","preventionTips":["Treat kernel JSON configs as schema-validated data: run a small validator before model loading.","Prefer kernel catalogs pulled from the hub over hand-written mappings.","Keep mappings in version control and diff them when upgrading transformers."],"tags":["kernel-config","validation","hub-kernels"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}