Comfy-Org / Comfy-Org/ComfyUI

Meta Tensor Device Transition Error by Using to_empty() in ComfyUI

Open
#13,635 1 comment 0 reactions 1 assignee Claimed by @rattus128 View on GitHub
User Support
Dominant language
Python
Stars
133k
Forks
15.7k
Avg merge
1d 6h
Merged PRs (30d)
155

Description

### Custom Node Testing

- [x] I have tried disabling custom nodes and the issue persists (see [how to disable custom nodes](https://docs.comfy.org/troubleshooting/custom-node-issues#step-1%3A-test-with-all-custom-nodes-disabled) if you need help)

### Your question

Has anyone run into the "Cannot copy out of meta tensor; no data!" error when shifting models between devices in ComfyUI? I’ve tried using to_empty() as suggested but still can’t get it working smoothly. I’d love to know if someone has successfully resolved this or has any insights on handling meta tensor transitions.

### Logs

```powershell
NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty() instead of torch.nn.Module.to() when moving module from meta to a different device.

File "/Applications/ComfyUI.app/Contents/Resources/ComfyUI/execution.py", line 534, in execute
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)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/Applications/ComfyUI.app/Contents/Resources/ComfyUI/execution.py", line 334, in get_output_data
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)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/Applications/ComfyUI.app/Contents/Resources/ComfyUI/execution.py", line 308, in _async_map_node_over_list
await process_inputs(input_dict, i)

File "/Applications/ComfyUI.app/Contents/Resources/ComfyUI/execution.py", line 296, in process_inputs
result = f(**inputs)
^^^^^^^^^^^

File "/Applications/ComfyUI.app/Contents/Resources/ComfyUI/comfy_api/internal/__init__.py", line 149, in wrapped_func
return method(locked_class, **inputs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/Applications/ComfyUI.app/Contents/Resources/ComfyUI/comfy_api/latest/_io.py", line 1826, in EXECUTE_NORMALIZED
to_return = cls.execute(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/Users/Nik_1/Documents/ComfyUI/custom_nodes/comfyui-sam3/nodes/sam3_interactive.py", line 669, in execute
comfy.model_management.load_models_gpu([sam3_model])

File "/Applications/ComfyUI.app/Contents/Resources/ComfyUI/comfy/model_management.py", line 820, in load_models_gpu
loaded_model.model_load(lowvram_model_memory, force_patch_weights=force_patch_weights)

File "/Applications/ComfyUI.app/Contents/Resources/ComfyUI/comfy/model_management.py", line 582, in model_load
self.model_use_more_vram(use_more_vram, force_patch_weights=force_patch_weights)

File "/Applications/ComfyUI.app/Contents/Resources/ComfyUI/comfy/model_management.py", line 613, in model_use_more_vram
return self.model.partially_load(self.device, extra_memory, force_patch_weights=force_patch_weights)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/Applications/ComfyUI.app/Contents/Resources/ComfyUI/comfy/model_patcher.py", line 1066, in partially_load
self.detach()

File "/Applications/ComfyUI.app/Contents/Resources/ComfyUI/comfy/model_patcher.py", line 1082, in detach
self.unpatch_model(self.offload_device, unpatch_weights=unpatch_all)

File "/Users/Nik_1/Documents/ComfyUI/custom_nodes/comfyui-sam3/nodes/sam3_model_patcher.py", line 92, in unpatch_model
super().unpatch_model(device_to, unpatch_weights)

File "/Applications/ComfyUI.app/Contents/Resources/ComfyUI/comfy/model_patcher.py", line 943, in unpatch_model
self.model.to(device_to)

File "/Users/Nik_1/Documents/ComfyUI/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1371, in to
return self._apply(convert)
^^^^^^^^^^^^^^^^^^^^

File "/Users/Nik_1/Documents/ComfyUI/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 930, in _apply
module._apply(fn)

File "/Users/Nik_1/Documents/ComfyUI/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 930, in _apply
module._apply(fn)

File "/Users/Nik_1/Documents/ComfyUI/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 930, in _apply
module._apply(fn)

[Previous line repeated 3 more times]

File "/Users/Nik_1/Documents/ComfyUI/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 957, in _apply
param_applied = fn(param)
^^^^^^^^^

File "/Users/Nik_1/Documents/ComfyUI/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1364, in convert
raise NotImplementedError(
```

### Other

NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty() instead of torch.nn.Module.to() when moving module from meta to a different device.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.