Skip to content

Commit

Permalink
add safetensors to requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
AUTOMATIC1111 committed Nov 27, 2022
1 parent f108782 commit 6074175
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
11 changes: 5 additions & 6 deletions modules/sd_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from collections import namedtuple
import torch
import re
import safetensors.torch
from omegaconf import OmegaConf

from ldm.util import instantiate_from_config
Expand Down Expand Up @@ -173,14 +174,12 @@ def load_model_weights(model, checkpoint_info, vae_file="auto"):
# load from file
print(f"Loading weights [{sd_model_hash}] from {checkpoint_file}")

if checkpoint_file.endswith(".safetensors"):
try:
from safetensors.torch import load_file
except ImportError as e:
raise ImportError(f"The model is in safetensors format and it is not installed, use `pip install safetensors`: {e}")
pl_sd = load_file(checkpoint_file, device=shared.weight_load_location)
_, extension = os.path.splitext(checkpoint_file)
if extension.lower() == ".safetensors":
pl_sd = safetensors.torch.load_file(checkpoint_file, device=shared.weight_load_location)
else:
pl_sd = torch.load(checkpoint_file, map_location=shared.weight_load_location)

if "global_step" in pl_sd:
print(f"Global Step: {pl_sd['global_step']}")

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ lark
inflection
GitPython
torchsde
safetensors
1 change: 1 addition & 0 deletions requirements_versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ lark==1.1.2
inflection==0.5.1
GitPython==3.1.27
torchsde==0.2.5
safetensors==0.2.5

0 comments on commit 6074175

Please sign in to comment.