Skip to content

Commit

Permalink
(MA) added ETA printouts to the hyperparameter search
Browse files Browse the repository at this point in the history
  • Loading branch information
amkrajewski committed Mar 29, 2024
1 parent 36fce5a commit ff16218
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pysipfenn/core/modelAdjusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from functools import reduce
import operator
from random import shuffle
import time

# Default 3rd party imports
import numpy as np
Expand Down Expand Up @@ -451,8 +452,10 @@ def matrixHyperParameterSearch(
verbose: Same as in the ``adjust`` method. Default is ``True``.
plot: Whether to plot the training history after all the combinations are tested. Default is ``True``.
"""
nTasks = len(learningRates) * len(optimizers) * len(weightDecays)
if verbose:
print("Starting the hyperparameter search...")
print(f"{nTasks} combinations will be tested.\n")

Check warning on line 458 in pysipfenn/core/modelAdjusters.py

View check run for this annotation

Codecov / codecov/patch

pysipfenn/core/modelAdjusters.py#L455-L458

Added lines #L455 - L458 were not covered by tests

bestModel: torch.nn.Module = None
bestTrainingLoss: float = np.inf
Expand All @@ -467,6 +470,8 @@ def matrixHyperParameterSearch(
trainLossHistory: List[List[float]] = []
validationLossHistory: List[List[float]] = []
labels: List[str] = []
tasksDone = 0
t0 = time.perf_counter()

Check warning on line 474 in pysipfenn/core/modelAdjusters.py

View check run for this annotation

Codecov / codecov/patch

pysipfenn/core/modelAdjusters.py#L470-L474

Added lines #L470 - L474 were not covered by tests

for learningRate in learningRates:
for optimizer in optimizers:
Expand Down Expand Up @@ -517,6 +522,11 @@ def matrixHyperParameterSearch(
else:
print(f"Model with LR: {learningRate}, OPT: {optimizer}, WD: {weightDecay} did not improve.")

Check warning on line 523 in pysipfenn/core/modelAdjusters.py

View check run for this annotation

Codecov / codecov/patch

pysipfenn/core/modelAdjusters.py#L523

Added line #L523 was not covered by tests

tasksDone += 1
pastTimePerTask = ((time.perf_counter() - t0)/60) / tasksDone
print(f"Task {tasksDone}/{nTasks} done. Estimated time left: {pastTimePerTask * (nTasks - tasksDone):.2f} minutes.\n")

Check warning on line 527 in pysipfenn/core/modelAdjusters.py

View check run for this annotation

Codecov / codecov/patch

pysipfenn/core/modelAdjusters.py#L525-L527

Added lines #L525 - L527 were not covered by tests


if verbose:
print(f"\n\nBest model found with LR: {bestHyperparameters['learningRate']}, OPT: {bestHyperparameters['optimizer']}, "

Check warning on line 531 in pysipfenn/core/modelAdjusters.py

View check run for this annotation

Codecov / codecov/patch

pysipfenn/core/modelAdjusters.py#L530-L531

Added lines #L530 - L531 were not covered by tests
f"WD: {bestHyperparameters['weightDecay']}, Epoch: {bestHyperparameters['epochs']}")
Expand Down

0 comments on commit ff16218

Please sign in to comment.