{"record":{"id":"95a42eddd25d0083","repo":"binary-husky/gpt_academic","slug":"chatglmft","errorCode":null,"errorMessage":"不能正常加载ChatGLMFT的参数！","messagePattern":"不能正常加载ChatGLMFT的参数！","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"request_llms/bridge_chatglmft.py","lineNumber":107,"sourceCode":"                    model.transformer.prefix_encoder.load_state_dict(new_prefix_state_dict)\n\n                    if model_args['quantization_bit'] is not None and model_args['quantization_bit'] != 0:\n                        logger.info(f\"Quantized to {model_args['quantization_bit']} bit\")\n                        model = model.quantize(model_args['quantization_bit'])\n                    model = model.cuda()\n                    if model_args['pre_seq_len'] is not None:\n                        # P-tuning v2\n                        model.transformer.prefix_encoder.float()\n                    self.chatglmft_model = model.eval()\n\n                    break\n                else:\n                    break\n            except Exception as e:\n                retry += 1\n                if retry > 3:\n                    self.child.send('[Local Message] Call ChatGLMFT fail 不能正常加载ChatGLMFT的参数。')\n                    raise RuntimeError(\"不能正常加载ChatGLMFT的参数！\")\n\n        while True:\n            # 进入任务等待状态\n            kwargs = self.child.recv()\n            # 收到消息，开始请求\n            try:\n                for response, history in self.chatglmft_model.stream_chat(self.chatglmft_tokenizer, **kwargs):\n                    self.child.send(response)\n                    # # 中途接收可能的终止指令（如果有的话）\n                    # if self.child.poll():\n                    #     command = self.child.recv()\n                    #     if command == '[Terminate]': break\n            except:\n                from toolbox import trimmed_format_exc\n                self.child.send('[Local Message] Call ChatGLMFT fail.' + '\\n```\\n' + trimmed_format_exc() + '\\n```\\n')\n            # 请求处理结束，开始下一个循环\n            self.child.send('[Finish]')\n","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/request_llms/bridge_chatglmft.py#L89-L125","documentation":"GetModelHolderLoadThread for ChatGLMFT retries loading the fine-tuned model/parameters up to 3 times; on the 4th failure (retry > 3) it raises RuntimeError('不能正常加载ChatGLMFT的参数！') and also notifies the child process. The underlying exception from model loading (missing checkpoint files, GPU OOM, config mismatch) is discarded — only the attempt counter survives.","triggerScenarios":"CHATGLMFT_CHECKPOINT path points to a directory without the expected model files (missing pytorch_model.bin / config.json / tokenizer files); the fine-tuned checkpoint's architecture/parameter names do not match the ChatGLM version installed; CUDA out-of-memory or missing GPU when instantiating the model; P-tuning v2 checkpoint loaded without matching pre_seq_len settings.","commonSituations":"Wrong or partially-uploaded checkpoint directory; checkpoint trained on ChatGLM2 loaded into a ChatGLM3 runtime (or vice versa); shared GPU already occupied so every load attempt OOMs; config keys (pre_seq_len, dtype) not matching the checkpoint, making load_state_dict raise on each retry.","solutions":["Point CHATGLMFT_CHECKPOINT at a complete checkpoint dir (contains config.json, tokenizer files, and the model weights) and verify the files exist.","Match versions: checkpoint, transformers, and the ChatGLM base model version must agree; re-export the checkpoint if not.","Check GPU memory (nvidia-smi) and free it / use a smaller device_map or CPU test-load first to see the real error.","Reproduce the load outside the thread (plain AutoModel.from_pretrained on the same path) to surface the actual exception that the retry loop swallows."],"exampleFix":"# before\nMODEL_PATH = conf_singleton['CHATGLMFT_CHECKPOINT']\n\n# after (surface the real error once instead of 3 blind retries)\ntry:\n    model = AutoModel.from_pretrained(MODEL_PATH, trust_remote_code=True)\nexcept Exception as e:\n    logger.exception(f'ChatGLMFT checkpoint load failed: {e}')\n    raise","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef checkpoint_complete(path: str) -> bool:\n    p = Path(path)\n    required = ['config.json']\n    weights = ['pytorch_model.bin', 'model.safetensors']\n    return p.is_dir() and all((p / f).exists() for f in required) and any((p / w).exists() for w in weights)\n\nif not checkpoint_complete(conf['CHATGLMFT_CHECKPOINT']):\n    raise SystemExit('CHATGLMFT_CHECKPOINT incomplete: need config.json + weights')","typeGuard":null,"tryCatchPattern":"try:\n    run_chatglmft_request(...)\nexcept RuntimeError as e:\n    if 'ChatGLMFT' in str(e):\n        logger.error('model load failed — check checkpoint path, GPU memory, version match')\n        switch_to_remote_model()  # fallback provider\n    raise","preventionTips":["Validate the checkpoint directory contents and GPU free memory before starting the loader thread.","Keep checkpoint, transformers, and ChatGLM base versions aligned; re-export after upgrades.","Load once in a scratch script to see the real exception — the retry loop hides it."],"tags":["chatglm","model-loading","checkpoint","gpu","fine-tuning"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}