{"record":{"id":"e9adb3ee1cf8ad9a","repo":"sgl-project/sglang","slug":"dimension-dimension-must-be-divisible-by-2","errorCode":null,"errorMessage":"dimension ({dimension}) must be divisible by 2","messagePattern":"dimension \\((.+?)\\) must be divisible by 2","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/vlas/pi05_core.py","lineNumber":833,"sourceCode":"        return GemmaVariantConfig(\n            width=2048,\n            depth=18,\n            mlp_dim=16_384,\n            num_heads=8,\n            num_kv_heads=1,\n            head_dim=256,\n        )\n    raise ValueError(f\"Unknown Pi05 Gemma variant: {variant}\")\n\n\ndef create_sinusoidal_pos_embedding(\n    time: torch.Tensor,\n    dimension: int,\n    min_period: float,\n    max_period: float,\n) -> Tensor:\n    if dimension % 2 != 0:\n        raise ValueError(f\"dimension ({dimension}) must be divisible by 2\")\n    if time.ndim != 1:\n        raise ValueError(\"time must have shape [batch]\")\n    fraction = torch.linspace(\n        0.0,\n        1.0,\n        dimension // 2,\n        dtype=torch.float64,\n        device=time.device,\n    )\n    period = min_period * (max_period / min_period) ** fraction\n    scaling = 1.0 / period * 2 * math.pi\n    sin_input = scaling[None, :] * time[:, None].to(torch.float64)\n    return torch.cat([torch.sin(sin_input), torch.cos(sin_input)], dim=1)\n\n\ndef make_att_2d_masks(\n    pad_masks: torch.Tensor,\n    att_masks: torch.Tensor,","sourceCodeStart":815,"sourceCodeEnd":851,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/vlas/pi05_core.py#L815-L851","documentation":"create_sinusoidal_pos_embedding builds a sinusoidal time embedding of the requested dimension by splitting it into sin/cos halves, so the dimension must be even. An odd dimension makes the construction impossible and the function raises immediately. It is called by embed_suffix during forward, so the bad dimension usually traces back to a model config (embedding dim).","triggerScenarios":"Calling create_sinusoidal_pos_embedding(time, dimension=odd_number, ...) — typically because a config value like the action/time embedding dimension was set to an odd number (e.g. 1023) or computed dynamically to an odd size.","commonSituations":"Customizing Pi05 model dimensions without keeping them even; deriving dimension from another parameter (e.g. hidden_size - 1); porting configs from another codebase with different parity conventions.","solutions":["Set the embedding dimension to an even number (e.g. 1024 instead of 1023) in the config that feeds embed_suffix","Trace where dimension comes from and round it: dimension = 2 * (dimension // 2)","Validate parity at config-load time before model construction"],"exampleFix":"# before\ntime_emb = create_sinusoidal_pos_embedding(t, dimension=1023, min_period=..., max_period=...)\n\n# after\ntime_emb = create_sinusoidal_pos_embedding(t, dimension=1024, min_period=..., max_period=...)","handlingStrategy":"validation","validationCode":"dim = cfg.time_embedding_dim\nassert dim % 2 == 0, f\"time_embedding_dim must be even, got {dim}\"","typeGuard":"def is_even_dimension(dim: int) -> bool:\n    \"\"\"Type guard: dimension usable for sinusoidal embedding.\"\"\"\n    return isinstance(dim, int) and dim > 0 and dim % 2 == 0","tryCatchPattern":"try:\n    emb = create_sinusoidal_pos_embedding(t, dim, pmin, pmax)\nexcept ValueError as e:\n    if \"divisible by 2\" in str(e):\n        dim = 2 * (dim // 2)\n        emb = create_sinusoidal_pos_embedding(t, dim, pmin, pmax)\n    else:\n        raise","preventionTips":["Keep all embedding dimensions in Pi05 configs even by construction (multiples of 2)","When deriving dims from arithmetic (hidden_size // 4 + 1 etc.), assert evenness in a config validator"],"tags":["pi05","sinusoidal-embedding","dimension-validation"],"backgroundTag":"shape-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}