Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Overbill1683
Stable Diffusion Webui
提交
141a17e9
S
Stable Diffusion Webui
项目概览
Overbill1683
/
Stable Diffusion Webui
8 个月 前同步成功
通知
1713
Star
78
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
S
Stable Diffusion Webui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
141a17e9
编写于
3月 02, 2024
作者:
A
AUTOMATIC1111
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
style changes for #14979
上级
da67afe5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
41 addition
and
29 deletion
+41
-29
modules/sd_models.py
modules/sd_models.py
+41
-29
未找到文件。
modules/sd_models.py
浏览文件 @
141a17e9
...
...
@@ -552,36 +552,48 @@ def repair_config(sd_config):
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
)
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
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
if
hasattr
(
sd_model
,
'alphas_cumprod'
)
and
hasattr
(
sd_model
,
'alphas_cumprod_original'
):
sd_model
.
alphas_cumprod
=
sd_model
.
alphas_cumprod_original
.
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
)
"""
Applies an override to the alpha schedule of the model according to settings.
- downcasts the alpha schedule to half precision
- rescales the alpha schedule to have zero terminal SNR
"""
if
not
hasattr
(
sd_model
,
'alphas_cumprod'
)
or
not
hasattr
(
sd_model
,
'alphas_cumprod_original'
):
return
sd_model
.
alphas_cumprod
=
sd_model
.
alphas_cumprod_original
.
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'
sd2_clip_weight
=
'cond_stage_model.model.transformer.resblocks.0.attn.in_proj_weight'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录