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]: loading stable diffusion model: UnpicklingError #16868

Open
4 of 6 tasks
Yeeeeeee123 opened this issue Feb 26, 2025 · 8 comments
Open
4 of 6 tasks

[Bug]: loading stable diffusion model: UnpicklingError #16868

Yeeeeeee123 opened this issue Feb 26, 2025 · 8 comments
Labels
asking-for-help-with-local-system-issues This issue is asking for help related to local system; please offer assistance

Comments

@Yeeeeeee123
Copy link

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
  • 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: 48a1582
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

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

  1. run run.bat
  2. 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

@Yeeeeeee123 Yeeeeeee123 added the bug-report Report of a bug, yet to be confirmed label Feb 26, 2025
@Yeeeeeee123
Copy link
Author

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 😄

@Haoming02
Copy link
Contributor

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...

@Yeeeeeee123
Copy link
Author

Yeeeeeee123 commented Feb 27, 2025

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...

Thank you, I just started using this and am not familiar with the model, can you tell me what model I should use :)

@Haoming02
Copy link
Contributor

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

@Yeeeeeee123
Copy link
Author

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 :)

@missionfloyd
Copy link
Collaborator

You're also using a webui version from January 2023. Update with git pull and delete the venv folder.

@missionfloyd missionfloyd added asking-for-help-with-local-system-issues This issue is asking for help related to local system; please offer assistance and removed bug-report Report of a bug, yet to be confirmed labels Feb 28, 2025
@Yeeeeeee123
Copy link
Author

Yeeeeeee123 commented Feb 28, 2025

You're also using a webui version from January 2023. Update with git pull and delete the venv folder.

thanks, I just use this to download it

@lapertme2
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
asking-for-help-with-local-system-issues This issue is asking for help related to local system; please offer assistance
Projects
None yet
Development

No branches or pull requests

4 participants