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 peft resume #10887

Merged
merged 1 commit into from
Oct 15, 2024
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
15 changes: 11 additions & 4 deletions nemo/lightning/resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ def setup(self, trainer: Union[pl.Trainer, fl.Fabric], model=None):
trainer.checkpoint_callback.last_model_path = trainer_ckpt_path
# Load artifacts
if getattr(self.restore_config, 'load_artifacts', False):
context_path = self.get_context_path(model)
if isinstance(trainer_ckpt_path, AdapterPath):
# load tokenizer from the base model during peft resume, in case the first peft checkpoint
# is deleted before the current peft checkpoint is saved
context_path = trainer_ckpt_path.base_model_path / "context"
if not context_path.exists():
context_path = trainer_ckpt_path.base_model_path
else:
context_path = self.get_context_path(model)
model = _try_restore_tokenizer(model, context_path)

elif self.restore_config:
Expand Down Expand Up @@ -150,9 +157,9 @@ def _resume_peft(self, adapter_meta_path, model):

assert self.restore_config, "PEFT resume requires specifying restore_config"
base_model_path = self._extract_path(model, self.restore_config.path)
if base_model_path != Path(metadata['model_ckpt_path']):
raise ValueError(
f"When trying to resume a PEFT training run, found mismatching values: "
if base_model_path not in [Path(metadata['model_ckpt_path']), Path(metadata['model_ckpt_path']).parent]:
logging.warning(
f"⚠️ When trying to resume a PEFT training run, found mismatching values: "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice emoji haha

f"your specified restore_path points to {base_model_path}, "
f"but the PEFT checkpoint was trained with "
f"model_ckpt_path={metadata['model_ckpt_path']}"
Expand Down
Loading