Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
1b66d527
Commit
1b66d527
authored
Dec 24, 2022
by
AUTOMATIC1111
Committed by
GitHub
Dec 24, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5595 from wywywywy/ldsr-safetensors
Add SafeTensors support to LDSR
parents
eba60a42
8bcdd504
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
4 deletions
+14
-4
extensions-builtin/LDSR/ldsr_model_arch.py
extensions-builtin/LDSR/ldsr_model_arch.py
+8
-2
extensions-builtin/LDSR/scripts/ldsr_model.py
extensions-builtin/LDSR/scripts/ldsr_model.py
+6
-2
No files found.
extensions-builtin/LDSR/ldsr_model_arch.py
View file @
1b66d527
import
os
import
gc
import
time
import
warnings
...
...
@@ -8,6 +9,7 @@ import torchvision
from
PIL
import
Image
from
einops
import
rearrange
,
repeat
from
omegaconf
import
OmegaConf
import
safetensors.torch
from
ldm.models.diffusion.ddim
import
DDIMSampler
from
ldm.util
import
instantiate_from_config
,
ismap
...
...
@@ -28,8 +30,12 @@ class LDSR:
model
:
torch
.
nn
.
Module
=
cached_ldsr_model
else
:
print
(
f
"Loading model from {self.modelPath}"
)
pl_sd
=
torch
.
load
(
self
.
modelPath
,
map_location
=
"cpu"
)
sd
=
pl_sd
[
"state_dict"
]
_
,
extension
=
os
.
path
.
splitext
(
self
.
modelPath
)
if
extension
.
lower
()
==
".safetensors"
:
pl_sd
=
safetensors
.
torch
.
load_file
(
self
.
modelPath
,
device
=
"cpu"
)
else
:
pl_sd
=
torch
.
load
(
self
.
modelPath
,
map_location
=
"cpu"
)
sd
=
pl_sd
[
"state_dict"
]
if
"state_dict"
in
pl_sd
else
pl_sd
config
=
OmegaConf
.
load
(
self
.
yamlPath
)
config
.
model
.
target
=
"ldm.models.diffusion.ddpm.LatentDiffusionV1"
model
:
torch
.
nn
.
Module
=
instantiate_from_config
(
config
.
model
)
...
...
extensions-builtin/LDSR/scripts/ldsr_model.py
View file @
1b66d527
...
...
@@ -25,6 +25,7 @@ class UpscalerLDSR(Upscaler):
yaml_path
=
os
.
path
.
join
(
self
.
model_path
,
"project.yaml"
)
old_model_path
=
os
.
path
.
join
(
self
.
model_path
,
"model.pth"
)
new_model_path
=
os
.
path
.
join
(
self
.
model_path
,
"model.ckpt"
)
safetensors_model_path
=
os
.
path
.
join
(
self
.
model_path
,
"model.safetensors"
)
if
os
.
path
.
exists
(
yaml_path
):
statinfo
=
os
.
stat
(
yaml_path
)
if
statinfo
.
st_size
>=
10485760
:
...
...
@@ -33,8 +34,11 @@ class UpscalerLDSR(Upscaler):
if
os
.
path
.
exists
(
old_model_path
):
print
(
"Renaming model from model.pth to model.ckpt"
)
os
.
rename
(
old_model_path
,
new_model_path
)
model
=
load_file_from_url
(
url
=
self
.
model_url
,
model_dir
=
self
.
model_path
,
file_name
=
"model.ckpt"
,
progress
=
True
)
if
os
.
path
.
exists
(
safetensors_model_path
):
model
=
safetensors_model_path
else
:
model
=
load_file_from_url
(
url
=
self
.
model_url
,
model_dir
=
self
.
model_path
,
file_name
=
"model.ckpt"
,
progress
=
True
)
yaml
=
load_file_from_url
(
url
=
self
.
yaml_url
,
model_dir
=
self
.
model_path
,
file_name
=
"project.yaml"
,
progress
=
True
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment