{"record":{"id":"e955c0d49ec0fd1c","repo":"sgl-project/sglang","slug":"unsupported-rrdbnet-conv-first-input-channels-in","errorCode":null,"errorMessage":"Unsupported RRDBNet conv_first input channels: {in_channels}","messagePattern":"Unsupported RRDBNet conv_first input channels: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/postprocess/realesrgan_upscaler.py","lineNumber":226,"sourceCode":"# ---------------------------------------------------------------------------\n# Architecture auto-detection\n# ---------------------------------------------------------------------------\n\n\ndef _build_net_from_state_dict(state_dict: dict) -> nn.Module:\n    \"\"\"Detect architecture from checkpoint keys and return an unloaded network.\"\"\"\n    if \"conv_first.weight\" in state_dict:\n        # RRDBNet (e.g., RealESRGAN_x4plus)\n        num_feat = state_dict[\"conv_first.weight\"].shape[0]\n        in_channels = state_dict[\"conv_first.weight\"].shape[1]\n        if in_channels == 3:\n            scale = 4\n        elif in_channels == 12:\n            scale = 2\n        elif in_channels == 48:\n            scale = 1\n        else:\n            raise ValueError(\n                f\"Unsupported RRDBNet conv_first input channels: {in_channels}\"\n            )\n        num_block = sum(\n            1\n            for k in state_dict\n            if k.startswith(\"body.\") and k.endswith(\".rdb1.conv1.weight\")\n        )\n        num_grow_ch = state_dict[\"body.0.rdb1.conv1.weight\"].shape[0]\n        logger.info(\n            \"Detected RRDBNet: num_feat=%d, num_block=%d, num_grow_ch=%d, scale=%d\",\n            num_feat,\n            num_block,\n            num_grow_ch,\n            scale,\n        )\n        return RRDBNet(\n            num_in_ch=3,\n            num_out_ch=3,","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/postprocess/realesrgan_upscaler.py#L208-L244","documentation":"Raised in realesrgan_upscaler._build_net_from_state_dict when inferring scale from the RRDBNet checkpoint's conv_first weight shape: 3→scale 4, 12→scale 2, 48→scale 1. Any other input-channel count means the checkpoint is not a standard RRDBNet real-ESRGAN model.","triggerScenarios":"Loading a .pth whose 'conv_first.weight' has an unexpected first dimension (e.g. 1, 6, or 64 channels), typically a different super-resolution architecture or a non-image model.","commonSituations":"Pointing model_path at a vanilla ESRGAN/SRGAN/Real-ESRGAN anime-video variant with different channel layout, or at an unrelated PyTorch file.","solutions":["Use a standard Real-ESRGAN RRDBNet or SRVGGNetCompact checkpoint (e.g. RealESRGAN_x4plus)","Point model_path at a local .pth or 'repo_id:filename' for a supported model"],"exampleFix":"// before\nupscaler = RealESRGANUpscaler(model_path=\"some_srgan.pth\")\n// after\nupscaler = RealESRGANUpscaler(model_path=\"ai-forever/RealESRGAN_x4:RealESRGAN_x4.pth\")","handlingStrategy":"try-catch","validationCode":"sd = torch.load(pth, map_location=\"cpu\", weights_only=True)\nch = sd.get(\"conv_first.weight\").shape[1]\nassert ch in (3, 12, 48), f\"unsupported RRDB channels {ch}\"","typeGuard":null,"tryCatchPattern":"try:\n    upscaler.upscale(frame)\nexcept RuntimeError as e:\n    if \"not compatible\" in str(e) or \"conv_first\" in str(e):\n        raise ValueError(\"Use a standard Real-ESRGAN checkpoint\") from e\n    raise","preventionTips":["Smoke-test new checkpoints standalone with torch.load before wiring them in","Stick to published Real-ESRGAN x4plus/x2plus/animevideo checkpoints"],"tags":["realesrgan","checkpoint","architecture","postprocess"],"backgroundTag":"incompatible-checkpoint","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}