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(trainer): load checkpoint without ckpt_path which doesn't allow for updated hyperparameters #46

Merged
merged 1 commit into from
Sep 18, 2023
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
31 changes: 29 additions & 2 deletions everyvoice/base_cli/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import os
from enum import Enum
from pathlib import Path
from pprint import pformat

Check warning on line 10 in everyvoice/base_cli/helpers.py

View check run for this annotation

Codecov / codecov/patch

everyvoice/base_cli/helpers.py#L10

Added line #L10 was not covered by tests
from typing import List, Optional, Union

from deepdiff import DeepDiff

Check warning on line 13 in everyvoice/base_cli/helpers.py

View check run for this annotation

Codecov / codecov/patch

everyvoice/base_cli/helpers.py#L13

Added line #L13 was not covered by tests
from loguru import logger
from tqdm import tqdm

Expand Down Expand Up @@ -147,8 +149,33 @@
and os.path.exists(config.training.finetune_checkpoint)
else None
)
tensorboard_logger.log_hyperparams(config.dict())
trainer.fit(model_obj, data, ckpt_path=last_ckpt)
# Train from Scratch
if last_ckpt is None:
model_obj = model(config)
tensorboard_logger.log_hyperparams(config.dict())
trainer.fit(model_obj, data)

Check warning on line 156 in everyvoice/base_cli/helpers.py

View check run for this annotation

Codecov / codecov/patch

everyvoice/base_cli/helpers.py#L154-L156

Added lines #L154 - L156 were not covered by tests
else:
model_obj = model.load_from_checkpoint(last_ckpt)

Check warning on line 158 in everyvoice/base_cli/helpers.py

View check run for this annotation

Codecov / codecov/patch

everyvoice/base_cli/helpers.py#L158

Added line #L158 was not covered by tests
# Check if the trainer has changed (but ignore subdir since it is specific to the run)
diff = DeepDiff(model_obj.config.training.dict(), config.training.dict())

Check warning on line 160 in everyvoice/base_cli/helpers.py

View check run for this annotation

Codecov / codecov/patch

everyvoice/base_cli/helpers.py#L160

Added line #L160 was not covered by tests
training_config_diff = [
item for item in diff["values_changed"].items() if "sub_dir" not in item[0]
]
if training_config_diff:
model_obj.config.training = config.training
tensorboard_logger.log_hyperparams(config.dict())

Check warning on line 166 in everyvoice/base_cli/helpers.py

View check run for this annotation

Codecov / codecov/patch

everyvoice/base_cli/helpers.py#L165-L166

Added lines #L165 - L166 were not covered by tests
# Finetune from Checkpoint
logger.warning(

Check warning on line 168 in everyvoice/base_cli/helpers.py

View check run for this annotation

Codecov / codecov/patch

everyvoice/base_cli/helpers.py#L168

Added line #L168 was not covered by tests
f"""Some of your training hyperparameters have changed from your checkpoint at '{last_ckpt}', so we will override your checkpoint hyperparameters.
Your training logs will start from epoch 0/step 0, but will still use the weights from your checkpoint. Values Changed: {pformat(training_config_diff)}
"""
)
trainer.fit(model_obj, data)

Check warning on line 173 in everyvoice/base_cli/helpers.py

View check run for this annotation

Codecov / codecov/patch

everyvoice/base_cli/helpers.py#L173

Added line #L173 was not covered by tests
else:
logger.info(f"Resuming from checkpoint '{last_ckpt}'")

Check warning on line 175 in everyvoice/base_cli/helpers.py

View check run for this annotation

Codecov / codecov/patch

everyvoice/base_cli/helpers.py#L175

Added line #L175 was not covered by tests
# Resume from checkpoint
tensorboard_logger.log_hyperparams(config.dict())
trainer.fit(model_obj, data, ckpt_path=last_ckpt)

Check warning on line 178 in everyvoice/base_cli/helpers.py

View check run for this annotation

Codecov / codecov/patch

everyvoice/base_cli/helpers.py#L177-L178

Added lines #L177 - L178 were not covered by tests


def inference_base_command(name: Enum):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
clipdetect>=0.1.3
deepdiff>=6.5.0
anytree>=2.8.0
einops==0.5.0
g2p>=1.0.20230417
Expand Down