{"record":{"id":"ebbcc36025a0faa1","repo":"sgl-project/sglang","slug":"invalid-format-expected-a-mapping-from-gpu-id-to","errorCode":null,"errorMessage":"Invalid format: expected a mapping from GPU id to IB device string","messagePattern":"Invalid format: expected a mapping from GPU id to IB device string","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/distributed/device_communicators/mooncake_transfer_engine.py","lineNumber":57,"sourceCode":"        try:\n            with open(normalized_input, \"r\", encoding=\"utf-8\") as file:\n                mapping = json.load(file)\n        except json.JSONDecodeError as exc:\n            raise RuntimeError(\n                f\"Failed to parse JSON content from file {normalized_input}\"\n            ) from exc\n        except (IOError, OSError) as exc:\n            raise RuntimeError(\n                f\"Failed to read JSON file {normalized_input}: {exc}\"\n            ) from exc\n    else:\n        try:\n            mapping = json.loads(normalized_input)\n        except json.JSONDecodeError as exc:\n            raise ValueError(f\"Invalid JSON mapping: {normalized_input}\") from exc\n\n    if not isinstance(mapping, dict):\n        raise ValueError(\n            \"Invalid format: expected a mapping from GPU id to IB device string\"\n        )\n\n    normalized_mapping: Dict[int, str] = {}\n    for gpu_key, ib_devices in mapping.items():\n        normalized_key = int(gpu_key) if str(gpu_key).isdigit() else None\n        if normalized_key is None or not isinstance(ib_devices, str):\n            raise ValueError(\n                \"Invalid format: keys must be integers (or string \"\n                \"representations of integers) and values must be strings\"\n            )\n        normalized_mapping[normalized_key] = ib_devices.strip()\n\n    if not normalized_mapping:\n        raise ValueError(\"No valid GPU mappings found in JSON\")\n\n    return normalized_mapping\n","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/distributed/device_communicators/mooncake_transfer_engine.py#L39-L75","documentation":"The parsed mooncake IB-device config (from file or inline JSON) is valid JSON but not a JSON object — e.g. an array or a scalar string. parse_ib_device_config requires a dict mapping GPU id to IB device string before it iterates keys/values.","triggerScenarios":"Supplying a JSON array like [\"mlx5_0\", \"mlx5_1\"] or a bare string \"\\\"mlx5_0\\\"\" as the mapping; note a bare non-JSON string input returns earlier, so this specifically comes from JSON-parsed values that are not dicts.","commonSituations":"Assuming the config takes a list of devices indexed by GPU order instead of an explicit id->device mapping.","solutions":["Change the value to a JSON object keyed by GPU id: {\"0\": \"mlx5_0\", \"1\": \"mlx5_1\"}","If all GPUs share one device, drop the JSON and pass the plain device string"],"exampleFix":"# before\n--mooncake-ip-device '[\"mlx5_0\", \"mlx5_1\"]'\n\n# after\n--mooncake-ip-device '{\"0\": \"mlx5_0\", \"1\": \"mlx5_1\"}'","handlingStrategy":"type-guard","validationCode":"import json\n\ndef is_ib_mapping(v) -> bool:\n    return isinstance(v, dict) and all(\n        str(k).isdigit() and isinstance(x, str) and x.strip()\n        for k, x in v.items()\n    )","typeGuard":"def is_ib_device_mapping(cfg: object) -> bool:\n    return (\n        isinstance(cfg, str)\n        or (isinstance(cfg, dict) and bool(cfg)\n            and all(str(k).isdigit() and isinstance(v, str) for k, v in cfg.items()))\n    )","tryCatchPattern":"if not is_ib_mapping(json.loads(cfg)):\n    raise ConfigError(\"expected a GPU-id -> IB-device-string object\")\nparse_ib_device_config(cfg)","preventionTips":["Document the schema as {\"<gpu_id>\": \"<ib_devices>\"}","Validate parsed config shape in a pre-launch lint step","Use a plain string config for the uniform-device case"],"tags":["json","config","schema","mooncake"],"backgroundTag":"schema-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}