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
c4afdb78
Commit
c4afdb78
authored
Feb 22, 2024
by
Kohaku-Blueleaf
Committed by
GitHub
Feb 22, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
For no constraint
parent
64179c32
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
5 deletions
+6
-5
extensions-builtin/Lora/network_oft.py
extensions-builtin/Lora/network_oft.py
+6
-5
No files found.
extensions-builtin/Lora/network_oft.py
View file @
c4afdb78
...
...
@@ -27,7 +27,7 @@ class NetworkModuleOFT(network.NetworkModule):
# kohya-ss/New LyCORIS OFT/BOFT
if
"oft_blocks"
in
weights
.
w
.
keys
():
self
.
oft_blocks
=
weights
.
w
[
"oft_blocks"
]
# (num_blocks, block_size, block_size)
self
.
alpha
=
weights
.
w
.
get
(
"alpha"
,
self
.
alpha
)
# alpha is constraint
self
.
alpha
=
weights
.
w
.
get
(
"alpha"
,
None
)
# alpha is constraint
self
.
dim
=
self
.
oft_blocks
.
shape
[
0
]
# lora dim
# Old LyCORIS OFT
elif
"oft_diag"
in
weights
.
w
.
keys
():
...
...
@@ -56,7 +56,7 @@ class NetworkModuleOFT(network.NetworkModule):
self
.
num_blocks
=
self
.
dim
self
.
block_size
=
self
.
out_dim
//
self
.
dim
self
.
constraint
=
(
1
if
self
.
alpha
is
None
else
self
.
alpha
)
*
self
.
out_dim
self
.
constraint
=
(
0
if
self
.
alpha
is
None
else
self
.
alpha
)
*
self
.
out_dim
if
self
.
is_R
:
self
.
constraint
=
None
self
.
block_size
=
self
.
dim
...
...
@@ -73,9 +73,10 @@ class NetworkModuleOFT(network.NetworkModule):
if
not
self
.
is_R
:
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
.
to
(
oft_blocks
.
device
))
block_Q
=
block_Q
*
((
new_norm_Q
+
1e-8
)
/
(
norm_Q
+
1e-8
))
if
self
.
constraint
!=
0
:
norm_Q
=
torch
.
norm
(
block_Q
.
flatten
())
new_norm_Q
=
torch
.
clamp
(
norm_Q
,
max
=
self
.
constraint
.
to
(
oft_blocks
.
device
))
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
)
...
...
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