Need advice: PytorchStreamReader failed reading zip archive

Hello!
I’m new to this and I’m trying to get SD running on my local Windows 10 machine in an Anaconda Powershell Prompt. I’ve been sorting out dependencies but I’ve run into an error I can’t figure out:

(ldm) PS C:\Users\dev_w\Documents\GitHub\stable-diffusion> python scripts/txt2img.py --prompt "prompt in space" --plms --ckpt sd-v1-4.ckpt --skip_grid --n_samples 1
Global seed set to 42
Loading model from sd-v1-4.ckpt
Traceback (most recent call last):
  File "scripts/txt2img.py", line 352, in <module>
    main()
  File "scripts/txt2img.py", line 246, in main
    model = load_model_from_config(config, f"{opt.ckpt}")
  File "scripts/txt2img.py", line 51, in load_model_from_config
    pl_sd = torch.load(ckpt, map_location="cpu")
  File "C:\Users\dev_w\miniconda3\envs\ldm\lib\site-packages\torch\serialization.py", line 705, in load
    with _open_zipfile_reader(opened_file) as opened_zipfile:
  File "C:\Users\dev_w\miniconda3\envs\ldm\lib\site-packages\torch\serialization.py", line 243, in __init__
    super(_open_zipfile_reader, self).__init__(torch._C.PyTorchFileReader(name_or_buffer))
RuntimeError: PytorchStreamReader failed reading zip archive: invalid header or archive is corrupted

I’m not sure what zip file it’s trying to read. I re-downloaded sd-v1-4.ckpt but it didn’t help. Here’s the output from transformers-cli.exe env:

(ldm) PS C:\Users\dev_w\Documents\GitHub\stable-diffusion> transformers-cli.exe env
Traceback (most recent call last):
  File "c:\users\dev_w\miniconda3\envs\ldm\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\dev_w\miniconda3\envs\ldm\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\dev_w\miniconda3\envs\ldm\Scripts\transformers-cli.exe\__main__.py", line 4, in <module>
  File "c:\users\dev_w\miniconda3\envs\ldm\lib\site-packages\transformers\commands\transformers_cli.py", line 26, in <module>
    from .user import UserCommands
  File "c:\users\dev_w\miniconda3\envs\ldm\lib\site-packages\transformers\commands\user.py", line 20, in <module>
    from huggingface_hub.hf_api import HfFolder, create_repo, login, logout, whoami
ImportError: cannot import name 'login' from 'huggingface_hub.hf_api' (c:\users\dev_w\miniconda3\envs\ldm\lib\site-packages\huggingface_hub\hf_api.py)

Any help is appreciated!

Did you manage to solve this? have same problem too

No, not yet. I haven’t been able to get anyone to respond to me.

I fixed a similar issue for myself recently by doing the following:

  1. Open python file @
    File "C:\Users\dev_w\miniconda3\envs\ldm\lib\site-packages\torch\serialization.py", line 243, in __init__

  2. Scroll to line 243, mine looked like this:

class _open_zipfile_reader(_opener):
    def __init__(self, name_or_buffer) -> None:
        super().__init__(torch._C.PyTorchFileReader(name_or_buffer))
  1. Added some prints to find out which file wasn’t loading:
class _open_zipfile_reader(_opener):
    def __init__(self, name_or_buffer) -> None:
        print('*******************************************')
        print(name_or_buffer)
        print('*******************************************')
        super().__init__(torch._C.PyTorchFileReader(name_or_buffer))
  1. Re run the command and I see the filename in the output (yours will be different since we are playing with different models):
*******************************************
<_io.BufferedReader name='/home/user/.cache/audioldm/audioldm-s-full.ckpt'>
*******************************************
  1. This file audioldm-s-full.ckpt (the model file) was corrupt, so I deleted it and the next time I ran the command, the model re-downloaded.

Hope this helps!

4 Likes

Oh my god, You are a savior. Thanks a lot!!!