Skip to content

Commit

Permalink
Fix adapter_config.json saving in DPO recipes (pytorch#2162)
Browse files Browse the repository at this point in the history
  • Loading branch information
SalmanMohammadi authored Dec 19, 2024
1 parent 1372af4 commit e03604f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions recipes/lora_dpo_distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
DoRALinear,
get_adapter_params,
get_adapter_state_dict,
get_lora_module_names,
get_merged_lora_ckpt,
LoRALinear,
set_trainable_params,
Expand Down Expand Up @@ -595,6 +596,17 @@ def save_checkpoint(
}
)

adapter_config = {
"r": self._lora_rank,
"lora_alpha": self._lora_alpha,
"target_modules": get_lora_module_names(
self._lora_attn_modules,
self._apply_lora_to_mlp,
self._apply_lora_to_output,
),
"peft_type": "LORA",
}
checkpoint_dict.update({training.ADAPTER_CONFIG: adapter_config})
self._checkpointer.save_checkpoint(
checkpoint_dict,
epoch=epoch,
Expand Down
13 changes: 13 additions & 0 deletions recipes/lora_dpo_single_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
disable_adapter,
get_adapter_params,
get_adapter_state_dict,
get_lora_module_names,
get_merged_lora_ckpt,
set_trainable_params,
validate_missing_and_unexpected_for_lora,
Expand Down Expand Up @@ -448,6 +449,18 @@ def save_checkpoint(self, epoch: int) -> None:

ckpt_dict.update({training.MODEL_KEY: merged_state_dict})

adapter_config = {
"r": self._lora_rank,
"lora_alpha": self._lora_alpha,
"target_modules": get_lora_module_names(
self._lora_attn_modules,
self._apply_lora_to_mlp,
self._apply_lora_to_output,
),
"peft_type": "LORA",
}
ckpt_dict.update({training.ADAPTER_CONFIG: adapter_config})

self._checkpointer.save_checkpoint(
ckpt_dict,
epoch=epoch,
Expand Down

0 comments on commit e03604f

Please sign in to comment.