mirror of
https://github.com/Physton/sd-webui-prompt-all-in-one.git
synced 2026-12-03 18:42:25 +07:00
[PR #369] [MERGED] Fix: Use try-except to stabilize token counter during model access #362
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Physton/sd-webui-prompt-all-in-one#362
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Physton/sd-webui-prompt-all-in-one/pull/369
Author: @neon-aiart
Created: 11/26/2025
Status: ✅ Merged
Merged: 11/26/2025
Merged by: @Physton
Base:
main← Head:fix/token-counter-v4📝 Commits (2)
077daf3FIX: Prevent critical TypeError in token counter with robust null check (v4)88be653Fix: Use try-except to stabilize token counter during model access📊 Changes
1 file changed (+30 additions, -29 deletions)
View changed files
📝
scripts/physton_prompt/get_token_counter.py(+30 -29)📄 Description
This commit fixes a critical server crash issue that occurs when the token counter API is triggered during model instability.
🐛 Bug Details
The crash occurs when the token counter API is called (e.g., by user interaction like using a word/tag completion extension) while the model is switching or loading (e.g., via the dropdown menu or XYZ Plot).
sd_models.model_data.sd_model) exists in memory but its internal component,cond_stage_model, is momentarilyNoneor in an incomplete state due to aggressive memory management in Forge/reForge..cond_stage_modelattribute triggers aTypeError: argument of type 'NoneType' is not iterablewithin PyTorch's internal__getattr__method, which standard Pythonifchecks cannot safely bypass.🛠️ Solution and Rationale
Previous attempts using sequential
ifchecks (e.g.,if A is None or A.B is None) failed because the crash happened inside PyTorch's attribute lookup process, bypassing Python's short-circuit evaluation.get_token_counterfunction is wrapped in atry-exceptblock as the final and most robust defense.{"token_count": 0, "max_length": 0}instead of crashing the server.🕹️ Reproduction Steps
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.