{"record":{"id":"f5af50c0041c566c","repo":"sgl-project/sglang","slug":"num-frames-height-width-are-required-when-hidden-s","errorCode":null,"errorMessage":"num_frames/height/width are required when hidden_states is pre-packed.","messagePattern":"num_frames/height/width are required when hidden_states is pre-packed\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/dits/sana_wm_refiner_transformer.py","lineNumber":358,"sourceCode":"    ) -> torch.Tensor:\n        # Accept either packed (B, L, in_dim) or raw 5D (B, C, T, H, W).\n        if hidden_states.dim() == 5:\n            B_, _, T_, H_, W_ = hidden_states.shape\n            if num_frames is None:\n                num_frames = T_\n            if height is None:\n                height = H_\n            if width is None:\n                width = W_\n            hidden_states = pack_latents(\n                hidden_states,\n                patch_size=self.patch_size,\n                patch_size_t=self.patch_size_t,\n            )\n            packed_input = True\n        else:\n            if num_frames is None or height is None or width is None:\n                raise ValueError(\n                    \"num_frames/height/width are required when hidden_states is pre-packed.\"\n                )\n            packed_input = False\n\n        B = hidden_states.size(0)\n\n        video_coords = self.rope.prepare_video_coords(\n            batch_size=B,\n            num_frames=num_frames,\n            height=height,\n            width=width,\n            device=hidden_states.device,\n            fps=fps,\n        )\n        video_rotary_emb = self.rope(\n            video_coords,\n            device=hidden_states.device,\n            out_dtype=hidden_states.dtype,","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/dits/sana_wm_refiner_transformer.py#L340-L376","documentation":"The refiner transformer can both pack raw latents itself and accept pre-packed token sequences. If hidden_states is already packed (token form), you must tell it the original video geometry via num_frames/height/width so RoPE and attention windows can be computed.","triggerScenarios":"Calling forward with 3-D pre-packed hidden_states (B, tokens, C) but omitting any of num_frames, height, width.","commonSituations":"Caching packed latents from a previous stage and forwarding without geometry metadata; porting a pipeline that assumed the model infers geometry (it can't from packed tokens alone).","solutions":["Pass num_frames, height, and width (the latent-plane dimensions) alongside packed hidden_states","Or pass unpacked 5-D hidden_states (B, C, T, H, W) and let the refiner pack internally","Store geometry alongside cached packed latents so it is never lost"],"exampleFix":"# before\nout = refiner(packed_h, timestep=t, encoder_hidden_states=ehs)\n# after\nout = refiner(packed_h, timestep=t, encoder_hidden_states=ehs,\n              num_frames=T, height=H, width=W)","handlingStrategy":"validation","validationCode":"if hidden_states.ndim == 3:\n    assert num_frames and height and width, 'geometry required for packed input'","typeGuard":"def is_unpacked(h: torch.Tensor) -> bool: return h.ndim == 5","tryCatchPattern":null,"preventionTips":["Carry (num_frames, height, width) in the same struct as packed latents"],"tags":["sana-wm","refiner","missing-argument","pre-packed-latents"],"backgroundTag":"missing-required-argument","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}