Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix loraga merge #9765

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions paddlenlp/peft/lora/lora_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,18 @@
model_state_dict = self.model.state_dict()
if self.lora_config.loraga:

def process_split_and_assign(name, concat_tensor, axis, init_dict, state_dict):
def process_split_and_assign(name, concat_tensor, init_dict, state_dict):
if "lora_A" in name:
axis = 1

Check warning on line 332 in paddlenlp/peft/lora/lora_model.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/peft/lora/lora_model.py#L330-L332

Added lines #L330 - L332 were not covered by tests
else:
axis = 0

Check warning on line 334 in paddlenlp/peft/lora/lora_model.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/peft/lora/lora_model.py#L334

Added line #L334 was not covered by tests
if isinstance(concat_tensor, np.ndarray):
final_lora, init_lora = np.split(concat_tensor, 2, axis=axis)
init_lora = paddle.to_tensor(init_lora)
else:
final_lora, init_lora = paddle.split(concat_tensor, 2, axis=axis)
if "lora_B" in name:
init_lora *= -1

Check warning on line 341 in paddlenlp/peft/lora/lora_model.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/peft/lora/lora_model.py#L340-L341

Added lines #L340 - L341 were not covered by tests
init_dict[name] = init_lora
state_dict[name] = final_lora
return init_lora
Expand All @@ -341,13 +347,13 @@
if "lora_A" in name:
concat_lora_A = state_dict[name]
init_loraA = process_split_and_assign(
name, concat_lora_A, axis=1, init_dict=self.loraga_init_dict, state_dict=state_dict
name, concat_lora_A, init_dict=self.loraga_init_dict, state_dict=state_dict
)

loraB_name = name.replace("lora_A", "lora_B")
concat_lora_B = state_dict[loraB_name]
init_loraB = process_split_and_assign(
loraB_name, concat_lora_B, axis=0, init_dict=self.loraga_init_dict, state_dict=state_dict
loraB_name, concat_lora_B, init_dict=self.loraga_init_dict, state_dict=state_dict
)

base_name = name.replace("lora_A", "weight")
Expand Down Expand Up @@ -690,7 +696,7 @@
if "lora_A" in name:
trainable_state_dict[name] = paddle.concat([weight, self.loraga_init_dict[name]], axis=1)
else:
trainable_state_dict[name] = paddle.concat([weight, self.loraga_init_dict[name]], axis=0)
trainable_state_dict[name] = paddle.concat([weight, -self.loraga_init_dict[name]], axis=0)

Check warning on line 699 in paddlenlp/peft/lora/lora_model.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/peft/lora/lora_model.py#L699

Added line #L699 was not covered by tests
else:
trainable_state_dict[name] = weight

Expand Down