{"record":{"id":"711fd8fb2af03628","repo":"sgl-project/sglang","slug":"expert-pack-is-not-identity-triplet-layout","errorCode":null,"errorMessage":"expert-pack is not identity triplet layout","messagePattern":"expert-pack is not identity triplet layout","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"python/sglang/srt/layers/moe/expert_pack.py","lineNumber":94,"sourceCode":"            raise ValueError(\"expert-pack struct sizes do not match\")\n        header = cls(\n            flags=values[4],\n            index_count=values[5],\n            data_start=values[6],\n            alignment=values[7],\n            num_layers=values[8],\n            num_experts=values[9],\n            top_k=values[10],\n            role_count=values[11],\n            model_identity_sha256=values[12].hex(),\n            source_blob_sha256=values[13].hex(),\n            config_sha256=values[14].hex(),\n        )\n        expected = header.num_layers * header.num_experts * len(ROLE_NAMES)\n        if header.index_count != expected or header.role_count != len(ROLE_NAMES):\n            raise ValueError(\"expert-pack header coverage is inconsistent\")\n        if header.flags & REQUIRED_FLAGS != REQUIRED_FLAGS:\n            raise ValueError(\"expert-pack is not identity triplet layout\")\n        if header.alignment <= 0 or header.alignment & (header.alignment - 1):\n            raise ValueError(\"expert-pack alignment is invalid\")\n        minimum = HEADER_STRUCT.size + header.index_count * ENTRY_STRUCT.size\n        if header.data_start < minimum or header.data_start % header.alignment:\n            raise ValueError(\"expert-pack data offset is invalid\")\n        return header\n\n\n@dataclass(frozen=True)\nclass ExpertPackEntry:\n    layer: int\n    expert: int\n    role_id: int\n    dtype_id: int\n    dtype: str\n    tensor_name: str\n    source_slice_offset: int\n    source_slice_nbytes: int","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/layers/moe/expert_pack.py#L76-L112","documentation":"The header's flags bitmask does not contain REQUIRED_FLAGS (bits 0 and 1), meaning the pack is not stored in the identity triplet layout the runtime requires (one entry per gate/up/down role per expert, with identity transform). The reader refuses packs produced with non-trivial transforms or a different layout.","triggerScenarios":"ExpertPackHeader.read on a pack whose flags field is missing bit 0 or bit 1 — e.g. produced by a packer that applied transforms (transposed/quantized-repacked layout) or a legacy/partial pack written before the flags existed.","commonSituations":"Packs produced by an older or third-party packing tool that did not set the identity-triplet flags; attempting to load a transform-based (non-identity) pack into a runtime that only supports identity layout; version skew between packer and reader.","solutions":["Re-pack the experts with the current tool, which sets REQUIRED_FLAGS (bits 0|1) for identity triplet layout","Check the packer version used to create the file and upgrade/rebuild so flags match the reader","If you need transformed layouts, use a reader/runtime version that supports those flags instead"],"exampleFix":"# before\n# pack created with transform-mode tooling -> flags=0\nstore = ExpertPackStore(\"experts.pack\")\n\n# after\n# rebuild with identity triplet layout (sets flags bits 0 and 1)\nstore = ExpertPackStore(\"experts.identity.pack\")","handlingStrategy":"validation","validationCode":"def has_identity_triplet_flags(path):\n    with open(path, \"rb\") as f:\n        v = HEADER_STRUCT.unpack(f.read(HEADER_STRUCT.size))\n    return v[4] & 0b11 == 0b11","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin the sglang version used for packing and serving to the same release","Record the packer version in the manifest and check it before loading"],"tags":["moe","expert-pack","binary-format","flags","layout-mismatch"],"backgroundTag":"file-format-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}