Skip to content

Lora converter block fails on windows due to "could not open file in read-only mode" error #176

Closed
@maxious

Description

@maxious

Trying load a local Lora

  File "C:\ComfyUI\custom_nodes\svdquant\nodes\lora\flux.py", line 115, in load_lora
    model.model.diffusion_model.model.update_lora_params(tmp_file.name)
  File "C:\ComfyUI\venv\Lib\site-packages\nunchaku\utils.py", line 50, in load_state_dict_in_safetensors
    with safetensors.safe_open(fetch_or_download(path), framework="pt", device=device) as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: could not open file <C:\Users\user\AppData\Local\Temp\tmpw303rs9q.safetensors> in read-only mode; error code: <32>

I think error code 32 is "The process cannot access the file because it is being used by another process." because tempfile is waiting for the variable to go out of scope to delete the tempfile so it keeps the file handle open.

Workaround: switch with tempfile.NamedTemporaryFile(suffix=".safetensors", delete=False) to with tempfile.NamedTemporaryFile(suffix=".safetensors", delete=True) in lora\flux.py. The error then does not happen at the expense of leaving some tempfiles on disk

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions