StartHua / Comfyui_CXH_joy_caption

Recommended based on comfyui node pictures:Joy_caption + MiniCPMv2_6-prompt-generator + florence2
Apache License 2.0
446 stars 26 forks source link

ValueError: list.remove(x): x not in list -- Error when using Florence models #79

Open patriciagomesoo opened 2 months ago

patriciagomesoo commented 2 months ago

Hello, I get this error after an update, when loading any Florence 2 models, like Cog or Base. It used to work perfect but now it gives this error:

FETCH DATA from: C:\Users\GABSU\ComfyUI\custom_nodes\ComfyUI-Manager\extension-node-map.json [DONE] got prompt using sdpa for attention !!! Exception during processing !!! list.remove(x): x not in list Traceback (most recent call last): File "C:\Users\GABSU\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:\Users\GABSU\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:\Users\GABSU\ComfyUI\execution.py", line 169, in _map_node_over_list process_inputs(input_dict, i) File "C:\Users\GABSU\ComfyUI\execution.py", line 158, in process_inputs results.append(getattr(obj, func)(**inputs)) File "C:\Users\GABSU\ComfyUI\custom_nodes\Comfyui_CXH_joy_caption\florence_nodes.py", line 92, in loadmodel model = AutoModelForCausalLM.from_pretrained(model_path, attn_implementation=attention, device_map=device, torch_dtype=dtype,trust_remote_code=True) File "C:\Users\GABSU\ComfyUI\venv\lib\site-packages\transformers\models\auto\auto_factory.py", line 553, in from_pretrained model_class = get_class_from_dynamic_module( File "C:\Users\GABSU\ComfyUI\venv\lib\site-packages\transformers\dynamic_module_utils.py", line 540, in get_class_from_dynamic_module final_module = get_cached_module_file( File "C:\Users\GABSU\ComfyUI\venv\lib\site-packages\transformers\dynamic_module_utils.py", line 365, in get_cached_module_file modules_needed = check_imports(resolved_module_file) File "C:\Users\GABSU\ComfyUI\venv\lib\site-packages\transformers\dynamic_module_utils.py", line 181, in check_imports imports = get_imports(filename) File "C:\Users\GABSU\ComfyUI\custom_nodes\Comfyui_CXH_joy_caption\florence_nodes.py", line 26, in fixed_get_imports imports.remove("flash_attn") ValueError: list.remove(x): x not in list


Someone has any ideas how to fix this? Thank you :)

best1923 commented 1 month ago

In the File "C:\Users\GABSU\ComfyUI\custom_nodes\Comfyui_CXH_joy_caption\florence_nodes.py", line 26, in fixed_get_imports imports.remove("flash_attn") change the imports.remove("flash_attn") to if "flash_attn" in imports: imports.remove("flash_attn")

mirek190 commented 1 month ago

It should look like that :

ComfyUI\custom_nodes\Comfyui_CXH_joy_caption\florence_nodes.py

def fixed_get_imports(filename: str | os.PathLike) -> list[str]:
    if not str(filename).endswith("modeling_florence2.py"):
        return get_imports(filename)
    imports = get_imports(filename)
    if "flash_attn" in imports:
        imports.remove("flash_attn")
    return imports
Poukpalaova commented 1 month ago

That worked for my, thanks at @mirek190