sgl-project/sglang · error · ValueError
Position map {height}x{width} is not divisible by {grid_reso
Error message
Position map {height}x{width} is not divisible by {grid_resolution}. What it means
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.
Source
Thrown at python/sglang/multimodal_gen/runtime/models/dits/hunyuan3d_paint.py:204
if not isinstance(mid_block, UNetMidBlock2DCrossAttn):
raise TypeError(f"Unexpected SD2 mid block: {type(mid_block).__name__}.")
replace(mid_block.attentions[0], "mid_0_0")
for block_index, block in enumerate(unet.up_blocks):
if not isinstance(block, CrossAttnUpBlock2D):
continue
for attention_index, attention in enumerate(block.attentions):
replace(attention, f"up_{block_index}_{attention_index}_0")
@torch.no_grad()
def compute_voxel_grid_mask(
position: torch.Tensor, grid_resolution: int = 8
) -> torch.Tensor:
position = position.half()
_, _, _, height, width = position.shape
if height % grid_resolution != 0 or width % grid_resolution != 0:
raise ValueError(
f"Position map {height}x{width} is not divisible by {grid_resolution}."
)
valid_mask = (position != 1).all(dim=2, keepdim=True).expand_as(position)
position = position.masked_fill(~valid_mask, 0)
position = rearrange(
position,
"b n c (nh gh) (nw gw) -> b n nh nw c gh gw",
nh=grid_resolution,
nw=grid_resolution,
)
valid_mask = rearrange(
valid_mask,
"b n c (nh gh) (nw gw) -> b n nh nw c gh gw",
nh=grid_resolution,
nw=grid_resolution,
)
counts = valid_mask.sum(dim=(-2, -1))
grid_position = position.sum(dim=(-2, -1)) / counts.clamp(min=1)View on GitHub (pinned to 0132848349)
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
Example fix
# before mask = compute_voxel_grid_mask(position) # position is 500x500, grid=8 # after position = F.interpolate(position, size=(512, 512), mode="nearest") mask = compute_voxel_grid_mask(position) # 512 % 8 == 0
Defensive patterns
Strategy: validation
Validate before calling
_,_,_,h,w = position.shape
assert h % grid_resolution == 0 and w % grid_resolution == 0, f'{h}x{w} not divisible by {grid_resolution}' Type guard
def map_divisible_by_grid(position: torch.Tensor, grid_resolution: int) -> bool:
_,_,_,h,w = position.shape
return h % grid_resolution == 0 and w % grid_resolution == 0 Prevention
- 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
When it happens
Trigger: 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.
Common situations: Rendering position maps at arbitrary resolutions; changing grid_resolution to a value that no longer divides the map size.
Related errors
- O partial tensor must have 4 or 5 dimensions: (num_splits, b
- LSE partial tensor must have 3 or 4 dimensions: (num_splits,
- O tensor must have 3 or 4 dimensions: (batch, seqlen, nheads
- LSE tensor must have 2 or 3 dimensions: (batch, seqlen, nhea
- Validate failed: unsupported dtype: {t.dtype}
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/d088817aef908dcc.
Report an issue: GitHub.