Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

make control-net load order deterministic (#13701)

rattus1ac78180b3f7
diff --git a/comfy/model_management.py b/comfy/model_management.py
index 02ad66656..21738a4c7 100644
--- a/comfy/model_management.py
+++ b/comfy/model_management.py
@@ -721,13 +721,15 @@ def load_models_gpu(models, memory_required=0, force_patch_weights=False, minimu
else:
minimum_memory_required = max(inference_memory, minimum_memory_required + extra_reserved_memory())
- models_temp = set()
+ # Order-preserving dedup. A plain set() would randomize iteration order across runs
+ models_temp = {}
for m in models:
- models_temp.add(m)
+ models_temp[m] = None
for mm in m.model_patches_models():
- models_temp.add(mm)
+ models_temp[mm] = None
- models = models_temp
+ models = list(models_temp)
+ models.reverse()
models_to_load = []
diff --git a/comfy/sampler_helpers.py b/comfy/sampler_helpers.py
index bbba09e26..3782fd2d5 100644
--- a/comfy/sampler_helpers.py
+++ b/comfy/sampler_helpers.py
@@ -89,7 +89,8 @@ def get_additional_models(conds, dtype):
gligen += get_models_from_cond(conds[k], "gligen")
add_models += get_models_from_cond(conds[k], "additional_models")
- control_nets = set(cnets)
+ # Order-preserving dedup. A plain set() would randomize iteration order across runs
+ control_nets = list(dict.fromkeys(cnets))
inference_memory = 0
control_models = []