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

Make loaded peft adapters optionally trainable #1701

Merged
merged 5 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions llmfoundry/models/hf/hf_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ def build_inner_model(
model = PeftModelForCausalLM.from_pretrained(
model,
pretrained_lora_id_or_path,
is_trainable=True,
)

if prepare_for_fsdp:
Expand Down
23 changes: 23 additions & 0 deletions tests/models/hf/test_hf_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright 2024 MosaicML LLM Foundry authors
# SPDX-License-Identifier: Apache-2.0

from peft import PeftModel

from llmfoundry.models.hf.hf_base import BaseHuggingFaceModel


Expand All @@ -23,3 +25,24 @@ def test_build_inner_model_fsdp():
)

assert model.fsdp_wrap_fn(model.model.layers[0])


def test_pretrained_peft_trainable():
model = BaseHuggingFaceModel.build_inner_model(
pretrained_model_name_or_path='facebook/opt-350m',
pretrained_lora_id_or_path='ybelkada/opt-350m-lora',
trust_remote_code=False,
init_device='cpu',
use_flash_attention_2=False,
use_auth_token=False,
config_overrides={},
load_in_8bit=False,
pretrained=True,
prepare_for_fsdp=True,
)

assert isinstance(model, PeftModel)

n_trainable, n_all = model.get_nb_trainable_parameters()
assert n_all > 0
assert n_trainable > 0
Loading