|
17 | 17 |
|
18 | 18 | import nodes |
19 | 19 | import comfy.model_management |
| 20 | +import comfy.model_prefetch |
20 | 21 | import comfy.model_sampling |
21 | 22 | import comfy.nested_tensor |
22 | 23 | import comfy.patcher_extension |
@@ -478,7 +479,8 @@ def diffusion_model_wrapper(self, executor, x, timestep, context, transformer_op |
478 | 479 | self.active = self.sigma_end <= sigma <= self.sigma_start |
479 | 480 | self.control_stream = None |
480 | 481 | if self.active: |
481 | | - self.prepare_control_latent(x[0].shape) |
| 482 | + with comfy.model_prefetch.pause_malloc_graph(): |
| 483 | + self.prepare_control_latent(x[0].shape) |
482 | 484 | try: |
483 | 485 | return executor(x, timestep, context, transformer_options, **kwargs) |
484 | 486 | finally: |
@@ -540,12 +542,15 @@ def __init__(self, control_patch, block_index, previous): |
540 | 542 | self.previous = previous |
541 | 543 |
|
542 | 544 | def __call__(self, args, extra_args): |
543 | | - self.control_patch.before_block(self.block_index, args) |
| 545 | + # Control state must stay outside the base block's allocation scope. |
| 546 | + with comfy.model_prefetch.pause_malloc_graph(): |
| 547 | + self.control_patch.before_block(self.block_index, args) |
544 | 548 | if self.previous is None: |
545 | 549 | out = extra_args["original_block"](args) |
546 | 550 | else: |
547 | 551 | out = self.previous(args, extra_args) |
548 | | - return self.control_patch.after_block(self.block_index, args, out) |
| 552 | + with comfy.model_prefetch.pause_malloc_graph(): |
| 553 | + return self.control_patch.after_block(self.block_index, args, out) |
549 | 554 |
|
550 | 555 | def to(self, device_or_dtype): |
551 | 556 | self.control_patch.to(device_or_dtype) |
|
0 commit comments