Skip to content

Commit 358e9e2

Browse files
Merge pull request #14726 from v0xie/fix-oft-device
Fix kohya-ss OFT network wrong device for eye and constraint
2 parents c17f7ee + fd38314 commit 358e9e2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

extensions-builtin/Lora/network_oft.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ def __init__(self, net: network.Network, weights: network.NetworkWeights):
5757

5858
def calc_updown(self, orig_weight):
5959
oft_blocks = self.oft_blocks.to(orig_weight.device)
60-
eye = torch.eye(self.block_size, device=self.oft_blocks.device)
60+
eye = torch.eye(self.block_size, device=oft_blocks.device)
6161

6262
if self.is_kohya:
6363
block_Q = oft_blocks - oft_blocks.transpose(1, 2) # ensure skew-symmetric orthogonal matrix
6464
norm_Q = torch.norm(block_Q.flatten())
65-
new_norm_Q = torch.clamp(norm_Q, max=self.constraint)
65+
new_norm_Q = torch.clamp(norm_Q, max=self.constraint.to(oft_blocks.device))
6666
block_Q = block_Q * ((new_norm_Q + 1e-8) / (norm_Q + 1e-8))
6767
oft_blocks = torch.matmul(eye + block_Q, (eye - block_Q).float().inverse())
6868

0 commit comments

Comments
 (0)