{"record":{"id":"e8394b6c0ebc5f26","repo":"sgl-project/sglang","slug":"unknown-shard-id-shard-id-e8394b","errorCode":null,"errorMessage":"Unknown Shard Id {shard_id}","messagePattern":"Unknown Shard Id (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/layers/linear.py","lineNumber":121,"sourceCode":"    quantized_offset = orig_offset * quantized_total // total\n    quantized_size = orig_size * quantized_total // total\n\n    return quantized_size, quantized_offset\n\n\ndef adjust_scalar_to_fused_array(param, loaded_weight, shard_id):\n    \"\"\"For fused modules (QKV and MLP) we have an array of length\n    N that holds 1 scale for each \"logical\" matrix. So the param\n    is an array of length N. The loaded_weight corresponds to\n    one of the shards on disk. Here, we slice the param based on\n    the shard_id for loading.\n    \"\"\"\n    qkv_idxs = {\"q\": 0, \"k\": 1, \"v\": 2}\n\n    if isinstance(shard_id, str):\n        shard_id = qkv_idxs[shard_id]\n    elif not isinstance(shard_id, int):\n        raise ValueError(f\"Unknown Shard Id {shard_id}\")\n\n    # AutoFP8 scales do not have a shape\n    # compressed-tensors scales do have a shape\n    if len(loaded_weight.shape) != 0:\n        assert loaded_weight.shape[0] == 1\n        loaded_weight = loaded_weight[0]\n\n    return param[shard_id], loaded_weight\n\n\ndef adjust_shard_offsets(shard_offsets, loaded_weight, dim):\n    actual_weight_size = loaded_weight.size(dim)\n    target_weight_size = shard_offsets[-1][-1] + shard_offsets[-1][-2]\n    if actual_weight_size != target_weight_size:\n        new_shard_offsets = []\n        new_offset = 0\n        for shard_id, shard_offset, shard_size in shard_offsets:\n            actual_shard_size = actual_weight_size * shard_size // target_weight_size","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/layers/linear.py#L103-L139","documentation":"adjust_scalar_to_fused_array broadcasts a scalar quant scale into a fused QKV scale array; it maps shard_id 'q'/'k'/'v' (or 0/1/2) to the output slot. Any shard_id that is neither a string key in qkv_idxs nor an int raises ValueError('Unknown Shard Id ...').","triggerScenarios":"Calling weight_loader for a fused QKV quant scale with loaded_shard_id of an unexpected type/value, e.g. a model implementation passing a tuple, an Enum, or a shard name like 'gate'/'up'/'o' instead of 'q'/'k'/'v' or 0/1/2.","commonSituations":"New model architectures reusing MergedColumnParallelLinear-style scale loading for non-QKV fused layers (gate/up projections); refactors changing shard_id to a tuple, which this v1 path does not support.","solutions":["Pass shard_id as 'q', 'k', 'v' or int 0/1/2","For non-QKV fused layers (gate/up), use a weight_loader path that handles those shard ids or weight_loader_v2","If shard_id is a tuple, route to weight_loader_v2 as the code itself suggests"],"exampleFix":"# before\nlinear.weight_loader(param, scale, loaded_shard_id=(\"q\", 0))\n\n# after\nlinear.weight_loader(param, scale, loaded_shard_id=\"q\")","handlingStrategy":"type-guard","validationCode":"valid = {\"q\", \"k\", \"v\", 0, 1, 2}\nassert loaded_shard_id in valid, f\"bad shard_id {loaded_shard_id!r}; expected q/k/v or 0/1/2\"\nlinear.weight_loader(param, loaded_weight, loaded_shard_id)","typeGuard":"def is_valid_qkv_shard_id(sid) -> bool:\n    return sid in (\"q\", \"k\", \"v\") or (isinstance(sid, int) and not isinstance(sid, bool) and 0 <= sid <= 2)","tryCatchPattern":"try:\n    linear.weight_loader(param, loaded_weight, loaded_shard_id=sid)\nexcept ValueError as e:\n    if \"Unknown Shard Id\" in str(e):\n        sid = {\"gate\": 0, \"up\": 1}.get(sid, sid)  # map or fix upstream\n        linear.weight_loader_v2(param, loaded_weight, loaded_shard_id=sid)\n    else:\n        raise","preventionTips":["Use only 'q'/'k'/'v' or 0/1/2 with the v1 scale loader","For gate/up fused layers use weight_loader_v2","Type-check shard_id in model weight-loading tests"],"tags":["weight-loading","shard-id","qkv-fusion","quant-scale"],"backgroundTag":"invalid-argument-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}