stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

[Bug]: Error when loading v-pred model on dev branch

Open quicks1lver42 opened this issue 11 months ago • 4 comments

Checklist

  • [ ] The issue exists after disabling all extensions
  • [ ] The issue exists on a clean installation of webui
  • [ ] The issue is caused by an extension, but I believe it is caused by a bug in the webui
  • [ ] The issue exists in the current version of the webui
  • [X] The issue has not been reported before recently
  • [ ] The issue has been reported before but has not been fixed yet

What happened?

An error is thrown when trying to load a v-pred model using the dev branch.

Steps to reproduce the problem

  1. Pull dev branch
  2. Start WebUI
  3. Try to load v-pred model

What should have happened?

WebUI should successfully load the model.

What browsers do you use to access the UI ?

Mozilla Firefox

Sysinfo

•  version: [v1.10.1-42-g7799859f] •  python: 3.10.6   •  torch: 2.3.0+cu121   •  xformers: 0.0.26.post1   •  gradio: 3.41.2  

Console logs

changing setting sd_model_checkpoint to noobaiXLNAIXL_vPred05Version.safetensors [78748f163e]: ValueError
Traceback (most recent call last):
  File "A:\AI\stable-diffusion-webui\modules\options.py", line 165, in set
    option.onchange()
  File "A:\AI\stable-diffusion-webui\modules\call_queue.py", line 14, in f
    res = func(*args, **kwargs)
  File "A:\AI\stable-diffusion-webui\modules\initialize_util.py", line 181, in <lambda>
    shared.opts.onchange("sd_model_checkpoint", wrap_queued_call(lambda: sd_models.reload_model_weights()), call=False)
  File "A:\AI\stable-diffusion-webui\modules\sd_models.py", line 972, in reload_model_weights
    state_dict = get_checkpoint_state_dict(checkpoint_info, timer)
  File "A:\AI\stable-diffusion-webui\modules\sd_models.py", line 344, in get_checkpoint_state_dict
    res = read_state_dict(checkpoint_info.filename)
  File "A:\AI\stable-diffusion-webui\modules\sd_models.py", line 320, in read_state_dict
    pl_sd = safetensors.torch.load(open(checkpoint_file, 'rb').read())
  File "A:\AI\stable-diffusion-webui\venv\lib\site-packages\safetensors\torch.py", line 338, in load
    return _view2torch(flat)
  File "A:\AI\stable-diffusion-webui\venv\lib\site-packages\safetensors\torch.py", line 386, in _view2torch
    arr = torch.frombuffer(v["data"], dtype=dtype).reshape(v["shape"])
ValueError: both buffer length (0) and count (-1) must not be 0

Additional information

I have tried manually loading the checkpoint using the WebUI env using Diffusers via the following snippet and it successfully loads the model and generates an image: https://huggingface.co/Laxhar/noobai-XL-Vpred-0.5#method-iv-diffusers

I've also tried loading it via the safetensors module (the thing throwing the error above) and it loads fine that way too:

import safetensors.torch
import torch

model_path = "./models/Stable-diffusion/noobaiXLNAIXL_vPred05Version.safetensors"

try:
    model = safetensors.torch.load_file(model_path, device='cuda' if torch.cuda.is_available() else 'cpu')
    print("V-pred model loaded successfully.")
except Exception as e:
    print(f"Failed to load V-pred model: {e}")

This would seem to indicate that the issue is within WebUI itself.

quicks1lver42 avatar Nov 13 '24 01:11 quicks1lver42