{"record":{"id":"344b7c976b28d0b3","repo":"sgl-project/sglang","slug":"unsupported-scale-scale-choose-from-list-mappi","errorCode":null,"errorMessage":"Unsupported scale {scale}. Choose from {list(mapping.keys())}","messagePattern":"Unsupported scale (.+?)\\. Choose from (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/upsampler/latent_upsampler.py","lineNumber":128,"sourceCode":"\n    def forward(self, x: torch.Tensor) -> torch.Tensor:\n        residual = x\n        x = self.conv1(x)\n        # Fused GroupNorm + SiLU on the first norm of the block. The second\n        # norm (line below) is followed by `silu(norm + residual)`, which the\n        # current `apply_group_norm_silu` helper does not cover -- left on\n        # the eager path until a `group_norm_add_silu` helper exists.\n        x = apply_group_norm_silu(x, self.norm1, self.activation)\n        x = self.conv2(x)\n        x = self.norm2(x)\n        x = self.activation(x + residual)\n        return x\n\n\ndef _rational_for_scale(scale: float) -> Tuple[int, int]:\n    mapping = {0.75: (3, 4), 1.5: (3, 2), 2.0: (2, 1), 4.0: (4, 1)}\n    if float(scale) not in mapping:\n        raise ValueError(\n            f\"Unsupported scale {scale}. Choose from {list(mapping.keys())}\"\n        )\n    return mapping[float(scale)]\n\n\nclass SpatialRationalResampler(torch.nn.Module):\n    \"\"\"Fully-learned rational spatial scaling via PixelShuffle + anti-aliased downsample.\"\"\"\n\n    def __init__(self, mid_channels: int, scale: float):\n        super().__init__()\n        self.scale = float(scale)\n        self.num, self.den = _rational_for_scale(self.scale)\n        self.conv = torch.nn.Conv2d(\n            mid_channels, (self.num**2) * mid_channels, kernel_size=3, padding=1\n        )\n        self.pixel_shuffle = PixelShuffleND(2, upscale_factors=(self.num, self.num))\n        self.blur_down = BlurDownsample(dims=2, stride=self.den)\n","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/upsampler/latent_upsampler.py#L110-L146","documentation":"The latent upsampler only supports a fixed set of rational spatial scale factors, mapped internally to integer fractions (0.75→3/4, 1.5→3/2, 2.0→2/1, 4.0→4/1). Constructing SpatialRationalResampler with any other scale value raises this error because no rational upsampling path exists for it.","triggerScenarios":"Instantiating SpatialRationalResampler (or a wrapper that passes scale) with e.g. scale=3.0, scale=1.0, or a float that isn't exactly one of 0.75/1.5/2.0/4.0. The check is float(scale) not in mapping, so near-misses like 2.0000001 also fail.","commonSituations":"Copying a config from another model variant with different resolution requirements; passing a scale computed from a ratio (e.g. target_res/base_res) that doesn't land on a supported value; floating point drift when scale is derived arithmetically.","solutions":["Set scale to one of the supported values: 0.75, 1.5, 2.0, or 4.0","If scale is computed, round it to the nearest supported value before passing it in","If you need an unsupported ratio, use a different upsampler module that supports arbitrary scales"],"exampleFix":"# before\nresampler = SpatialRationalResampler(scale=3.0)\n# after\nresampler = SpatialRationalResampler(scale=4.0)","handlingStrategy":"validation","validationCode":"SUPPORTED_SCALES = {0.75, 1.5, 2.0, 4.0}\nif not any(abs(scale - s) < 1e-9 for s in SUPPORTED_SCALES):\n    scale = min(SUPPORTED_SCALES, key=lambda s: abs(scale - s))\n    # or raise your own descriptive error before constructing","typeGuard":"def is_supported_scale(scale: float) -> bool:\n    return float(scale) in {0.75, 1.5, 2.0, 4.0}","tryCatchPattern":null,"preventionTips":["Validate scale against the supported set in config loading, not at model construction","If scale is derived from resolutions, round it to the nearest supported rational explicitly"],"tags":["upsampler","scale","config","value-error"],"backgroundTag":"unsupported-config-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}