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).
This commit is contained in:
ねおん
2025-11-10 02:49:34 +09:00
committed by GitHub
parent 0aa3c04de4
commit fea3070a40

View File

@@ -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