From bcf1a1fab1e9efe0d4999ea14e9c0318409e0000 Mon Sep 17 00:00:00 2001 From: rattus <46076784+rattus128@users.noreply.github.com> Date: Sat, 7 Mar 2026 09:38:08 -0800 Subject: [PATCH] mm: reset_cast_buffers: sync compute stream before free (#12822) Sync the compute stream before freeing the cast buffers. This can cause use after free issues when the cast stream frees the buffer while the compute stream is behind enough to still needs a casted weight. --- comfy/model_management.py | 1 + 1 file changed, 1 insertion(+) diff --git a/comfy/model_management.py b/comfy/model_management.py index 39b4aa483..07bc8ad67 100644 --- a/comfy/model_management.py +++ b/comfy/model_management.py @@ -1148,6 +1148,7 @@ def reset_cast_buffers(): LARGEST_CASTED_WEIGHT = (None, 0) for offload_stream in STREAM_CAST_BUFFERS: offload_stream.synchronize() + synchronize() STREAM_CAST_BUFFERS.clear() soft_empty_cache()