Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Overbill1683
Stable Diffusion Webui
提交
6ef0ff39
S
Stable Diffusion Webui
项目概览
Overbill1683
/
Stable Diffusion Webui
9 个月 前同步成功
通知
1726
Star
80
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
S
Stable Diffusion Webui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
6ef0ff39
编写于
12月 14, 2023
作者:
A
AUTOMATIC1111
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merge pull request #14300 from AUTOMATIC1111/oft_fixes
Fix wrong implementation in network_oft
上级
120a84bd
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
11 addition
and
26 deletion
+11
-26
extensions-builtin/Lora/network_oft.py
extensions-builtin/Lora/network_oft.py
+11
-26
未找到文件。
extensions-builtin/Lora/network_oft.py
浏览文件 @
6ef0ff39
...
...
@@ -21,6 +21,8 @@ class NetworkModuleOFT(network.NetworkModule):
self
.
lin_module
=
None
self
.
org_module
:
list
[
torch
.
Module
]
=
[
self
.
sd_module
]
self
.
scale
=
1.0
# kohya-ss
if
"oft_blocks"
in
weights
.
w
.
keys
():
self
.
is_kohya
=
True
...
...
@@ -53,12 +55,18 @@ class NetworkModuleOFT(network.NetworkModule):
self
.
constraint
=
None
self
.
block_size
,
self
.
num_blocks
=
factorization
(
self
.
out_dim
,
self
.
dim
)
def
calc_updown
_kb
(
self
,
orig_weight
,
multiplier
):
def
calc_updown
(
self
,
orig_weight
):
oft_blocks
=
self
.
oft_blocks
.
to
(
orig_weight
.
device
,
dtype
=
orig_weight
.
dtype
)
oft_blocks
=
oft_blocks
-
oft_blocks
.
transpose
(
1
,
2
)
# ensure skew-symmetric orthogonal matrix
eye
=
torch
.
eye
(
self
.
block_size
,
device
=
self
.
oft_blocks
.
device
)
if
self
.
is_kohya
:
block_Q
=
oft_blocks
-
oft_blocks
.
transpose
(
1
,
2
)
# ensure skew-symmetric orthogonal matrix
norm_Q
=
torch
.
norm
(
block_Q
.
flatten
())
new_norm_Q
=
torch
.
clamp
(
norm_Q
,
max
=
self
.
constraint
)
block_Q
=
block_Q
*
((
new_norm_Q
+
1e-8
)
/
(
norm_Q
+
1e-8
))
oft_blocks
=
torch
.
matmul
(
eye
+
block_Q
,
(
eye
-
block_Q
).
float
().
inverse
())
R
=
oft_blocks
.
to
(
orig_weight
.
device
,
dtype
=
orig_weight
.
dtype
)
R
=
R
*
multiplier
+
torch
.
eye
(
self
.
block_size
,
device
=
orig_weight
.
device
)
# This errors out for MultiheadAttention, might need to be handled up-stream
merged_weight
=
rearrange
(
orig_weight
,
'(k n) ... -> k n ...'
,
k
=
self
.
num_blocks
,
n
=
self
.
block_size
)
...
...
@@ -72,26 +80,3 @@ class NetworkModuleOFT(network.NetworkModule):
updown
=
merged_weight
.
to
(
orig_weight
.
device
,
dtype
=
orig_weight
.
dtype
)
-
orig_weight
output_shape
=
orig_weight
.
shape
return
self
.
finalize_updown
(
updown
,
orig_weight
,
output_shape
)
def
calc_updown
(
self
,
orig_weight
):
# if alpha is a very small number as in coft, calc_scale() will return a almost zero number so we ignore it
multiplier
=
self
.
multiplier
()
return
self
.
calc_updown_kb
(
orig_weight
,
multiplier
)
# override to remove the multiplier/scale factor; it's already multiplied in get_weight
def
finalize_updown
(
self
,
updown
,
orig_weight
,
output_shape
,
ex_bias
=
None
):
if
self
.
bias
is
not
None
:
updown
=
updown
.
reshape
(
self
.
bias
.
shape
)
updown
+=
self
.
bias
.
to
(
orig_weight
.
device
,
dtype
=
orig_weight
.
dtype
)
updown
=
updown
.
reshape
(
output_shape
)
if
len
(
output_shape
)
==
4
:
updown
=
updown
.
reshape
(
output_shape
)
if
orig_weight
.
size
().
numel
()
==
updown
.
size
().
numel
():
updown
=
updown
.
reshape
(
orig_weight
.
shape
)
if
ex_bias
is
not
None
:
ex_bias
=
ex_bias
*
self
.
multiplier
()
return
updown
,
ex_bias
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录