FIX: Prevent TypeError in token counter during model switching (v2)

The previous fix (v1) was incomplete, as sd_model.cond_stage_model could still be None during model loading/unloading sequences (observed with XYZ Plot model swapping).
This v2 fix adds a specific check for cond_stage_model to ensure stability in dynamic environments.
This commit is contained in:
ねおん
2025-11-15 23:52:24 +09:00
committed by GitHub
parent 6a4fb7015b
commit b49e275eb0

View File

@@ -4,8 +4,10 @@ from functools import partial, reduce
def get_token_counter(text, steps):
# Check if the model is fully loaded to prevent TypeError during model switching
if sd_models.model_data.sd_model is None:
# Check if the model is fully loaded to prevent TypeError during model switching.
# Checks both sd_model and its subcomponent (cond_stage_model).
if sd_models.model_data.sd_model is None or \
sd_models.model_data.sd_model.cond_stage_model is None:
return {"token_count": 0, "max_length": 0}
# copy from modules.ui.py