Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: ValueError: Key epoch is invalid, expected torch.Tensor but received <class 'int'> #895

Closed
1 task done
alelordelo opened this issue Apr 18, 2023 · 2 comments
Closed
1 task done

Comments

@alelordelo
Copy link

Is there an existing issue for this?

  • I have searched the existing issues and checked the recent builds/commits of both this extension and the webui

What happened?

Tried to extract a ControlNet and got an error.

Steps to reproduce the problem

  1. Run this:
    !python extract_controlnet.py --src "/content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/models/epoch=76-step=38576.ckpt" --dst "/content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/models/latestconverted.safetensors"
    .
    2.got this:
    Traceback (most recent call last):
    File "/content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/extract_controlnet.py", line 25, in
    save_file(state_dict, args.dst)
    File "/usr/local/lib/python3.9/dist-packages/safetensors/torch.py", line 71, in save_file
    serialize_file(_flatten(tensors), filename, metadata=metadata)
    File "/usr/local/lib/python3.9/dist-packages/safetensors/torch.py", line 221, in _flatten
    raise ValueError(f"Key {k} is invalid, expected torch.Tensor but received {type(v)}")
    ValueError: Key epoch is invalid, expected torch.Tensor but received <class 'int'>

What should have happened?

Should have extracted the safetensor

Commit where the problem happens

webui:
controlnet: [20a5310]

What browsers do you use to access the UI ?

Apple Safari

Command Line Arguments

!python extract_controlnet.py --src "/content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/models/epoch=76-step=38576.ckpt" --dst "/content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/models/latestconverted.safetensors"

Console logs

Traceback (most recent call last):
  File "/content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/extract_controlnet.py", line 25, in <module>
    save_file(state_dict, args.dst)
  File "/usr/local/lib/python3.9/dist-packages/safetensors/torch.py", line 71, in save_file
    serialize_file(_flatten(tensors), filename, metadata=metadata)
  File "/usr/local/lib/python3.9/dist-packages/safetensors/torch.py", line 221, in _flatten
    raise ValueError(f"Key `{k}` is invalid, expected torch.Tensor but received {type(v)}")
ValueError: Key `epoch` is invalid, expected torch.Tensor but received <class 'int'>

Additional information

No response

@alelordelo
Copy link
Author

fixed with this:
!python extract_controlnet.py --src "/content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/models/epoch=76-step=38576.ckpt" --dst "/content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/models/latestconverted.ckpt"

@alelordelo
Copy link
Author

alelordelo commented Apr 18, 2023

actually, not sure if the comment above fixed the issue...

The latestconverted.ckpt model has the same size of epoch=76-step=38576.ckpt, which is 8.5GB.

Shouldn't this reduce the file size?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants