binary-husky/gpt_academic · error · RuntimeError
_llm_handle.get_state()
Error message
_llm_handle.get_state()
What it means
In predict_no_ui_long_connection (the non-UI plugin pathway), after obtaining the singleton local-LLM handle it checks _llm_handle.running; if the loader subprocess died (e.g. it raised error 182's RuntimeError), running is False and this raises RuntimeError with the handle's last state string (e.g. '`加载模型失败`'). The message is the state label, not a stack trace.
Source
Thrown at request_llms/local_llm_class.py:227
self.running = False
self.corrupted = True
break
else:
std_out = ""
yield res
def get_local_llm_predict_fns(LLMSingletonClass, model_name, history_format='classic'):
load_message = f"{model_name}尚未加载,加载需要一段时间。注意,取决于`config.py`的配置,{model_name}消耗大量的内存(CPU)或显存(GPU),也许会导致低配计算机卡死 ……"
def predict_no_ui_long_connection(inputs:str, llm_kwargs:dict, history:list=[], sys_prompt:str="", observe_window:list=[], console_silence:bool=False):
"""
refer to request_llms/bridge_all.py
"""
_llm_handle = GetSingletonHandle().get_llm_model_instance(LLMSingletonClass)
if len(observe_window) >= 1:
observe_window[0] = load_message + "\n\n" + _llm_handle.get_state()
if not _llm_handle.running:
raise RuntimeError(_llm_handle.get_state())
if history_format == 'classic':
# 没有 sys_prompt 接口,因此把prompt加入 history
history_feedin = []
history_feedin.append([sys_prompt, "Certainly!"])
for i in range(len(history)//2):
history_feedin.append([history[2*i], history[2*i+1]])
elif history_format == 'chatglm3':
# 有 sys_prompt 接口
conversation_cnt = len(history) // 2
history_feedin = [{"role": "system", "content": sys_prompt}]
if conversation_cnt:
for index in range(0, 2*conversation_cnt, 2):
what_i_have_asked = {}
what_i_have_asked["role"] = "user"
what_i_have_asked["content"] = history[index]
what_gpt_answer = {}
what_gpt_answer["role"] = "assistant"View on GitHub (pinned to d6bde0fa54)
Solutions
- Reproduce with the interactive predict() path first: its chatbot output shows the full '[Local Message]' traceback from the loader.
- Fix the underlying load failure (model path, memory, dependencies) — see error 182.
- Restart the app to rebuild the singleton handle after fixing config; a dead handle never recovers in-process.
- If memory-bound, choose a smaller model or add swap/quantization.
Defensive patterns
Strategy: validation
Validate before calling
_llm_handle = GetSingletonHandle().get_llm_model_instance(LLMSingletonClass)
if not getattr(_llm_handle, 'running', False):
# fail fast with the loader's last state instead of proceeding
raise ModelNotReady(_llm_handle.get_state()) Try / catch
try:
result = predict_no_ui_long_connection(...)
except RuntimeError as e:
if '加载模型失败' in str(e) or '失败' in str(e):
restart_model_subprocess_with_diagnostics() Prevention
- Warm-load local models at startup and gate the UI on running state.
- Restart the app after any local-model config change.
- Monitor the loader subprocess liveness in long-running deployments.
When it happens
Trigger: Calling predict_no_ui_long_connection for a local model whose background load failed or crashed: OOM kill of the loader process, exception during load_model_and_tokenizer, or the singleton was constructed moments ago and died before this call.
Common situations: Plugins/crazy_functions that use the no-ui pipeline against a local model on a machine with insufficient memory; first request after configuring a local model that fails to download; handle poisoned by a previous failed run.
Related errors
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/726b05af2f580690.
Report an issue: GitHub.