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
141a17e9
Commit
141a17e9
authored
Mar 02, 2024
by
AUTOMATIC1111
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style changes for #14979
parent
da67afe5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
29 deletions
+41
-29
modules/sd_models.py
modules/sd_models.py
+41
-29
No files found.
modules/sd_models.py
View file @
141a17e9
...
@@ -552,36 +552,48 @@ def repair_config(sd_config):
...
@@ -552,36 +552,48 @@ def repair_config(sd_config):
karlo_path
=
os
.
path
.
join
(
paths
.
models_path
,
'karlo'
)
karlo_path
=
os
.
path
.
join
(
paths
.
models_path
,
'karlo'
)
sd_config
.
model
.
params
.
noise_aug_config
.
params
.
clip_stats_path
=
sd_config
.
model
.
params
.
noise_aug_config
.
params
.
clip_stats_path
.
replace
(
"checkpoints/karlo_models"
,
karlo_path
)
sd_config
.
model
.
params
.
noise_aug_config
.
params
.
clip_stats_path
=
sd_config
.
model
.
params
.
noise_aug_config
.
params
.
clip_stats_path
.
replace
(
"checkpoints/karlo_models"
,
karlo_path
)
def
rescale_zero_terminal_snr_abar
(
alphas_cumprod
):
alphas_bar_sqrt
=
alphas_cumprod
.
sqrt
()
# Store old values.
alphas_bar_sqrt_0
=
alphas_bar_sqrt
[
0
]
.
clone
()
alphas_bar_sqrt_T
=
alphas_bar_sqrt
[
-
1
]
.
clone
()
# Shift so the last timestep is zero.
alphas_bar_sqrt
-=
(
alphas_bar_sqrt_T
)
# Scale so the first timestep is back to the old value.
alphas_bar_sqrt
*=
alphas_bar_sqrt_0
/
(
alphas_bar_sqrt_0
-
alphas_bar_sqrt_T
)
# Convert alphas_bar_sqrt to betas
alphas_bar
=
alphas_bar_sqrt
**
2
# Revert sqrt
alphas_bar
[
-
1
]
=
4.8973451890853435e-08
return
alphas_bar
def
apply_alpha_schedule_override
(
sd_model
,
p
=
None
):
def
apply_alpha_schedule_override
(
sd_model
,
p
=
None
):
def
rescale_zero_terminal_snr_abar
(
alphas_cumprod
):
"""
alphas_bar_sqrt
=
alphas_cumprod
.
sqrt
()
Applies an override to the alpha schedule of the model according to settings.
- downcasts the alpha schedule to half precision
# Store old values.
- rescales the alpha schedule to have zero terminal SNR
alphas_bar_sqrt_0
=
alphas_bar_sqrt
[
0
]
.
clone
()
"""
alphas_bar_sqrt_T
=
alphas_bar_sqrt
[
-
1
]
.
clone
()
if
not
hasattr
(
sd_model
,
'alphas_cumprod'
)
or
not
hasattr
(
sd_model
,
'alphas_cumprod_original'
):
# Shift so the last timestep is zero.
return
alphas_bar_sqrt
-=
(
alphas_bar_sqrt_T
)
sd_model
.
alphas_cumprod
=
sd_model
.
alphas_cumprod_original
.
to
(
shared
.
device
)
# Scale so the first timestep is back to the old value.
alphas_bar_sqrt
*=
alphas_bar_sqrt_0
/
(
alphas_bar_sqrt_0
-
alphas_bar_sqrt_T
)
if
opts
.
use_downcasted_alpha_bar
:
if
p
is
not
None
:
# Convert alphas_bar_sqrt to betas
p
.
extra_generation_params
[
'Downcast alphas_cumprod'
]
=
opts
.
use_downcasted_alpha_bar
alphas_bar
=
alphas_bar_sqrt
**
2
# Revert sqrt
sd_model
.
alphas_cumprod
=
sd_model
.
alphas_cumprod
.
half
()
.
to
(
shared
.
device
)
alphas_bar
[
-
1
]
=
4.8973451890853435e-08
return
alphas_bar
if
opts
.
sd_noise_schedule
==
"Zero Terminal SNR"
:
if
p
is
not
None
:
if
hasattr
(
sd_model
,
'alphas_cumprod'
)
and
hasattr
(
sd_model
,
'alphas_cumprod_original'
):
p
.
extra_generation_params
[
'Noise Schedule'
]
=
opts
.
sd_noise_schedule
sd_model
.
alphas_cumprod
=
sd_model
.
alphas_cumprod_original
.
to
(
shared
.
device
)
sd_model
.
alphas_cumprod
=
rescale_zero_terminal_snr_abar
(
sd_model
.
alphas_cumprod
)
.
to
(
shared
.
device
)
if
opts
.
use_downcasted_alpha_bar
:
if
p
is
not
None
:
p
.
extra_generation_params
[
'Downcast alphas_cumprod'
]
=
opts
.
use_downcasted_alpha_bar
sd_model
.
alphas_cumprod
=
sd_model
.
alphas_cumprod
.
half
()
.
to
(
shared
.
device
)
if
opts
.
sd_noise_schedule
==
"Zero Terminal SNR"
:
if
p
is
not
None
:
p
.
extra_generation_params
[
'Noise Schedule'
]
=
opts
.
sd_noise_schedule
sd_model
.
alphas_cumprod
=
rescale_zero_terminal_snr_abar
(
sd_model
.
alphas_cumprod
)
.
to
(
shared
.
device
)
sd1_clip_weight
=
'cond_stage_model.transformer.text_model.embeddings.token_embedding.weight'
sd1_clip_weight
=
'cond_stage_model.transformer.text_model.embeddings.token_embedding.weight'
sd2_clip_weight
=
'cond_stage_model.model.transformer.resblocks.0.attn.in_proj_weight'
sd2_clip_weight
=
'cond_stage_model.model.transformer.resblocks.0.attn.in_proj_weight'
...
...
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