PromptEnhancer error: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
using prompt enhancer causes me this error below
loaded completely 5757.675 5757.673828125 False
!!! Exception during processing !!! Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument index in method wrapper_CUDA__index_select)
Traceback (most recent call last):
File "C:\Users\Gumayusi\AppData\Local\Programs\@comfyorgcomfyui-electron\resources\ComfyUI\execution.py", line 345, in execute
output_data, output_ui, has_subgraph = get_output_data(obj, input_data_all, execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Gumayusi\AppData\Local\Programs\@comfyorgcomfyui-electron\resources\ComfyUI\execution.py", line 220, in get_output_data
return_values = _map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True, execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Gumayusi\AppData\Local\Programs\@comfyorgcomfyui-electron\resources\ComfyUI\execution.py", line 192, in _map_node_over_list
process_inputs(input_dict, i)
File "C:\Users\Gumayusi\AppData\Local\Programs\@comfyorgcomfyui-electron\resources\ComfyUI\execution.py", line 181, in process_inputs
results.append(getattr(obj, func)(**inputs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\Users\Gumayusi\Documents\ComfyUI\custom_nodes\ComfyUI-LTXVideo\prompt_enhancer_nodes.py", line 202, in enhance
enhanced_prompt = model(prompt, image_conditioning, max_resulting_tokens)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\Users\Gumayusi\Documents\ComfyUI\.venv\Lib\site-packages\torch\nn\modules\module.py", line 1739, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\Users\Gumayusi\Documents\ComfyUI\.venv\Lib\site-packages\torch\nn\modules\module.py", line 1750, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\Users\Gumayusi\Documents\ComfyUI\custom_nodes\ComfyUI-LTXVideo\prompt_enhancer_nodes.py", line 42, in forward
enhanced_prompt = generate_cinematic_prompt(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\Users\Gumayusi\Documents\ComfyUI\custom_nodes\ComfyUI-LTXVideo\prompt_enhancer_utils.py", line 110, in generate_cinematic_prompt
prompts = _generate_i2v_prompt(
^^^^^^^^^^^^^^^^^^^^^
File "E:\Users\Gumayusi\Documents\ComfyUI\custom_nodes\ComfyUI-LTXVideo\prompt_enhancer_utils.py", line 175, in _generate_i2v_prompt
image_captions = _generate_image_captions(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\Users\Gumayusi\Documents\ComfyUI\custom_nodes\ComfyUI-LTXVideo\prompt_enhancer_utils.py", line 214, in _generate_image_captions
generated_ids = image_caption_model.generate(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Gumayusi\.cache\huggingface\modules\transformers_modules\Florence-2-large-PromptGen-v2.0\modeling_florence2.py", line 2790, in generate
inputs_embeds = self.get_input_embeddings()(input_ids)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\Users\Gumayusi\Documents\ComfyUI\.venv\Lib\site-packages\torch\nn\modules\module.py", line 1739, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\Users\Gumayusi\Documents\ComfyUI\.venv\Lib\site-packages\torch\nn\modules\module.py", line 1750, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\Users\Gumayusi\Documents\ComfyUI\.venv\Lib\site-packages\torch\nn\modules\sparse.py", line 190, in forward
return F.embedding(
^^^^^^^^^^^^
File "E:\Users\Gumayusi\Documents\ComfyUI\.venv\Lib\site-packages\torch\nn\functional.py", line 2551, in embedding
return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument index in method wrapper_CUDA__index_select)
ComfyUI with LTXV Prompt Enhancer If you're encountering the following error when using the LTXV Prompt Enhancer node in ComfyUI: "RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! Here’s a clear step-by-step guide to fix it permanently."
Why This Happens The root cause is that the models (image_caption_model and llm_model) are not explicitly moved to the correct device (e.g., CUDA) when loaded. As a result, some tensors remain on CPU while others are on GPU, leading to the device mismatch error.
✅ Solution You need to update the code so that both models are moved to the correct device right after loading. Here’s how:
✍️ Edit prompt_enhancer_nodes.py Find the following two functions:
🔹 down_load_llm_model(...) Update it like this:
def down_load_llm_model(self, llm_name, load_device):
model_path = self.model_path_download_if_needed(llm_name)
llm_model = AutoModelForCausalLM.from_pretrained(
model_path,
torch_dtype=torch.bfloat16,
).to(load_device) # ✅ Move model to correct device
llm_tokenizer = AutoTokenizer.from_pretrained(
model_path,
)
return llm_model, llm_tokenizer
down_load_image_captioner(...) Update it like this:
def down_load_image_captioner(self, image_captioner, load_device):
model_path = self.model_path_download_if_needed(image_captioner)
image_caption_model = AutoModelForCausalLM.from_pretrained(
model_path, trust_remote_code=True
).to(load_device) # ✅ Move model to correct device
image_caption_processor = AutoProcessor.from_pretrained(
model_path, trust_remote_code=True
)
return image_caption_model, image_caption_processor
prompt_enhancer_nodes.py
i follow your method but still got the error