{"record":{"id":"801db6b60513ef2a","repo":"sgl-project/sglang","slug":"pi05-weight-load-failed-len-missing-missing-we","errorCode":null,"errorMessage":"Pi05 weight load failed: {len(missing)} missing weights, {mismatched} mismatched weights. Running a robot policy with uninitialized or partially loaded weights is unsafe.","messagePattern":"Pi05 weight load failed: (.+?) missing weights, (.+?) mismatched weights\\. Running a robot policy with uninitialized or partially loaded weights is unsafe\\.","errorType":"error_code","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"python/sglang/multimodal_gen/runtime/models/vlas/pi05_policy.py","lineNumber":771,"sourceCode":"                    target_params,\n                )\n                if target_weight is None:\n                    unexpected += 1\n                    continue\n                target_key, shard_id = target_weight\n                target = self._target_tensor_for_key(\n                    target_key,\n                    target_state,\n                    target_params,\n                )\n                if not self._load_tensor_to_target(target, tensor, shard_id):\n                    mismatched += 1\n                    continue\n                loaded_keys.add(target_key)\n\n        missing = [key for key in target_state if key not in loaded_keys]\n        if missing or mismatched:\n            raise RuntimeError(\n                f\"Pi05 weight load failed: {len(missing)} missing weights, \"\n                f\"{mismatched} mismatched weights. Running a robot policy with \"\n                \"uninitialized or partially loaded weights is unsafe.\"\n            )\n        if unexpected:\n            logger.warning(\n                \"Pi05 weight load: %d loaded, %d unexpected\",\n                len(loaded_keys),\n                unexpected,\n            )\n        else:\n            logger.info(\"Pi05 weights loaded successfully\")\n\n    def build_prefix_cache_key(\n        self,\n        observation: VLAObservationBatch,\n    ) -> str:\n        camera_order = tuple(observation.metadata.get(\"camera_order\", ()))","sourceCodeStart":753,"sourceCodeEnd":789,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/vlas/pi05_policy.py#L753-L789","documentation":"Pi05Policy._load_weights copies a checkpoint state_dict into the model and then verifies that every expected parameter was loaded with a matching shape; it reports counts of missing and shape-mismatched weights. Because running a robot policy with random or partially initialized weights produces dangerous physical actions, this check is a hard RuntimeError, not a warning. It runs during __init__/from_pretrained.","triggerScenarios":"Loading a checkpoint that doesn't match the model config: missing keys (partial finetune exports, renamed modules), or shape mismatches (e.g. different action dimension, different Gemma variant depth, or a checkpoint from another Pi0/Pi05 architecture).","commonSituations":"Checkpoint/model version skew after upgrading sglang; finetuned checkpoints that omit vision-tower weights; editing model config (action_dim, num_steps) so shapes no longer line up; mixed safetensors shards not all present in the directory.","solutions":["Verify all checkpoint shards are present in the model path (incomplete downloads are the #1 cause)","Confirm the model config (variant, action_dim) matches the checkpoint — re-download the original config.json","If you finetuned and intentionally dropped modules, export the full state_dict instead","Log missing/mismatched key lists before the raise (or in a debugger) to see exactly which modules fail"],"exampleFix":"# before\n# incomplete download: only model-00001-of-00002.safetensors present\npolicy = Pi05Policy.from_pretrained(\"./pi05_ckpt\")\n\n# after\n# complete both shards, then:\npolicy = Pi05Policy.from_pretrained(\"./pi05_ckpt\")","handlingStrategy":"try-catch","validationCode":"import os, glob, torch, json\nshards = sorted(glob.glob(f\"{model_path}/*.safetensors\"))\nassert shards, \"no safetensors found\"\nfrom safetensors import safe_open\nckpt_keys = set()\nfor s in shards:\n    with safe_open(s, framework=\"pt\") as f:\n        ckk_keys |= set(f.keys())\n# quick sanity: every ckpt key starts with a known Pi05 module prefix\nbad = [k for k in ck_keys if not k.startswith((\"vision_tower.\", \"language_model.\", \"noise_proj.\", \"action_in_proj.\", \"action_out_proj.\"))]\nassert not bad, f\"foreign keys: {bad[:5]}\"","typeGuard":null,"tryCatchPattern":"try:\n    policy = Pi05Policy.from_pretrained(path)\nexcept RuntimeError as e:\n    if \"Pi05 weight load failed\" in str(e):\n        # do NOT fall back to partial weights for a robot policy\n        raise SystemExit(\n            f\"Checkpoint incomplete/mismatched at {path}. \"\n            \"Re-download or fix config. Details: {e}\"\n        ) from e\n    raise","preventionTips":["Verify checkpoint shard counts and file sizes (hash check) after download before serving","Keep model config and weights versioned together; never mix config.json from one release with weights from another","Treat this error as fatal — never catch-and-continue for robotics control"],"tags":["pi05","weight-loading","checkpoint","state-dict"],"backgroundTag":"checkpoint-load-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}