kijai / ComfyUI-FluxTrainer

Apache License 2.0
492 stars 27 forks source link

extract flux lora report "File does not contain tensor double_blocks.0.img_attn.proj.weight" error #65

Open deepfree2023 opened 2 months ago

deepfree2023 commented 2 months ago

image

Traceback (most recent call last): File "K:\ComfyUI_windows_portable\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 "K:\ComfyUI_windows_portable\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 "K:\ComfyUI_windows_portable\ComfyUI\execution.py", line 169, in _map_node_over_list process_inputs(input_dict, i) File "K:\ComfyUI_windows_portable\ComfyUI\execution.py", line 158, in process_inputs results.append(getattr(obj, func)(**inputs)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "K:\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-FluxTrainer\nodes.py", line 1542, in extract outpath = svd( ^^^^ File "K:\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-FluxTrainer\flux_extract_lora.py", line 87, in svd value_t = ft.get_tensor(key) ^^^^^^^^^^^^^^^^^^ safetensors_rust.SafetensorError: File does not contain tensor double_blocks.0.img_attn.proj.weight

kijai commented 2 months ago

Where is that finetuned model from? I think the underlaying kohya script only supports LoRAs trained with kohya.

deepfree2023 commented 2 months ago

From civitai, is it possible to make this node universal to support extracting other LORAs?

kijai commented 2 months ago

Everything is possible, but for this I wouldn't know how.... Comfy has added more generic LoRa extract node into comfyui though, maybe try that.

bananasss00 commented 1 month ago

Everything is possible, but for this I wouldn't know how.... Comfy has added more generic LoRa extract node into comfyui though, maybe try that.

I encountered a situation with such a model. The issue turned out to be simple: the model had a prefix "model.diffusion_model.", while the original model did not have this prefix. As a result, the LoRA extractor could not match the keys of the two models.

This can be resolved by, for example, modifying the code as follows:

with open_fn(model_tuned) as f_tuned:
    for key in tqdm(keys):
        key2 = key if key in f_tuned.keys() else 'model.diffusion_model.' + key

        if key2 not in f_tuned.keys():
            print(f'{key} not found')
            continue

        # get tensors and calculate difference
        value_o = f_org.get_tensor(key)
        value_t = f_tuned.get_tensor(key2)
retronomi commented 2 days ago

Everything is possible, but for this I wouldn't know how.... Comfy has added more generic LoRa extract node into comfyui though, maybe try that.

I encountered a situation with such a model. The issue turned out to be simple: the model had a prefix "model.diffusion_model.", while the original model did not have this prefix. As a result, the LoRA extractor could not match the keys of the two models.

This can be resolved by, for example, modifying the code as follows:

with open_fn(model_tuned) as f_tuned:
    for key in tqdm(keys):
        key2 = key if key in f_tuned.keys() else 'model.diffusion_model.' + key

        if key2 not in f_tuned.keys():
            print(f'{key} not found')
            continue

        # get tensors and calculate difference
        value_o = f_org.get_tensor(key)
        value_t = f_tuned.get_tensor(key2)

Was having this issue in kohya_ss and this worked for me, thanks!