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 PeftConfig loading from a remote repo. #649

Merged
merged 6 commits into from
Aug 24, 2023
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
12 changes: 8 additions & 4 deletions trl/models/modeling_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import torch.nn as nn
from accelerate import Accelerator
from huggingface_hub import hf_hub_download
from huggingface_hub.utils import EntryNotFoundError, HFValidationError, LocalEntryNotFoundError
from transformers import PreTrainedModel

from ..import_utils import is_peft_available
Expand Down Expand Up @@ -163,7 +164,7 @@ class and the arguments that are specific to trl models. The kwargs
"adapter_config.json",
token=token,
)
except: # noqa
except (EntryNotFoundError, LocalEntryNotFoundError, HFValidationError):
remote_adapter_config = None
else:
remote_adapter_config = None
Expand All @@ -181,7 +182,8 @@ class and the arguments that are specific to trl models. The kwargs
if local_adapter_present:
trained_adapter_config = PeftConfig.from_pretrained(pretrained_model_name_or_path)
else:
trained_adapter_config = PeftConfig.from_pretrained(remote_adapter_config)
remote_adapter_dir = os.path.dirname(remote_adapter_config)
trained_adapter_config = PeftConfig.from_pretrained(remote_adapter_dir)

# Load the pretrained base model
pretrained_model = cls.transformers_parent_class.from_pretrained(
Expand Down Expand Up @@ -253,7 +255,7 @@ class and the arguments that are specific to trl models. The kwargs
token=token,
)
# sharded
except: # noqa
except (EntryNotFoundError, LocalEntryNotFoundError, HFValidationError):
if os.path.exists(sharded_index_filename):
index_file_name = sharded_index_filename
else:
Expand All @@ -263,7 +265,8 @@ class and the arguments that are specific to trl models. The kwargs
"pytorch_model.bin.index.json",
token=token,
)
except ValueError: # not continue training, do not have v_head weight
except (EntryNotFoundError, LocalEntryNotFoundError, HFValidationError):
# not continue training, do not have v_head weight
is_resuming_training = False
logging.warning(
f"A {type(pretrained_model)} model is loaded from '{pretrained_model_name_or_path}', "
Expand All @@ -279,6 +282,7 @@ class and the arguments that are specific to trl models. The kwargs
if any([module in k for module in cls.supported_modules]):
files_to_download.add(v)
is_shared = True

if is_resuming_training:
if is_shared:
# download each file and add it to the state_dict
Expand Down