This commit is contained in:
Kohaku-Blueleaf 2025-07-23 14:37:30 +08:00
parent dc05edb5b2
commit 2100f4cac2
3 changed files with 7 additions and 10 deletions

View File

@ -78,7 +78,7 @@ class LohaDiff(WeightAdapterTrainBase):
def __init__(self, weights): def __init__(self, weights):
super().__init__() super().__init__()
# Unpack weights tuple from LoHaAdapter # Unpack weights tuple from LoHaAdapter
w1a, w1b, alpha, w2a, w2b, t1, t2, dora_scale = weights w1a, w1b, alpha, w2a, w2b, t1, t2, _ = weights
# Create trainable parameters # Create trainable parameters
self.hada_w1_a = torch.nn.Parameter(w1a) self.hada_w1_a = torch.nn.Parameter(w1a)
@ -98,7 +98,7 @@ class LohaDiff(WeightAdapterTrainBase):
# Store rank and non-trainable alpha # Store rank and non-trainable alpha
self.rank = w1b.shape[0] self.rank = w1b.shape[0]
self.register_buffer("alpha", torch.tensor(alpha)) self.alpha = torch.nn.Parameter(torch.tensor(alpha), requires_grad=False)
def __call__(self, w): def __call__(self, w):
org_dtype = w.dtype org_dtype = w.dtype

View File

@ -17,16 +17,16 @@ class LokrDiff(WeightAdapterTrainBase):
(lokr_w1, lokr_w2, alpha, lokr_w1_a, lokr_w1_b, lokr_w2_a, lokr_w2_b, lokr_t2, dora_scale) = weights (lokr_w1, lokr_w2, alpha, lokr_w1_a, lokr_w1_b, lokr_w2_a, lokr_w2_b, lokr_t2, dora_scale) = weights
self.use_tucker = False self.use_tucker = False
if lokr_w1_a is not None: if lokr_w1_a is not None:
out_dim_a, rank_a = lokr_w1_a.shape[0], lokr_w1_a.shape[1] _, rank_a = lokr_w1_a.shape[0], lokr_w1_a.shape[1]
rank_a, in_dim_a = lokr_w1_b.shape[0], lokr_w1_b.shape[1] rank_a, _ = lokr_w1_b.shape[0], lokr_w1_b.shape[1]
self.lokr_w1_a = torch.nn.Parameter(lokr_w1_a) self.lokr_w1_a = torch.nn.Parameter(lokr_w1_a)
self.lokr_w1_b = torch.nn.Parameter(lokr_w1_b) self.lokr_w1_b = torch.nn.Parameter(lokr_w1_b)
self.w1_rebuild = True self.w1_rebuild = True
self.ranka = rank_a self.ranka = rank_a
if lokr_w2_a is not None: if lokr_w2_a is not None:
out_dim_b, rank_b = lokr_w2_a.shape[0], lokr_w2_a.shape[1] _, rank_b = lokr_w2_a.shape[0], lokr_w2_a.shape[1]
rank_b, in_dim_b = lokr_w2_b.shape[0], lokr_w2_b.shape[1] rank_b, _ = lokr_w2_b.shape[0], lokr_w2_b.shape[1]
self.lokr_w2_a = torch.nn.Parameter(lokr_w2_a) self.lokr_w2_a = torch.nn.Parameter(lokr_w2_a)
self.lokr_w2_b = torch.nn.Parameter(lokr_w2_b) self.lokr_w2_b = torch.nn.Parameter(lokr_w2_b)
if lokr_t2 is not None: if lokr_t2 is not None:
@ -36,12 +36,10 @@ class LokrDiff(WeightAdapterTrainBase):
self.rankb = rank_b self.rankb = rank_b
if lokr_w1 is not None: if lokr_w1 is not None:
out_dim_a, in_dim_a = lokr_w1.shape[0], lokr_w1.shape[1]
self.lokr_w1 = torch.nn.Parameter(lokr_w1) self.lokr_w1 = torch.nn.Parameter(lokr_w1)
self.w1_rebuild = False self.w1_rebuild = False
if lokr_w2 is not None: if lokr_w2 is not None:
out_dim_b, in_dim_b = lokr_w2.shape[0], lokr_w2.shape[1]
self.lokr_w2 = torch.nn.Parameter(lokr_w2) self.lokr_w2 = torch.nn.Parameter(lokr_w2)
self.w2_rebuild = False self.w2_rebuild = False

View File

@ -10,7 +10,7 @@ class OFTDiff(WeightAdapterTrainBase):
def __init__(self, weights): def __init__(self, weights):
super().__init__() super().__init__()
# Unpack weights tuple from LoHaAdapter # Unpack weights tuple from LoHaAdapter
blocks, rescale, alpha, dora_scale = weights blocks, rescale, alpha, _ = weights
# Create trainable parameters # Create trainable parameters
self.oft_blocks = torch.nn.Parameter(blocks) self.oft_blocks = torch.nn.Parameter(blocks)
@ -124,7 +124,6 @@ class OFTAdapter(WeightAdapterBase):
rescale = v[1] rescale = v[1]
alpha = v[2] alpha = v[2]
if alpha is None: if alpha is None:
print("Alpha is None")
alpha = 0 alpha = 0
dora_scale = v[3] dora_scale = v[3]