{"record":{"id":"8bb58f91eb2b9c21","repo":"sgl-project/sglang","slug":"expert-pack-alignment-is-invalid","errorCode":null,"errorMessage":"expert-pack alignment is invalid","messagePattern":"expert-pack alignment is invalid","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"python/sglang/srt/layers/moe/expert_pack.py","lineNumber":96,"sourceCode":"            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\n    pack_offset: int\n    pack_nbytes: int","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/layers/moe/expert_pack.py#L78-L114","documentation":"The header's alignment field is not a positive power of two. The reader requires power-of-two alignment to compute data_start % alignment checks and to do aligned (possibly O_DIRECT) reads; zero, negative, or non-power-of-two values indicate header corruption or a bad packer.","triggerScenarios":"ExpertPackHeader.read when alignment is 0, or a value like 12/24/1000 where alignment & (alignment-1) != 0 — typically from corrupted bytes or a hand-crafted header.","commonSituations":"Bit-flip corruption of the pack file, incomplete uploads, or packs written by experimental tooling that used arbitrary alignment (e.g. 384) instead of 256/4096.","solutions":["Re-download or regenerate the pack and verify its sha256 against the manifest","Rebuild with an explicit power-of-two alignment (256 or 4096)","If producing packs yourself, assert alignment is a power of two before writing the header"],"exampleFix":"# before\nheader.alignment = 384  # writer bug\n\n# after\nheader.alignment = 256  # power of two, satisfies alignment & (alignment-1) == 0","handlingStrategy":"validation","validationCode":"def alignment_is_valid(path):\n    with open(path, \"rb\") as f:\n        v = HEADER_STRUCT.unpack(f.read(HEADER_STRUCT.size))\n    a = v[7]\n    return a > 0 and (a & (a - 1)) == 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify sha256 of the pack against the manifest before loading","Use standard alignments (256/4096) when producing packs"],"tags":["moe","expert-pack","binary-format","alignment","corruption"],"backgroundTag":"file-format-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}