Skip to content

SwarmTiling crashes ComfyUI due to unsafe copy.deepcopy(ModelPatcher) (should use model.clone()) #1276

@vertigoelectric

Description

@vertigoelectric

Expected Behavior

Expected Behavior

When enabling seamless tiling via the built-in SwarmTiling node (X and/or Y tiling), image generation should complete successfully and produce tileable output without errors or backend crashes. The ComfyUI backend should remain stable, and the tiling operation should work consistently across models and resolutions, as it did in prior versions.

Actual Behavior

Actual Behavior

When generating images with seamless tiling enabled (using the SwarmTiling node), the ComfyUI backend crashes during execution. Generation fails with a Python traceback originating from src/BuiltinExtensions/ComfyUIBackend/ExtraNodes/SwarmComfyCommon/SwarmTiling.py, specifically at the line that attempts to duplicate the model using copy.deepcopy(model).

The error consistently manifests as:

  • TypeError: 'NoneType' object is not callable during copy.deepcopy
  • Followed by cleanup errors such as AttributeError: 'ModelPatcher' object has no attribute 'pinned'

This occurs even after:

  • Updating SwarmUI to the latest version (including 0.9.8-Beta)
  • Rebuilding SwarmUI from source
  • Testing with multiple SDXL models (e.g. JuggernautXL Lightning)
  • Verifying a clean, isolated Python environment

As a workaround, bypassing the SwarmTiling node entirely and manually setting width/height (or injecting UI buttons via Tampermonkey) allows generation to succeed, indicating the failure is specific to the SwarmTiling implementation rather than the model or environment.

Steps to Reproduce

Steps to Reproduce

  1. Launch SwarmUI (latest version tested, including 0.9.8-Beta) with the default ComfyUI self-start backend.
  2. Select an SDXL-based checkpoint (for example: juggernautXL_juggXILightningByRD.safetensors).
  3. Enable Seamless Tileable in the SwarmUI interface (this routes through the SwarmTiling node).
  4. Use any resolution or aspect ratio (issue occurs regardless of whether standard ratios or custom large resolutions are used).
  5. Start image generation.

Result:

  • Generation fails during execution.
  • ComfyUI throws a traceback in SwarmTiling.py at the copy.deepcopy(model) call.
  • The backend process exits or aborts the job with the NoneType / ModelPatcher errors described in Actual Behavior.

Notes:

  • Disabling seamless tiling allows the same prompt, model, and resolution to generate successfully.
  • The issue reproduces reliably and is not tied to a specific checkpoint, prompt, or resolution.

Debug Logs

