[Bug]: loading stable diffusion model: UnpicklingError
Checklist
- [x] The issue exists after disabling all extensions
- [x] 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
- [x] 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?
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)] Commit hash: 48a15821de768fea76e66f26df83df3fddf18f4b Installing requirements for Web UI Launching Web UI with arguments: --lowvram --precision full --no-half F:\AI\stable-diffusion-webui\system\python\lib\site-packages\urllib3\connectionpool.py:1064: InsecureRequestWarning: Unverified HTTPS request is being made to host 'api.gradio.app'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings warnings.warn( No module 'xformers'. Proceeding without it. Warning: caught exception 'Torch not compiled with CUDA enabled', memory monitor disabled LatentDiffusion: Running in eps-prediction mode DiffusionWrapper has 859.52 M params. Loading weights [e1441589a6] from F:\AI\stable-diffusion-webui\webui\models\Stable-diffusion\v1-5-pruned.ckpt loading stable diffusion model: UnpicklingError Traceback (most recent call last): File "F:\AI\stable-diffusion-webui\webui\webui.py", line 104, in initialize modules.sd_models.load_model() File "F:\AI\stable-diffusion-webui\webui\modules\sd_models.py", line 392, in load_model load_model_weights(sd_model, checkpoint_info) File "F:\AI\stable-diffusion-webui\webui\modules\sd_models.py", line 247, in load_model_weights sd = read_state_dict(checkpoint_info.filename) File "F:\AI\stable-diffusion-webui\webui\modules\sd_models.py", line 222, in read_state_dict pl_sd = torch.load(checkpoint_file, map_location=map_location or shared.weight_load_location) File "F:\AI\stable-diffusion-webui\webui\modules\safe.py", line 106, in load return load_with_extra(filename, extra_handler=global_extra_handler, *args, **kwargs) File "F:\AI\stable-diffusion-webui\webui\modules\safe.py", line 151, in load_with_extra return unsafe_torch_load(filename, *args, **kwargs) File "F:\AI\stable-diffusion-webui\system\python\lib\site-packages\torch\serialization.py", line 1470, in load raise pickle.UnpicklingError(_get_wo_message(str(e))) from None _pickle.UnpicklingError: Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint. (1) In PyTorch 2.6, we changed the default value of the
weights_onlyargument intorch.loadfromFalsetoTrue. Re-runningtorch.loadwithweights_onlyset toFalsewill likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source. (2) Alternatively, to load withweights_only=Trueplease check the recommended steps in the following error message. WeightsUnpickler error: Unsupported global: GLOBAL pytorch_lightning.callbacks.model_checkpoint.ModelCheckpoint was not an allowed global by default. Please usetorch.serialization.add_safe_globals([ModelCheckpoint])or thetorch.serialization.safe_globals([ModelCheckpoint])context manager to allowlist this global if you trust this class/function. Check the documentation of torch.load to learn more about types accepted by default with weights_only https://pytorch.org/docs/stable/generated/torch.load.html. Stable diffusion model failed to load, exiting
I searched the web for this error and got mostly answers that would add 'weights_only=True', but I don't know where to add this line of code
Steps to reproduce the problem
- run run.bat
- Error occurs
What should have happened?
WebUI should run successfully.
What browsers do you use to access the UI ?
No response
Sysinfo
I couldn't generate the file.
Console logs
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Commit hash: 48a15821de768fea76e66f26df83df3fddf18f4b
Installing requirements for Web UI
Launching Web UI with arguments: --lowvram --precision full --no-half
F:\AI\stable-diffusion-webui\system\python\lib\site-packages\urllib3\connectionpool.py:1064: InsecureRequestWarning: Unverified HTTPS request is being made to host 'api.gradio.app'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
warnings.warn(
No module 'xformers'. Proceeding without it.
Warning: caught exception 'Torch not compiled with CUDA enabled', memory monitor disabled
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Loading weights [e1441589a6] from F:\AI\stable-diffusion-webui\webui\models\Stable-diffusion\v1-5-pruned.ckpt
loading stable diffusion model: UnpicklingError
Traceback (most recent call last):
File "F:\AI\stable-diffusion-webui\webui\webui.py", line 104, in initialize
modules.sd_models.load_model()
File "F:\AI\stable-diffusion-webui\webui\modules\sd_models.py", line 392, in load_model
load_model_weights(sd_model, checkpoint_info)
File "F:\AI\stable-diffusion-webui\webui\modules\sd_models.py", line 247, in load_model_weights
sd = read_state_dict(checkpoint_info.filename)
File "F:\AI\stable-diffusion-webui\webui\modules\sd_models.py", line 222, in read_state_dict
pl_sd = torch.load(checkpoint_file, map_location=map_location or shared.weight_load_location)
File "F:\AI\stable-diffusion-webui\webui\modules\safe.py", line 106, in load
return load_with_extra(filename, extra_handler=global_extra_handler, *args, **kwargs)
File "F:\AI\stable-diffusion-webui\webui\modules\safe.py", line 151, in load_with_extra
return unsafe_torch_load(filename, *args, **kwargs)
File "F:\AI\stable-diffusion-webui\system\python\lib\site-packages\torch\serialization.py", line 1470, in load
raise pickle.UnpicklingError(_get_wo_message(str(e))) from None
_pickle.UnpicklingError: Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint.
(1) In PyTorch 2.6, we changed the default value of the `weights_only` argument in `torch.load` from `False` to `True`. Re-running `torch.load` with `weights_only` set to `False` will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source.
(2) Alternatively, to load with `weights_only=True` please check the recommended steps in the following error message.
WeightsUnpickler error: Unsupported global: GLOBAL pytorch_lightning.callbacks.model_checkpoint.ModelCheckpoint was not an allowed global by default. Please use `torch.serialization.add_safe_globals([ModelCheckpoint])` or the `torch.serialization.safe_globals([ModelCheckpoint])` context manager to allowlist this global if you trust this class/function.
Check the documentation of torch.load to learn more about types accepted by default with weights_only https://pytorch.org/docs/stable/generated/torch.load.html.
Stable diffusion model failed to load, exiting
请按任意键继续. . .
Additional information
No response
I change sd_models.py:line 222 to pl_sd = torch.load(checkpoint_file, map_location=map_location or shared.weight_load_location, weights_only=False),and I solved my problem 😄
Well, you shouldn't be using a .ckpt checkpoint nowadays anyway, much less the base v1-5-pruned checkpoint which is like 3 years old at this point...
Well, you shouldn't be using a
.ckptcheckpoint nowadays anyway, much less the basev1-5-prunedcheckpoint which is like 3 years old at this point...
Thank you, I just started using this and am not familiar with the model, can you tell me what model I should use :)
If you're just starting out, try the good ol' reliable Realistic Vision
btw, CivitAI is a site that hosts a lot of other checkpoints, you can take a look there
If you're just starting out, try the good ol' reliable Realistic Vision
btw, CivitAI is a site that hosts a lot of other checkpoints, you can take a look there
thank you :)
You're also using a webui version from January 2023. Update with git pull and delete the venv folder.
You're also using a webui version from January 2023. Update with
git pulland delete the venv folder.
thanks, I just use this to download it
I change sd_models.py:line 222 to
pl_sd = torch.load(checkpoint_file, map_location=map_location or shared.weight_load_location, weights_only=False),and I solved my problem 😄
yes, modify to False,not True. My line is 323