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
4cc3add7
Commit
4cc3add7
authored
Jul 06, 2024
by
AUTOMATIC1111
Committed by
GitHub
Jul 06, 2024
1
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16078 from huchenlei/fix_sd2
Fix SD2 loading
parents
50514ce4
c3ef381c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
1 deletion
+8
-1
modules/sd_hijack_unet.py
modules/sd_hijack_unet.py
+2
-0
modules/sd_models_config.py
modules/sd_models_config.py
+6
-1
No files found.
modules/sd_hijack_unet.py
View file @
4cc3add7
...
...
@@ -138,6 +138,7 @@ CondFunc('ldm.models.diffusion.ddpm.LatentDiffusion.decode_first_stage', first_s
CondFunc
(
'ldm.models.diffusion.ddpm.LatentDiffusion.encode_first_stage'
,
first_stage_sub
,
first_stage_cond
)
CondFunc
(
'ldm.models.diffusion.ddpm.LatentDiffusion.get_first_stage_encoding'
,
lambda
orig_func
,
*
args
,
**
kwargs
:
orig_func
(
*
args
,
**
kwargs
)
.
float
(),
first_stage_cond
)
# Always make sure inputs to unet are in correct dtype
CondFunc
(
'ldm.models.diffusion.ddpm.LatentDiffusion.apply_model'
,
apply_model
)
CondFunc
(
'sgm.modules.diffusionmodules.wrappers.OpenAIWrapper.forward'
,
apply_model
)
...
...
@@ -150,5 +151,6 @@ def timestep_embedding_cast_result(orig_func, timesteps, *args, **kwargs):
return
orig_func
(
timesteps
,
*
args
,
**
kwargs
)
.
to
(
dtype
=
dtype
)
# Always make sure timestep calculation is in correct dtype
CondFunc
(
'ldm.modules.diffusionmodules.openaimodel.timestep_embedding'
,
timestep_embedding_cast_result
)
CondFunc
(
'sgm.modules.diffusionmodules.openaimodel.timestep_embedding'
,
timestep_embedding_cast_result
)
modules/sd_models_config.py
View file @
4cc3add7
...
...
@@ -56,14 +56,19 @@ def is_using_v_parameterization_for_sd2(state_dict):
unet
.
eval
()
with
torch
.
no_grad
():
unet_dtype
=
torch
.
float
original_unet_dtype
=
devices
.
dtype_unet
unet_sd
=
{
k
.
replace
(
"model.diffusion_model."
,
""
):
v
for
k
,
v
in
state_dict
.
items
()
if
"model.diffusion_model."
in
k
}
unet
.
load_state_dict
(
unet_sd
,
strict
=
True
)
unet
.
to
(
device
=
device
,
dtype
=
torch
.
float
)
unet
.
to
(
device
=
device
,
dtype
=
unet_dtype
)
devices
.
dtype_unet
=
unet_dtype
test_cond
=
torch
.
ones
((
1
,
2
,
1024
),
device
=
device
)
*
0.5
x_test
=
torch
.
ones
((
1
,
4
,
8
,
8
),
device
=
device
)
*
0.5
out
=
(
unet
(
x_test
,
torch
.
asarray
([
999
],
device
=
device
),
context
=
test_cond
)
-
x_test
)
.
mean
()
.
item
()
devices
.
dtype_unet
=
original_unet_dtype
return
out
<
-
1
...
...
nanahira
@nanahira
mentioned in commit
ffead92d
·
Sep 03, 2025
mentioned in commit
ffead92d
mentioned in commit ffead92d4e36a5082fa6ac5dd54c88477c9b524e
Toggle commit list
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