Skip to content

Expected all tensors to be on same device error in comfy++ mode #35

Open
@NeedsMoar

Description

@NeedsMoar

When set to comfy++ mode (normalization mode doesn't matter, all other interpretations work with the same prompt although some don't give good outputs because the weighting is all wrong), the following error is thrown. Unfortunately the majority of my workflows have this setup. I tried swapping in the smZ CLIP Text Encode++, but it somehow reshapes the CLIP tensor to from 768 to 1024 and breaks SD 1.5 textual embeddings with nothing but a message on the command prompt. Not to mention it's a pain to switch out nodes depending on how things were wired up.

I haven't tried it but I'm guessing this occurs because the creation of ws is

ws = []

Rather than as a tensor so it's starting on the CPU for some reason, and it probably just needs to have a .to(device=base_emb.device) slapped on the end of line 106 to make sure it's on the GPU.

The error is:

!!! Exception during processing !!! Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
Traceback (most recent call last):
  File "C:\Programs\ComfyUI\execution.py", line 323, 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:\Programs\ComfyUI\execution.py", line 198, 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:\Programs\ComfyUI\execution.py", line 169, in _map_node_over_list
    process_inputs(input_dict, i)
  File "C:\Programs\ComfyUI\execution.py", line 158, in process_inputs
    results.append(getattr(obj, func)(**inputs))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Programs\ComfyUI\custom_nodes\ComfyUI_ADV_CLIP_emb\nodes.py", line 21, in encode
    embeddings_final, pooled = advanced_encode(clip, text, token_normalization, weight_interpretation, w_max=1.0, apply_to_pooled=affect_pooled=='enable')
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Programs\ComfyUI\custom_nodes\ComfyUI_ADV_CLIP_emb\adv_encode.py", line 266, in advanced_encode
    return advanced_encode_from_tokens(tokenized['l'],
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Programs\ComfyUI\custom_nodes\ComfyUI-ppm\compat\advanced_encode.py", line 46, in advanced_encode_from_tokens_negpip
    weighted_emb, pooled = advanced_encode_from_tokens(
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Programs\ComfyUI\custom_nodes\ComfyUI_ADV_CLIP_emb\adv_encode.py", line 203, in advanced_encode_from_tokens
    embs, pooled = from_masked(unweighted_tokens, weights, word_ids, base_emb, length, encode_func)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Programs\ComfyUI\custom_nodes\ComfyUI_ADV_CLIP_emb\adv_encode.py", line 107, in from_masked
    pooled = (pooled - pooled_start) * (ws - 1)
             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions