{"record":{"id":"d92840093c182b66","repo":"sgl-project/sglang","slug":"seq-len-seq-len-used-rows-used","errorCode":null,"errorMessage":"seq_len {seq_len} < used rows {used}","messagePattern":"seq_len (.+?) < used rows (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/minimax_h3/packed_sequence.py","lineNumber":379,"sourceCode":"        keyframe_frame_indices=keyframe_frame_indices,\n    )\n    resolved_keyframe_indices = _resolve_keyframe_frame_indices(\n        keyframe_indices,\n        frame_count=frame_count,\n    )\n    keyframe_rows = len(keyframe_indices) * frame_rows\n    video_rows = latent_t * frame_rows\n    audio_rows = audio_t * audio_channel\n    ref_rows = ref_visual_rows + ref_audio_rows\n    used = text_len + keyframe_rows + ref_rows + audio_rows + video_rows\n    if seq_len is None:\n        seq_len = (\n            (used + MINIMAX_H3_PACKED_SEQUENCE_ALIGNMENT - 1)\n            // MINIMAX_H3_PACKED_SEQUENCE_ALIGNMENT\n            * MINIMAX_H3_PACKED_SEQUENCE_ALIGNMENT\n        )\n    if seq_len < used:\n        raise ValueError(f\"seq_len {seq_len} < used rows {used}\")\n\n    text_sl = slice(0, text_len)\n    keyframe_sl = slice(text_len, text_len + keyframe_rows)\n    cursor = keyframe_sl.stop\n    block_slices: list[dict[str, object]] = []\n    for item in parsed:\n        kind = str(item[\"kind\"])\n        if kind == \"image\":\n            rows = int(item[\"rows\"])\n            visual_sl = slice(cursor, cursor + rows)\n            cursor = visual_sl.stop\n            block_slices.append({**item, \"visual_sl\": visual_sl})\n        elif kind == \"audio\":\n            rows = int(item[\"audio_rows\"])\n            audio_sl = slice(cursor, cursor + rows)\n            cursor = audio_sl.stop\n            block_slices.append({**item, \"audio_sl\": audio_sl})\n        else:","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/minimax_h3/packed_sequence.py#L361-L397","documentation":"The builder computes an alignment-padded seq_len (rounded up to MINIMAX_H3_PACKED_SEQUENCE_ALIGNMENT) from the used row count, or accepts a caller-supplied seq_len; it then asserts seq_len >= used. The check fires when an explicitly passed seq_len is smaller than the rows the layout actually needs (text + keyframe + all reference blocks).","triggerScenarios":"Passing a custom seq_len (rather than letting it be derived) that is less than the computed `used` rows — e.g. seq_len computed from a stale latent shape or from only some of the ref_blocks.","commonSituations":"Reusing a seq_len cached from an earlier request with fewer media blocks; computing seq_len with a different patch size or alignment constant than the packer; trimming seq_len to fit a KV budget without recomputing required rows.","solutions":["Omit seq_len and let the builder derive it with alignment padding.","Recompute seq_len from the same inputs (text_len, latent shape, all ref_blocks) after any change to the media list.","If truncation is intended, reduce ref_blocks or latent resolution instead of forcing a smaller seq_len."],"exampleFix":"# before\nout = minimax_h3_packed_sequence_ref2va_blocks(..., seq_len=old_len)\n\n# after\nout = minimax_h3_packed_sequence_ref2va_blocks(...)  # seq_len derived + aligned","handlingStrategy":"validation","validationCode":"# Let the builder derive seq_len; if you must pass it, verify:\nfrom sglang.multimodal_gen.runtime.pipelines_core.stages.model_specific_stages.minimax_h3.packed_sequence import MINIMAX_H3_PACKED_SEQUENCE_ALIGNMENT\nassert seq_len is None or seq_len >= used_rows_estimate, \"seq_len smaller than required rows\"","typeGuard":null,"tryCatchPattern":"try:\n    layout = minimax_h3_packed_sequence_ref2va_blocks(..., seq_len=seq_len)\nexcept ValueError as e:\n    if \"seq_len\" in str(e):\n        layout = minimax_h3_packed_sequence_ref2va_blocks(...)  # retry with derived seq_len\n    else:\n        raise","preventionTips":["Never hand-compute seq_len; derive it or omit it.","Recompute any cached seq_len whenever ref_blocks or latent dims change."],"tags":["validation","sequence-length","alignment","minimax-h3"],"backgroundTag":"invalid-argument-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}