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 to resume adapter training from an existing adapter weights #3983

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion ludwig/models/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ def initialize_adapter(self):
"`finetune` or remove the adapter config."
)

self.model = initialize_adapter(self.model, self.config_obj)
is_trainable = self.config_obj.trainer.type == "finetune"
self.model = initialize_adapter(self.model, self.config_obj, is_trainable=is_trainable)

logger.info("==================================================")
logger.info("Trainable Parameter Summary For Fine-Tuning")
Expand Down
5 changes: 3 additions & 2 deletions ludwig/utils/llm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,14 @@ def to_device(


def initialize_adapter(
model: PreTrainedModel, config_obj: "LLMModelConfig" # noqa F821
model: PreTrainedModel, config_obj: "LLMModelConfig", is_trainable: bool = False # noqa F821
) -> Union["PeftModel", PreTrainedModel]: # noqa F821
"""Wrap a pretrained model with a PEFT model for fine-tuning.

Args:
model: Pretrained model to fine-tune with an adapter.
config_obj: LLM config
is_trainable: bool indicating whether the adapter should be trainable

Returns:
`model` wrapped in a PEFT model if an adapter config was provided, otherwise `model`.
Expand All @@ -175,7 +176,7 @@ def initialize_adapter(
peft_config = PeftConfig.from_pretrained(config_obj.adapter.pretrained_adapter_weights)

model = MODEL_TYPE_TO_PEFT_MODEL_MAPPING[peft_config.task_type].from_pretrained(
model, config_obj.adapter.pretrained_adapter_weights
model, config_obj.adapter.pretrained_adapter_weights, is_trainable=is_trainable
)
else:
# Leave this import inline to support a minimal install of Ludwig
Expand Down