{"record":{"id":"c318ac4eba0940fe","repo":"huggingface/transformers","slug":"an-error-occurred-while-trying-to-load-from-repo","errorCode":null,"errorMessage":"An error occurred while trying to load from '{repo_id}': {e}.","messagePattern":"An error occurred while trying to load from '(.+?)': (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/integrations/hub_kernels.py","lineNumber":647,"sourceCode":"    # extract the rev after the @ if it exists\n    repo_id, _, rev = repo_id.partition(\"@\")\n    repo_id = repo_id.strip()\n\n    # create revision xor version\n    rev = rev.strip() if rev else None\n    version = None\n    if rev is None:\n        # FA4 is still in beta -> redirect to v0 else default to v1\n        is_fa4 = is_flash_attention_requested(requested_attention_implementation=repo_id, version=4)\n        version = 0 if is_fa4 else 1\n\n    # Load the kernel from hub\n    try:\n        kernel = get_kernel(repo_id, revision=rev, version=version, allow_all_kernels=allow_all_kernels)\n    except ValueError:\n        raise\n    except Exception as e:\n        raise ValueError(f\"An error occurred while trying to load from '{repo_id}': {e}.\")\n\n    # correctly wrap the kernel\n    mask_implementation = \"flash_attention_2\"\n    if hasattr(kernel, \"flash_attn_varlen_func\"):\n        if attention_wrapper is None:\n            attention_wrapper = flash_attention_forward\n        kernel_function = attention_wrapper\n    elif hasattr(kernel, \"sparse_atten_func\"):\n        # Block-sparse kernels (e.g. `kernels-staging/msa`) expose `sparse_atten_func` instead of\n        # `flash_attn_varlen_func`; their call contract differs from the attention interface, so we\n        # bind the dedicated transformers-side wrapper that adapts the arguments and hides the\n        # prefill-kernel / decode-fallback dispatch.\n        from .msa_attention import msa_attention_forward\n\n        kernel_function = attention_wrapper if attention_wrapper is not None else msa_attention_forward\n        mask_implementation = \"sdpa\"\n    elif kernel_name is not None:\n        kernel_function = getattr(kernel, kernel_name)","sourceCodeStart":629,"sourceCodeEnd":665,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/integrations/hub_kernels.py#L629-L665","documentation":"After a hub kernel repo id is parsed, transformers calls `get_kernel(repo_id, revision, version, allow_all_kernels)` and wraps any non-ValueError failure into a ValueError with the repo id and the underlying exception text. This is a boundary error: the real cause (network failure, missing repo, auth, bad revision, unsigned kernel with allow_all_kernels=False) is in `{e}`.","triggerScenarios":"Requesting `attn_implementation=\"kernels-community/flash-attn\"` (or a custom `user/repo@rev`) where the repo does not exist, the revision is invalid, the Hub is unreachable, or the kernel is outside `kernels-community` and `allow_all_kernels` was not enabled — any of these makes `get_kernel_hub` raise, which is then re-wrapped here.","commonSituations":"Typos in repo ids; offline or firewalled environments; private/unverified kernel repos requiring `trust_remote_code`/`allow_all_kernels=True`; pinned revisions that were deleted.","solutions":["Read the embedded `{e}` text first — it names the actual transport/repo failure.","Verify the repo exists and the id/revision are exact: open `https://huggingface.co/<repo_id>` and check tags/commits for `@rev`.","For kernels outside `kernels-community`, pass `allow_all_kernels=True` (only for sources you trust).","Check network/credentials (`huggingface-cli login`, HF_ENDPOINT reachability) if `{e}` mentions connection or 401/403 errors."],"exampleFix":"# before\nmodel = AutoModelForCausalLM.from_pretrained(m, attn_implementation=\"kernels-community/flash-attn3@badrev\")\n# ValueError: An error occurred while trying to load from 'kernels-community/flash-attn3': ...\n\n# after\nmodel = AutoModelForCausalLM.from_pretrained(\n    m,\n    attn_implementation=\"kernels-community/flash-attn3\",  # valid repo/revision\n    allow_all_kernels=True,  # only for trusted non-community kernels\n)","handlingStrategy":"retry","validationCode":"from huggingface_hub import HfApi\napi = HfApi()\nassert api.repo_exists(repo_id), f\"kernel repo {repo_id} does not exist\"\nif rev:\n    assert any(r == rev for r in [c.commit_id for c in api.list_repo_commits(repo_id)]) or rev in api.list_repo_refs(repo_id).convert(), \"bad revision\"","typeGuard":null,"tryCatchPattern":"import time\nfor attempt in range(3):\n    try:\n        model = load_with_kernel_attn(repo_id)\n        break\n    except ValueError as e:\n        msg = str(e)\n        if \"An error occurred while trying to load\" not in msg:\n            raise\n        inner = msg.split(\":\", 1)[1]\n        if any(s in inner for s in (\"Connection\", \"timed out\", \"401\", \"403\", \"404\")) and attempt < 2:\n            time.sleep(2 ** attempt)\n            continue\n        raise","preventionTips":["Validate repo ids and revisions against the Hub before first use.","Pass allow_all_kernels=True only for kernel repos you control or audit.","Log the inner exception text — it carries the real cause (network, auth, missing repo)."],"tags":["huggingface-hub","kernels","network","repo-not-found","wrapped-error"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}