{"record":{"id":"ce70039dde7a4ab1","repo":"sgl-project/sglang","slug":"expert-pack-data-offset-is-invalid","errorCode":null,"errorMessage":"expert-pack data offset is invalid","messagePattern":"expert-pack data offset is invalid","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"python/sglang/srt/layers/moe/expert_pack.py","lineNumber":99,"sourceCode":"            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\n    checksum: str\n    shape: tuple[int, ...]\n    quant_scheme: str","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/layers/moe/expert_pack.py#L81-L117","documentation":"The header's data_start offset either leaves the file before the header+index ends (data_start < HEADER_STRUCT.size + index_count*ENTRY_STRUCT.size), or is not aligned to the declared alignment. The reader needs a valid, aligned data region offset to mmap/read expert blobs correctly.","triggerScenarios":"ExpertPackHeader.read when data_start overlaps the index region or data_start % alignment != 0 — e.g. the packer forgot padding between index and data, or the header was edited to change alignment after writing.","commonSituations":"Packer bugs that skip alignment padding after the entry index; mixing an old header with a rewritten body; file corruption; changing alignment in config without re-packing.","solutions":["Regenerate the pack so data_start = align_up(header_size + index_size, alignment)","Keep alignment and layout config unchanged between packing and loading","Verify the file's sha256 against the manifest to rule out corruption"],"exampleFix":"# before\ndata_start = HEADER_STRUCT.size + index_count * ENTRY_STRUCT.size  # unaligned\n\n# after\nend_of_index = HEADER_STRUCT.size + index_count * ENTRY_STRUCT.size\ndata_start = (end_of_index + alignment - 1) & ~(alignment - 1)","handlingStrategy":"validation","validationCode":"def data_start_is_valid(path):\n    with open(path, \"rb\") as f:\n        v = HEADER_STRUCT.unpack(f.read(HEADER_STRUCT.size))\n    data_start, alignment, index_count = v[6], v[7], v[5]\n    minimum = HEADER_STRUCT.size + index_count * ENTRY_STRUCT.size\n    return data_start >= minimum and data_start % alignment == 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When writing packs, compute data_start as align_up(header+index, alignment)","Never edit alignment config after the pack body is written"],"tags":["moe","expert-pack","binary-format","offset","alignment"],"backgroundTag":"file-format-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}