{"record":{"id":"4d26c37845a4e6d8","repo":"sgl-project/sglang","slug":"ambiguous-tensor-payload-for-multi-module-update","errorCode":null,"errorMessage":"Ambiguous tensor payload for multi-module update. Provide a dict mapping module_name -> module payload, requested modules: {module_names}.","messagePattern":"Ambiguous tensor payload for multi-module update\\. Provide a dict mapping module_name -> module payload, requested modules: (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/post_training/weights_updater.py","lineNumber":759,"sourceCode":"    def _resolve_module_payloads(\n        self,\n        named_tensors: Any,\n        modules_to_update: list[tuple[str, torch.nn.Module]],\n    ) -> dict[str, Any]:\n        module_names = [name for name, _ in modules_to_update]\n        if isinstance(named_tensors, dict):\n            missing = [name for name in module_names if name not in named_tensors]\n            if missing:\n                raise ValueError(\n                    f\"Missing tensor payload for module(s): {missing}. \"\n                    f\"Provided modules: {list(named_tensors.keys())}\"\n                )\n            return {name: named_tensors[name] for name in module_names}\n\n        if len(module_names) == 1:\n            return {module_names[0]: named_tensors}\n\n        raise ValueError(\n            \"Ambiguous tensor payload for multi-module update. \"\n            \"Provide a dict mapping module_name -> module payload, \"\n            f\"requested modules: {module_names}.\"\n        )\n\n    def _materialize_weights_iter(self, module_payload: Any, load_format: str | None):\n        if load_format == \"flattened_bucket\":\n            if not isinstance(module_payload, dict):\n                raise ValueError(\n                    \"flattened_bucket payload must be a dict with \"\n                    \"'flattened_tensor' and 'metadata'.\"\n                )\n            flattened_tensor = module_payload.get(\"flattened_tensor\")\n            metadata = module_payload.get(\"metadata\")\n            if flattened_tensor is None or metadata is None:\n                raise ValueError(\n                    \"flattened_bucket payload missing 'flattened_tensor' or 'metadata'.\"\n                )","sourceCodeStart":741,"sourceCodeEnd":777,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/post_training/weights_updater.py#L741-L777","documentation":"Raised by WeightsUpdater._resolve_module_payloads when a non-dict payload is given but the update targets more than one module. With multiple modules the updater cannot tell which payload belongs to which module, so it demands a dict keyed by module name.","triggerScenarios":"Calling update_weights_from_tensor with named_tensors being a single payload object (list/tuple/flattened bucket) while target_modules (or the default full module set) contains 2+ modules. A single payload is only accepted when exactly one module is being updated.","commonSituations":"Code originally written for a single-module pipeline reused on a multi-module pipeline; defaulting target_modules=None (all modules) but passing one flat payload.","solutions":["Pass a dict {module_name: payload} covering every requested module","Or set target_modules to exactly one module so the single payload can be assigned to it"],"exampleFix":"// before\nupdater.update_weights_from_tensor(named_tensors=flat_payload, target_modules=[\"a\",\"b\"])\n// after\nupdater.update_weights_from_tensor(named_tensors={\"a\": payload_a, \"b\": payload_b})","handlingStrategy":"type-guard","validationCode":"if len(target_modules) > 1 and not isinstance(named_tensors, dict):\n    named_tensors = {target_modules[0]: named_tensors}  # only valid if you truly want one module\n# otherwise build a per-module dict","typeGuard":"def is_multi_module_payload(named_tensors: Any, n: int) -> bool:\n    return n == 1 or isinstance(named_tensors, dict)","tryCatchPattern":null,"preventionTips":["Always pass a dict {module_name: payload} regardless of module count","Keep target_modules explicit rather than None on multi-module pipelines"],"tags":["weights-update","payload","ambiguous","multimodal"],"backgroundTag":"ambiguous-payload-mapping","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}