Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Overbill1683
Stable Diffusion Webui
提交
b8159d09
S
Stable Diffusion Webui
项目概览
Overbill1683
/
Stable Diffusion Webui
大约 1 年 前同步成功
通知
1785
Star
81
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
S
Stable Diffusion Webui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
体验新版 GitCode,发现更多精彩内容 >>
提交
b8159d09
编写于
7月 13, 2023
作者:
A
AUTOMATIC1111
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add XL support for live previews: approx and TAESD
上级
6f23da60
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
40 addition
and
25 deletion
+40
-25
modules/sd_models_xl.py
modules/sd_models_xl.py
+1
-1
modules/sd_vae_approx.py
modules/sd_vae_approx.py
+26
-11
modules/sd_vae_taesd.py
modules/sd_vae_taesd.py
+13
-13
未找到文件。
modules/sd_models_xl.py
浏览文件 @
b8159d09
...
...
@@ -48,7 +48,7 @@ def extend_sdxl(model):
discretization
=
sgm
.
modules
.
diffusionmodules
.
discretizer
.
LegacyDDPMDiscretization
()
model
.
alphas_cumprod
=
torch
.
asarray
(
discretization
.
alphas_cumprod
,
device
=
devices
.
device
,
dtype
=
dtype
)
model
.
is_xl
=
True
model
.
is_
sd
xl
=
True
sgm
.
models
.
diffusion
.
DiffusionEngine
.
get_learned_conditioning
=
get_learned_conditioning
...
...
modules/sd_vae_approx.py
浏览文件 @
b8159d09
...
...
@@ -2,9 +2,9 @@ import os
import
torch
from
torch
import
nn
from
modules
import
devices
,
paths
from
modules
import
devices
,
paths
,
shared
sd_vae_approx_model
=
None
sd_vae_approx_model
s
=
{}
class
VAEApprox
(
nn
.
Module
):
...
...
@@ -31,19 +31,34 @@ class VAEApprox(nn.Module):
return
x
def
download_model
(
model_path
,
model_url
):
if
not
os
.
path
.
exists
(
model_path
):
os
.
makedirs
(
os
.
path
.
dirname
(
model_path
),
exist_ok
=
True
)
print
(
f
'Downloading VAEApprox model to:
{
model_path
}
'
)
torch
.
hub
.
download_url_to_file
(
model_url
,
model_path
)
def
model
():
global
sd_vae_approx_model
model_name
=
"vaeapprox-sdxl.pt"
if
getattr
(
shared
.
sd_model
,
'is_sdxl'
,
False
)
else
"model.pt"
loaded_model
=
sd_vae_approx_models
.
get
(
model_name
)
if
sd_vae_approx_model
is
None
:
model_path
=
os
.
path
.
join
(
paths
.
models_path
,
"VAE-approx"
,
"model.pt"
)
sd_vae_approx_model
=
VAEApprox
()
if
loaded_model
is
None
:
model_path
=
os
.
path
.
join
(
paths
.
models_path
,
"VAE-approx"
,
model_name
)
if
not
os
.
path
.
exists
(
model_path
):
model_path
=
os
.
path
.
join
(
paths
.
script_path
,
"models"
,
"VAE-approx"
,
"model.pt"
)
sd_vae_approx_model
.
load_state_dict
(
torch
.
load
(
model_path
,
map_location
=
'cpu'
if
devices
.
device
.
type
!=
'cuda'
else
None
))
sd_vae_approx_model
.
eval
()
sd_vae_approx_model
.
to
(
devices
.
device
,
devices
.
dtype
)
model_path
=
os
.
path
.
join
(
paths
.
script_path
,
"models"
,
"VAE-approx"
,
model_name
)
if
not
os
.
path
.
exists
(
model_path
):
model_path
=
os
.
path
.
join
(
paths
.
models_path
,
"VAE-approx"
,
model_name
)
download_model
(
model_path
,
'https://github.com/AUTOMATIC1111/stable-diffusion-webui/releases/download/v1.0.0-pre/'
+
model_name
)
loaded_model
=
VAEApprox
()
loaded_model
.
load_state_dict
(
torch
.
load
(
model_path
,
map_location
=
'cpu'
if
devices
.
device
.
type
!=
'cuda'
else
None
))
loaded_model
.
eval
()
loaded_model
.
to
(
devices
.
device
,
devices
.
dtype
)
sd_vae_approx_models
[
model_name
]
=
loaded_model
return
sd_vae_approx
_model
return
loaded
_model
def
cheap_approximation
(
sample
):
...
...
modules/sd_vae_taesd.py
浏览文件 @
b8159d09
...
...
@@ -8,9 +8,9 @@ import os
import
torch
import
torch.nn
as
nn
from
modules
import
devices
,
paths_internal
from
modules
import
devices
,
paths_internal
,
shared
sd_vae_taesd
=
None
sd_vae_taesd
_models
=
{}
def
conv
(
n_in
,
n_out
,
**
kwargs
):
...
...
@@ -61,9 +61,7 @@ class TAESD(nn.Module):
return
x
.
sub
(
TAESD
.
latent_shift
).
mul
(
2
*
TAESD
.
latent_magnitude
)
def
download_model
(
model_path
):
model_url
=
'https://github.com/madebyollin/taesd/raw/main/taesd_decoder.pth'
def
download_model
(
model_path
,
model_url
):
if
not
os
.
path
.
exists
(
model_path
):
os
.
makedirs
(
os
.
path
.
dirname
(
model_path
),
exist_ok
=
True
)
...
...
@@ -72,17 +70,19 @@ def download_model(model_path):
def
model
():
global
sd_vae_taesd
model_name
=
"taesdxl_decoder.pth"
if
getattr
(
shared
.
sd_model
,
'is_sdxl'
,
False
)
else
"taesd_decoder.pth"
loaded_model
=
sd_vae_taesd_models
.
get
(
model_name
)
if
sd_vae_taesd
is
None
:
model_path
=
os
.
path
.
join
(
paths_internal
.
models_path
,
"VAE-taesd"
,
"taesd_decoder.pth"
)
download_model
(
model_path
)
if
loaded_model
is
None
:
model_path
=
os
.
path
.
join
(
paths_internal
.
models_path
,
"VAE-taesd"
,
model_name
)
download_model
(
model_path
,
'https://github.com/madebyollin/taesd/raw/main/'
+
model_name
)
if
os
.
path
.
exists
(
model_path
):
sd_vae_taesd
=
TAESD
(
model_path
)
sd_vae_taesd
.
eval
()
sd_vae_taesd
.
to
(
devices
.
device
,
devices
.
dtype
)
loaded_model
=
TAESD
(
model_path
)
loaded_model
.
eval
()
loaded_model
.
to
(
devices
.
device
,
devices
.
dtype
)
sd_vae_taesd_models
[
model_name
]
=
loaded_model
else
:
raise
FileNotFoundError
(
'TAESD model not found'
)
return
sd_vae_taesd
.
decoder
return
loaded_model
.
decoder
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录