fix: dedup duplicate controlnet model ids - #46
Open
forkni wants to merge 2 commits into
Open
Conversation
ControlNet configs with duplicate model_ids were not deduplicated at startup (only the live-update path deduped, and asymmetrically). Adds a shared dedupe_controlnet_configs() helper: _prepare_controlnet_configs now dedups on load, and _update_controlnet_config dedups the incoming desired_config plus self-heals any pre-existing duplicate indices on an already-running stream. Root cause: current_models was index-keyed while desired_models was model_id-keyed, so the removal predicate never matched a duplicate whose model_id was still desired.
pyrefly flagged order/best_by_model (typed str-keyed) receiving an int from id(cfg) for the no-model_id fallback path in dedupe_controlnet_configs. Wrap it in a string sentinel; behavior is unchanged, type-checks clean now.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two ControlNet blocks pointing at the same
model_idwere not deduplicatedat startup — only the TouchDesigner live-update path (
Cnblock()) applied"highest weight wins". Startup duplicates loaded the model twice (double
VRAM) and conditioned the generated image additively, and the live path
could not repair what startup produced.
Root cause
_update_controlnet_config'scurrent_modelswas index-keyed(
{0: canny, 1: canny}) whiledesired_modelswas model_id-keyed(
{canny: cfg}). The removal predicate (model_id not in desired_models)never matched a duplicate whose model_id was still desired, so at most the
first duplicate index ever got updated.
Fix
dedupe_controlnet_configs()helper inconfig.py— collapsesduplicate
model_ids to the highestconditioning_scale, first-occurrenceorder, logging every drop at INFO.
_prepare_controlnet_configsnow dedups on load, closing the startup gapfor every config source (TD,
demo/realtime-img2img,examples/*)._update_controlnet_confignow (1) dedups the incomingdesired_configthrough the same helper — this also closes a second creation vector: a
stale, unrefreshed
current_modelssnapshot could otherwise add the samenot-yet-loaded model twice; (2) removes pre-existing duplicate indices from
the already-loaded pipeline before the reorder/diff pass, so an
already-running stream self-heals on its next live update; (3) recomputes
current_models/current_configafter those removals, fixing a latentstale-index/
IndexErrorrisk.Blast radius
Reached via
find_connectionson the changed function: 22 symbols across 13files, all pass-through consumers requiring no change —
demo/realtime-img2img,examples/benchmark/ab_bench.py,examples/config/config_video_test.py,examples/config/config_ipadapter_stream_test.py, and the TouchDesignercomponent's
td_manager.py.Tests
New
tests/unit/test_controlnet_duplicate_dedup.py(8 tests): dedup keepshighest scale + winner's preprocessor, pass-through when clean, pre-existing
duplicate removal on an already-loaded stream, the stale-
current_modelscreation-vector case (asserted on call count), non-duplicated setup left
intact, tie-breaks-to-first-occurrence, and a full startup→live end-to-end
collapse. Neighbor suites (
test_cn_cache_decay.py,test_controlnet_residual_merge.py,test_config_extraction_golden.py,test_param_updater_binding.py— 31 tests) unaffected.