huchenlei / ComfyUI_omost

ComfyUI implementation of Omost
Apache License 2.0
407 stars 28 forks source link

AssertionError of `assert len(comfy_tokens) == 1` #16

Closed mymusise closed 3 months ago

mymusise commented 3 months ago

Hi, I got a error when I running the workflow:

!!! Exception during processing!!! 
Traceback (most recent call last):
  File "/root/ComfyUI/execution.py", line 151, in recursive_execute
    output_data, output_ui = get_output_data(obj, input_data_all)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/ComfyUI/execution.py", line 81, in get_output_data
    return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/ComfyUI/execution.py", line 74, in map_node_over_list
    results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/ComfyUI/custom_nodes/ComfyUI_omost/omost_nodes.py", line 429, in layout_cond
    cond: ComfyUIConditioning = self.encode_bag_of_subprompts_greedy(
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/ComfyUI/custom_nodes/ComfyUI_omost/omost_nodes.py", line 348, in encode_bag_of_subprompts_greedy
    encoder_output = encode_bag_of_subprompts_greedy(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/ComfyUI/custom_nodes/ComfyUI_omost/lib_omost/greedy_encode.py", line 118, in encode_bag_of_subprompts_greedy
    suffix_targets: list[CLIPTokens] = [
                                       ^
  File "/root/ComfyUI/custom_nodes/ComfyUI_omost/lib_omost/greedy_encode.py", line 119, in <listcomp>
    tokenize_func(subprompt) for subprompt in suffixes
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/ComfyUI/custom_nodes/ComfyUI_omost/omost_nodes.py", line 336, in tokenize
    clip_l_tokens=convert_comfy_tokens(tokens["l"]),
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/ComfyUI/custom_nodes/ComfyUI_omost/omost_nodes.py", line 317, in convert_comfy_tokens
    assert len(comfy_tokens) == 1
           ^^^^^^^^^^^^^^^^^^^^^^
AssertionError
mymusise commented 3 months ago

I found that when the subprompt exceeds 75 tokens, clip.tokenize will return ids with a length > 1. The official approach is also to take only the first 75 tokens, so I think it's sufficient if the length of comfy_tokens is >= 1.