05:08:32.435 [Info] Creating new session 'local' for ::1
05:09:12.712 [Warning] [ComfyUI-0/STDERR] Traceback (most recent call last):
05:09:12.713 [Warning] [ComfyUI-0/STDERR]   File "I:\ai\SwarmUI\dlbackend\comfy\ComfyUI\execution.py", line 527, in execute
05:09:12.714 [Warning] [ComfyUI-0/STDERR]     output_data, output_ui, has_subgraph, has_pending_tasks = await get_output_data(prompt_id, unique_id, obj, input_data_all, execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb, v3_data=v3_data)
05:09:12.715 [Warning] [ComfyUI-0/STDERR]   File "I:\ai\SwarmUI\dlbackend\comfy\ComfyUI\execution.py", line 331, in get_output_data
05:09:12.716 [Warning] [ComfyUI-0/STDERR]     return_values = await _async_map_node_over_list(prompt_id, unique_id, obj, input_data_all, obj.FUNCTION, allow_interrupt=True, execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb, v3_data=v3_data)
05:09:12.716 [Warning] [ComfyUI-0/STDERR]   File "I:\ai\SwarmUI\dlbackend\comfy\ComfyUI\execution.py", line 305, in _async_map_node_over_list
05:09:12.717 [Warning] [ComfyUI-0/STDERR]     await process_inputs(input_dict, i)
05:09:12.718 [Warning] [ComfyUI-0/STDERR]   File "I:\ai\SwarmUI\dlbackend\comfy\ComfyUI\execution.py", line 293, in process_inputs
05:09:12.719 [Warning] [ComfyUI-0/STDERR]     result = f(**inputs)
05:09:12.720 [Warning] [ComfyUI-0/STDERR]   File "I:\ai\SwarmUI\src\BuiltinExtensions\ComfyUIBackend\ExtraNodes\SwarmComfyCommon\SwarmTiling.py", line 45, in adapt
05:09:12.721 [Warning] [ComfyUI-0/STDERR]     m = copy.deepcopy(model)
05:09:12.722 [Warning] [ComfyUI-0/STDERR]   File "C:\Users\vertigo\AppData\Local\Programs\Python\Python310\lib\copy.py", line 172, in deepcopy
05:09:12.723 [Warning] [ComfyUI-0/STDERR]     y = _reconstruct(x, memo, *rv)
05:09:12.724 [Warning] [ComfyUI-0/STDERR]   File "C:\Users\vertigo\AppData\Local\Programs\Python\Python310\lib\copy.py", line 271, in _reconstruct
05:09:12.724 [Warning] [ComfyUI-0/STDERR]     state = deepcopy(state, memo)
05:09:12.725 [Warning] [ComfyUI-0/STDERR]   File "C:\Users\vertigo\AppData\Local\Programs\Python\Python310\lib\copy.py", line 146, in deepcopy
05:09:12.726 [Warning] [ComfyUI-0/STDERR]     y = copier(x, memo)
05:09:12.727 [Warning] [ComfyUI-0/STDERR]   File "C:\Users\vertigo\AppData\Local\Programs\Python\Python310\lib\copy.py", line 231, in _deepcopy_dict
05:09:12.728 [Warning] [ComfyUI-0/STDERR]     y[deepcopy(key, memo)] = deepcopy(value, memo)
05:09:12.729 [Warning] [ComfyUI-0/STDERR]   File "C:\Users\vertigo\AppData\Local\Programs\Python\Python310\lib\copy.py", line 172, in deepcopy
05:09:12.730 [Warning] [ComfyUI-0/STDERR]     y = _reconstruct(x, memo, *rv)
05:09:12.731 [Warning] [ComfyUI-0/STDERR]   File "C:\Users\vertigo\AppData\Local\Programs\Python\Python310\lib\copy.py", line 271, in _reconstruct
05:09:12.735 [Warning] [ComfyUI-0/STDERR]     state = deepcopy(state, memo)
05:09:12.736 [Warning] [ComfyUI-0/STDERR]   File "C:\Users\vertigo\AppData\Local\Programs\Python\Python310\lib\copy.py", line 146, in deepcopy
05:09:12.737 [Warning] [ComfyUI-0/STDERR]     y = copier(x, memo)
05:09:12.738 [Warning] [ComfyUI-0/STDERR]   File "C:\Users\vertigo\AppData\Local\Programs\Python\Python310\lib\copy.py", line 231, in _deepcopy_dict
05:09:12.738 [Warning] [ComfyUI-0/STDERR]     y[deepcopy(key, memo)] = deepcopy(value, memo)
05:09:12.739 [Warning] [ComfyUI-0/STDERR]   File "C:\Users\vertigo\AppData\Local\Programs\Python\Python310\lib\copy.py", line 161, in deepcopy
05:09:12.740 [Warning] [ComfyUI-0/STDERR]     rv = reductor(4)
05:09:12.740 [Warning] [ComfyUI-0/STDERR] TypeError: 'NoneType' object is not callable
05:09:12.741 [Warning] [ComfyUI-0/STDERR]
05:09:18.580 [Warning] [ComfyUI-0/STDERR] Traceback (most recent call last):
05:09:18.581 [Warning] [ComfyUI-0/STDERR]   File "I:\ai\SwarmUI\dlbackend\comfy\ComfyUI\comfy\model_patcher.py", line 1406, in __del__
05:09:18.597 [Warning] [ComfyUI-0/STDERR]     self.unpin_all_weights()
05:09:18.598 [Warning] [ComfyUI-0/STDERR]   File "I:\ai\SwarmUI\dlbackend\comfy\ComfyUI\comfy\model_patcher.py", line 680, in unpin_all_weights
05:09:18.598 [Warning] [ComfyUI-0/STDERR]     for key in list(self.pinned):
05:09:18.599 [Warning] [ComfyUI-0/STDERR] AttributeError: 'ModelPatcher' object has no attribute 'pinned'```

### Other

Portions of this report were drafted with the assistance of an AI tool for clarity and organization. All testing, reproduction, and logs are from a real local SwarmUI setup.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions