{"record":{"id":"9ce0909c8a5bb1c7","repo":"sgl-project/sglang","slug":"invalid-latent-grid-for-memory-rope-latent-heigh","errorCode":null,"errorMessage":"Invalid latent grid for memory RoPE: {latent_height=} {latent_width=}","messagePattern":"Invalid latent grid for memory RoPE: (.+?) (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/joy_echo/memory.py","lineNumber":442,"sourceCode":"    target_num_frames: int,\n    latent_height: int,\n    latent_width: int,\n    device: torch.device,\n    fps: float,\n    memory_position_mode: str,\n    memory_downscale_factor: int = 1,\n    sp_target_start_offset: int = 0,\n) -> torch.Tensor:\n    \"\"\"Build [memory | target] video RoPE coordinates.\n\n    Under sequence parallelism the target video latents are time-sharded, so\n    ``target_num_frames`` is the *local* shard frame count and\n    ``sp_target_start_offset`` is the global frame index of this rank's first\n    target frame. The memory prefix is replicated (full) on every rank.\n    \"\"\"\n    tokens_per_latent_frame = int(latent_height) * int(latent_width)\n    if tokens_per_latent_frame <= 0:\n        raise ValueError(\n            f\"Invalid latent grid for memory RoPE: {latent_height=} {latent_width=}\"\n        )\n    if memory_video_len % tokens_per_latent_frame != 0:\n        raise ValueError(\n            \"memory_video_len must be a multiple of latent_height * latent_width, \"\n            f\"got {memory_video_len=} {latent_height=} {latent_width=}\"\n        )\n\n    memory_latent_frames = memory_video_len // tokens_per_latent_frame\n    position_mode = normalize_memory_position_mode(memory_position_mode)\n\n    memory_coords = rope.prepare_video_coords(\n        batch_size=batch_size,\n        num_frames=memory_latent_frames,\n        height=latent_height,\n        width=latent_width,\n        device=device,\n        fps=JOYAI_VIDEO_ROPE_FPS,","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/joy_echo/memory.py#L424-L460","documentation":"Memory video RoPE coordinates require a positive latent grid: latent_height * latent_width must be > 0 because each latent frame contributes exactly that many tokens. A zero or negative product means the VAE downsampling factors produced a degenerate grid (e.g. video shorter/smaller than the spatial/temporal stride), so positions cannot be computed.","triggerScenarios":"Calling build_memory_video_rope_coords with latent_height=0 or latent_width=0 (or negative), typically derived from (H // vae_spatial_stride) or (W // vae_spatial_stride) for a very small or empty video tensor.","commonSituations":"Feeding a stub/test video of a few pixels; empty batch producing H=0/W=0; mismatched VAE downsample factor config vs actual model; upstream crop/resize stage producing a zero-sized frame.","solutions":["Check the input video tensor's H and W before calling: ensure H >= vae_spatial_downsample and W >= vae_spatial_downsample","Verify the VAE downsample factor matches the checkpoint you loaded (e.g. 8x8 spatial, temporal stride) so computed latent dims are positive","Guard in the caller: skip memory-RoPE path or raise a clearer upstream error when the latent grid would be degenerate"],"exampleFix":"# before\ncoords = build_memory_video_rope_coords(memory_video_len=m, latent_height=h // 8, latent_width=w // 8)\n# after\nlh, lw = h // 8, w // 8\nassert lh > 0 and lw > 0, f\"video too small for VAE stride: {h=} {w=}\"\ncoords = build_memory_video_rope_coords(memory_video_len=m, latent_height=lh, latent_width=lw)","handlingStrategy":"validation","validationCode":"lh, lw = int(latent_height), int(latent_width)\nif lh <= 0 or lw <= 0:\n    raise ValueError(f\"degenerate latent grid {lh=} {lw=}; check video size vs VAE stride\")","typeGuard":"def has_valid_latent_grid(latent_height: int, latent_width: int) -> bool:\n    return int(latent_height) * int(latent_width) > 0","tryCatchPattern":null,"preventionTips":["Validate input video H/W against the VAE downsample factor at the pipeline entry","Log computed latent dims per clip to catch zero-size frames early"],"tags":["joy-echo","memory","rope","latent-grid","video"],"backgroundTag":"invalid-tensor-shape","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}