{"record":{"id":"04dc7206b0c4ec68","repo":"sgl-project/sglang","slug":"weight-name-weight-name-r-matches-multiple-files","errorCode":null,"errorMessage":"Weight name {weight_name!r} matches multiple files: {list(basename_matches)}","messagePattern":"Weight name (.+?) matches multiple files: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/weights/source.py","lineNumber":234,"sourceCode":"    return WeightInventory(\n        source=source,\n        resolved_revision=model_info.sha,\n        files=_filter_inventory_files(files, source),\n    )\n\n\ndef _select_named_file(candidates: tuple[str, ...], weight_name: str) -> str:\n    exact = tuple(path for path in candidates if path == weight_name)\n    if exact:\n        return exact[0]\n    basename_matches = tuple(\n        path for path in candidates if PurePosixPath(path).name == weight_name\n    )\n    if len(basename_matches) == 1:\n        return basename_matches[0]\n    if not basename_matches:\n        raise FileNotFoundError(f\"Requested weight {weight_name!r} was not found\")\n    raise ValueError(\n        f\"Weight name {weight_name!r} matches multiple files: \"\n        f\"{list(basename_matches)}\"\n    )\n\n\ndef select_weight_file(\n    inventory: WeightInventory, weight_name: str | None = None\n) -> str:\n    \"\"\"Select weights deterministically; never guess among independent files.\"\"\"\n    candidates = tuple(\n        path for path in inventory.files if path.lower().endswith(_WEIGHT_SUFFIXES)\n    )\n    if inventory.source.filename is not None:\n        return inventory.files[0]\n    if weight_name is not None:\n        return _select_named_file(candidates, weight_name)\n    if len(candidates) == 1:\n        return candidates[0]","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/weights/source.py#L216-L252","documentation":"The given weight_name matches more than one candidate file by basename (files in different subfolders sharing a name), so selection is ambiguous and the library refuses to guess.","triggerScenarios":"A repo contains e.g. 'transformer/model.safetensors' and 'vae/model.safetensors' and the caller asks for weight_name='model.safetensors'.","commonSituations":"Multi-component diffusion checkpoints where several subfolders each contain a same-named shard.","solutions":["Select by exact file URL including the subfolder path","Narrow the source to the subfolder (owner/repo/subfolder) before selecting","Pass the full relative path if the API accepts it"],"exampleFix":"# before\nresolve_weight(\"org/repo\", weight_name=\"model.safetensors\")\n# after\nresolve_weight(\"org/repo/transformer/resolve/main/model.safetensors\")","handlingStrategy":"validation","validationCode":"from pathlib import PurePosixPath\nmatches = [f for f in inv.files if PurePosixPath(f).name == weight_name]\nif len(matches) != 1:\n    raise SystemExit(f\"ambiguous or missing {weight_name}: {matches}\")","typeGuard":null,"tryCatchPattern":"try:\n    f = select_weight_file(inv, weight_name)\nexcept ValueError as e:\n    # disambiguate with an exact URL built from matches\n    raise","preventionTips":["Prefer exact file URLs for repos with same-named files in multiple subfolders","Check basename uniqueness before calling"],"tags":["weights","ambiguous-selection"],"backgroundTag":"ambiguous-file-selection","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}