From fea3070a40570499d186552c7b0dcea671f044e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AD=E3=81=8A=E3=82=93?= <240400715+neon-aiart@users.noreply.github.com> Date: Mon, 10 Nov 2025 02:49:34 +0900 Subject: [PATCH] FIX: Prevent TypeError: NoneType on model switching in token counter This fixes the critical `TypeError: argument of type 'NoneType' is not iterable` that frequently occurs in the token counter when the main Stable Diffusion model is being unloaded or reloaded (e.g., during XYZ Plot or manual model switching). The error happens because the `get_token_counter` function tries to access `sd_models.model_data.sd_model.cond_stage_model` when `sd_model` is momentarily `None`. The fix adds a robust check for `sd_models.model_data.sd_model is None` at the start of the function, ensuring the token counter safely returns 0 instead of causing an ASGI application crash across all environments (A1111, Forge/reForge). --- scripts/physton_prompt/get_token_counter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/physton_prompt/get_token_counter.py b/scripts/physton_prompt/get_token_counter.py index 13b7d7d..7d96e50 100644 --- a/scripts/physton_prompt/get_token_counter.py +++ b/scripts/physton_prompt/get_token_counter.py @@ -1,7 +1,7 @@ from modules import script_callbacks, extra_networks, prompt_parser, sd_models from modules.sd_hijack import model_hijack from functools import partial, reduce - + def get_token_counter(text, steps): # Check if the model is fully loaded to prevent TypeError during model switching