{"record":{"id":"d088817aef908dcc","repo":"sgl-project/sglang","slug":"position-map-height-x-width-is-not-divisible-by","errorCode":null,"errorMessage":"Position map {height}x{width} is not divisible by {grid_resolution}.","messagePattern":"Position map (.+?)x(.+?) is not divisible by (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/dits/hunyuan3d_paint.py","lineNumber":204,"sourceCode":"    if not isinstance(mid_block, UNetMidBlock2DCrossAttn):\n        raise TypeError(f\"Unexpected SD2 mid block: {type(mid_block).__name__}.\")\n    replace(mid_block.attentions[0], \"mid_0_0\")\n\n    for block_index, block in enumerate(unet.up_blocks):\n        if not isinstance(block, CrossAttnUpBlock2D):\n            continue\n        for attention_index, attention in enumerate(block.attentions):\n            replace(attention, f\"up_{block_index}_{attention_index}_0\")\n\n\n@torch.no_grad()\ndef compute_voxel_grid_mask(\n    position: torch.Tensor, grid_resolution: int = 8\n) -> torch.Tensor:\n    position = position.half()\n    _, _, _, height, width = position.shape\n    if height % grid_resolution != 0 or width % grid_resolution != 0:\n        raise ValueError(\n            f\"Position map {height}x{width} is not divisible by {grid_resolution}.\"\n        )\n    valid_mask = (position != 1).all(dim=2, keepdim=True).expand_as(position)\n    position = position.masked_fill(~valid_mask, 0)\n    position = rearrange(\n        position,\n        \"b n c (nh gh) (nw gw) -> b n nh nw c gh gw\",\n        nh=grid_resolution,\n        nw=grid_resolution,\n    )\n    valid_mask = rearrange(\n        valid_mask,\n        \"b n c (nh gh) (nw gw) -> b n nh nw c gh gw\",\n        nh=grid_resolution,\n        nw=grid_resolution,\n    )\n    counts = valid_mask.sum(dim=(-2, -1))\n    grid_position = position.sum(dim=(-2, -1)) / counts.clamp(min=1)","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/dits/hunyuan3d_paint.py#L186-L222","documentation":"compute_voxel_grid_mask pools a position map into a voxel grid via rearrange, which requires the spatial dimensions to be exactly divisible by grid_resolution (default 8). If height or width is not divisible, this ValueError is raised before the pooling rearrange.","triggerScenarios":"Calling compute_voxel_grid_mask (or compute_multi_resolution_mask) with a position map whose H or W is not a multiple of grid_resolution, e.g. 513x513 renders or non-multiple resolutions like 500x500 with grid_resolution=8.","commonSituations":"Rendering position maps at arbitrary resolutions; changing grid_resolution to a value that no longer divides the map size.","solutions":["Resize/crop the position map so H and W are multiples of grid_resolution (e.g. 512x512 for grid 8)","Choose a grid_resolution that divides both H and W (e.g. 5 for a 513-wide map)","Compute grid_resolution from the map size via a common divisor before calling"],"exampleFix":"# before\nmask = compute_voxel_grid_mask(position)  # position is 500x500, grid=8\n\n# after\nposition = F.interpolate(position, size=(512, 512), mode=\"nearest\")\nmask = compute_voxel_grid_mask(position)  # 512 % 8 == 0","handlingStrategy":"validation","validationCode":"_,_,_,h,w = position.shape\nassert h % grid_resolution == 0 and w % grid_resolution == 0, f'{h}x{w} not divisible by {grid_resolution}'","typeGuard":"def map_divisible_by_grid(position: torch.Tensor, grid_resolution: int) -> bool:\n    _,_,_,h,w = position.shape\n    return h % grid_resolution == 0 and w % grid_resolution == 0","tryCatchPattern":null,"preventionTips":["Render position maps at power-of-two resolutions","Assert divisibility before calling mask helpers","Derive grid_resolution from the map size when resolution is user-supplied"],"tags":["validation","shape-mismatch","mask","diffusion"],"backgroundTag":"image-size-not-divisible-by-patch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}