Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
S
Stable Diffusion Webui
管理
动态
成员
代码
仓库
分支
提交
标签
仓库图
比较修订版本
部署
模型注册表
分析
模型实验
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
Show more breadcrumbs
Hunter0726
Stable Diffusion Webui
提交
8b40f475
提交
8b40f475
编辑于
1年前
作者:
Nuullll
浏览文件
操作
下载
补丁
差异文件
Initial IPEX support
上级
f0f100e6
No related branches found
分支 包含提交
No related tags found
标签 包含提交
无相关合并请求
变更
2
隐藏空白变更内容
行内
左右并排
显示
2 个更改的文件
modules/devices.py
+9
-2
9 个添加, 2 个删除
modules/devices.py
modules/xpu_specific.py
+42
-0
42 个添加, 0 个删除
modules/xpu_specific.py
有
51 个添加
和
2 个删除
modules/devices.py
+
9
−
2
浏览文件 @
8b40f475
...
...
@@ -3,7 +3,7 @@ import contextlib
from
functools
import
lru_cache
import
torch
from
modules
import
errors
,
shared
from
modules
import
errors
,
shared
,
xpu_specific
if
sys
.
platform
==
"
darwin
"
:
from
modules
import
mac_specific
...
...
@@ -30,6 +30,9 @@ def get_optimal_device_name():
if
has_mps
():
return
"
mps
"
if
xpu_specific
.
has_ipex
:
return
xpu_specific
.
get_xpu_device_string
()
return
"
cpu
"
...
...
@@ -100,11 +103,15 @@ def autocast(disable=False):
if
dtype
==
torch
.
float32
or
shared
.
cmd_opts
.
precision
==
"
full
"
:
return
contextlib
.
nullcontext
()
if
xpu_specific
.
has_xpu
:
return
torch
.
autocast
(
"
xpu
"
)
return
torch
.
autocast
(
"
cuda
"
)
def
without_autocast
(
disable
=
False
):
return
torch
.
autocast
(
"
cuda
"
,
enabled
=
False
)
if
torch
.
is_autocast_enabled
()
and
not
disable
else
contextlib
.
nullcontext
()
device_type
=
"
xpu
"
if
xpu_specific
.
has_xpu
else
"
cuda
"
return
torch
.
autocast
(
device_type
,
enabled
=
False
)
if
torch
.
is_autocast_enabled
()
and
not
disable
else
contextlib
.
nullcontext
()
class
NansException
(
Exception
):
...
...
This diff is collapsed.
点击以展开。
modules/xpu_specific.py
0 → 100644
+
42
−
0
浏览文件 @
8b40f475
import
contextlib
from
modules
import
shared
from
modules.sd_hijack_utils
import
CondFunc
has_ipex
=
False
try
:
import
torch
import
intel_extension_for_pytorch
as
ipex
has_ipex
=
True
except
Exception
:
pass
def
check_for_xpu
():
if
not
has_ipex
:
return
False
return
hasattr
(
torch
,
'
xpu
'
)
and
torch
.
xpu
.
is_available
()
has_xpu
=
check_for_xpu
()
def
get_xpu_device_string
():
if
shared
.
cmd_opts
.
device_id
is
not
None
:
return
f
"
xpu:
{
shared
.
cmd_opts
.
device_id
}
"
return
"
xpu
"
def
return_null_context
(
*
args
,
**
kwargs
):
# pylint: disable=unused-argument
return
contextlib
.
nullcontext
()
if
has_xpu
:
CondFunc
(
'
torch.Generator
'
,
lambda
orig_func
,
device
=
None
:
torch
.
xpu
.
Generator
(
device
),
lambda
orig_func
,
device
=
None
:
device
is
not
None
and
device
!=
torch
.
device
(
"
cpu
"
)
and
device
!=
"
cpu
"
)
CondFunc
(
'
torch.nn.functional.layer_norm
'
,
lambda
orig_func
,
input
,
normalized_shape
=
None
,
weight
=
None
,
*
args
,
**
kwargs
:
orig_func
(
input
.
to
(
weight
.
data
.
dtype
),
normalized_shape
,
weight
,
*
args
,
**
kwargs
),
lambda
orig_func
,
input
,
normalized_shape
=
None
,
weight
=
None
,
*
args
,
**
kwargs
:
weight
is
not
None
and
input
.
dtype
!=
weight
.
data
.
dtype
)
CondFunc
(
'
torch.nn.modules.GroupNorm.forward
'
,
lambda
orig_func
,
self
,
input
:
orig_func
(
self
,
input
.
to
(
self
.
weight
.
data
.
dtype
)),
lambda
orig_func
,
self
,
input
:
input
.
dtype
!=
self
.
weight
.
data
.
dtype
)
This diff is collapsed.
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录