{"record":{"id":"4ad72b794f4f4f7e","repo":"sgl-project/sglang","slug":"hybrid-ref2va-layout-only-supports-first-last-keyf","errorCode":null,"errorMessage":"hybrid ref2va layout only supports first/last keyframe anchors, got resolved frame index {pixel_index}","messagePattern":"hybrid ref2va layout only supports first/last keyframe anchors, got resolved frame index (.+?)","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":504,"sourceCode":"    g[audio_sl, 0] = audio_t_grid.repeat(audio_channel)\n    g[audio_sl.start : audio_sl.start + audio_t, 2] = float(w_grid[0])\n    g[audio_sl.start + audio_t : audio_sl.stop, 2] = float(w_grid[-1])\n\n    video_g = g[video_sl].view(latent_t, frame_rows, 3)\n    video_g[:, :, 0] = _video_t_grid(latent_t, t_cursor)[:, None]\n    video_g[:, :, 1:] = target_frame[None]\n\n    for block_index, pixel_index in enumerate(resolved_keyframe_indices):\n        sl = slice(\n            keyframe_sl.start + block_index * frame_rows,\n            keyframe_sl.start + (block_index + 1) * frame_rows,\n        )\n        if pixel_index == 0:\n            cond_t = t_cursor\n        elif frame_count is not None and pixel_index == frame_count - 1:\n            cond_t = t_cursor + _temporal_position_span(latent_t) - _FRAME_RESCALE\n        else:\n            raise ValueError(\n                \"hybrid ref2va layout only supports first/last keyframe anchors, \"\n                f\"got resolved frame index {pixel_index}\"\n            )\n        g[sl, 0] = cond_t\n        g[sl, 1:] = target_frame\n\n    keyframe_img_pos = _range_for_slice(keyframe_sl)\n    target_img_pos = _range_for_slice(video_sl)\n    target_audio_pos = _range_for_slice(audio_sl)\n    img_pos = _cat_ranges([keyframe_img_pos] + ref_img_pos_parts + [target_img_pos])\n    audio_pos = _cat_ranges(ref_audio_pos_parts + [target_audio_pos])\n\n    update_mask = torch.zeros(img_pos.shape[0], dtype=torch.bool)\n    update_mask[keyframe_rows + ref_visual_rows :] = True\n    audio_update_mask = torch.zeros(audio_pos.shape[0], dtype=torch.bool)\n    audio_update_mask[ref_audio_rows:] = True\n    text_pos = torch.arange(0, text_len)\n","sourceCodeStart":486,"sourceCodeEnd":522,"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#L486-L522","documentation":"In the hybrid ref2va layout, each reference block may anchor to a keyframe, but only the first (pixel index 0) and last (frame_count - 1) frames of the target video are valid anchors. The error reports the resolved frame index when a keyframe_frame_indices entry maps to any middle frame. This restriction exists because only first/last keyframe rows are materialized in the packed sequence.","triggerScenarios":"Passing keyframe_frame_indices that resolve (via the keyframe-condition index resolution) to a frame index other than 0 or frame_count-1 — e.g. indices [1], [0, 5, 10] on a 12-frame clip where 5 is a middle frame.","commonSituations":"Sampling 'representative' middle frames as conditioning anchors; off-by-one errors producing frame_count instead of frame_count-1; a UI letting users pick arbitrary keyframes on a timeline.","solutions":["Restrict keyframe_frame_indices to values resolving to the first or last frame (typically 0 and/or frame_count-1).","Clamp/round requested anchor indices to the nearest endpoint before calling.","For mid-video conditioning, split the clip so the desired frame becomes an endpoint of a segment."],"exampleFix":"# before\nkeyframe_frame_indices = [0, 6, 11]  # 6 is a middle frame -> error\n\n# after\nkeyframe_frame_indices = [0, 11]  # first and last frames only","handlingStrategy":"validation","validationCode":"anchors = [i for i in keyframe_frame_indices if i in (0, frame_count - 1)]\nif len(anchors) != len(keyframe_frame_indices or []):\n    raise ValueError(\"only first/last frame anchors supported\")","typeGuard":"def valid_hybrid_anchors(indices, frame_count) -> bool:\n    return all(i == 0 or i == frame_count - 1 for i in indices)","tryCatchPattern":null,"preventionTips":["Restrict UIs/configs to first/last keyframe selection.","Clamp requested anchor indices to the nearest endpoint before building the layout."],"tags":["validation","keyframe","video","minimax-h3"],"backgroundTag":"unsupported-value-rejected","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}