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
f8f38c7c
Commit
f8f38c7c
authored
Jan 05, 2024
by
Kohaku-Blueleaf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix dtype casting for OFT module
parent
a06dab8d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
3 deletions
+3
-3
extensions-builtin/Lora/network_oft.py
extensions-builtin/Lora/network_oft.py
+3
-3
No files found.
extensions-builtin/Lora/network_oft.py
View file @
f8f38c7c
...
@@ -56,7 +56,7 @@ class NetworkModuleOFT(network.NetworkModule):
...
@@ -56,7 +56,7 @@ class NetworkModuleOFT(network.NetworkModule):
self
.
block_size
,
self
.
num_blocks
=
factorization
(
self
.
out_dim
,
self
.
dim
)
self
.
block_size
,
self
.
num_blocks
=
factorization
(
self
.
out_dim
,
self
.
dim
)
def
calc_updown
(
self
,
orig_weight
):
def
calc_updown
(
self
,
orig_weight
):
oft_blocks
=
self
.
oft_blocks
.
to
(
orig_weight
.
device
,
dtype
=
orig_weight
.
dtype
)
oft_blocks
=
self
.
oft_blocks
.
to
(
orig_weight
.
device
)
eye
=
torch
.
eye
(
self
.
block_size
,
device
=
self
.
oft_blocks
.
device
)
eye
=
torch
.
eye
(
self
.
block_size
,
device
=
self
.
oft_blocks
.
device
)
if
self
.
is_kohya
:
if
self
.
is_kohya
:
...
@@ -66,7 +66,7 @@ class NetworkModuleOFT(network.NetworkModule):
...
@@ -66,7 +66,7 @@ class NetworkModuleOFT(network.NetworkModule):
block_Q
=
block_Q
*
((
new_norm_Q
+
1e-8
)
/
(
norm_Q
+
1e-8
))
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
())
oft_blocks
=
torch
.
matmul
(
eye
+
block_Q
,
(
eye
-
block_Q
)
.
float
()
.
inverse
())
R
=
oft_blocks
.
to
(
orig_weight
.
device
,
dtype
=
orig_weight
.
dtype
)
R
=
oft_blocks
.
to
(
orig_weight
.
device
)
# This errors out for MultiheadAttention, might need to be handled up-stream
# 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
)
merged_weight
=
rearrange
(
orig_weight
,
'(k n) ... -> k n ...'
,
k
=
self
.
num_blocks
,
n
=
self
.
block_size
)
...
@@ -77,6 +77,6 @@ class NetworkModuleOFT(network.NetworkModule):
...
@@ -77,6 +77,6 @@ class NetworkModuleOFT(network.NetworkModule):
)
)
merged_weight
=
rearrange
(
merged_weight
,
'k m ... -> (k m) ...'
)
merged_weight
=
rearrange
(
merged_weight
,
'k m ... -> (k m) ...'
)
updown
=
merged_weight
.
to
(
orig_weight
.
device
,
dtype
=
orig_weight
.
dtype
)
-
orig_weight
updown
=
merged_weight
.
to
(
orig_weight
.
device
)
-
orig_weight
.
to
(
merged_weight
.
dtype
)
output_shape
=
orig_weight
.
shape
output_shape
=
orig_weight
.
shape
return
self
.
finalize_updown
(
updown
,
orig_weight
,
output_shape
)
return
self
.
finalize_updown
(
updown
,
orig_weight
,
output_shape
)
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