Skip to content

Commit

Permalink
fix(ml): change early stopping implementation
Browse files Browse the repository at this point in the history
Early stopping now terminates one epoch later
  • Loading branch information
DerYeger committed Oct 15, 2024
1 parent 6b28267 commit b01d699
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ml/gnn/src/gnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"Please provide the train, validation, and test dataset file paths as arguments"
)

num_epochs = 2000
num_epochs = 100
start_epoch = 0
patience = 10

Expand Down
2 changes: 1 addition & 1 deletion ml/gnn/src/model/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def fit(
remaining_patience = patience
else:
remaining_patience -= 1
if remaining_patience == 0:
if remaining_patience < 0:
self.layout_proxy.print(
f"{text_padding}Early stopping in epoch {epoch}"
)
Expand Down
2 changes: 1 addition & 1 deletion ml/tree-lstm/src/paper/mdeoperation.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def train(
remaining_patience = args.patience
else:
remaining_patience -= 1
if remaining_patience == 0:
if remaining_patience < 0:
print(f"Early stopping in epoch {epoch}")
break
sys.stdout.flush()
Expand Down
4 changes: 0 additions & 4 deletions ml/tree-lstm/src/tree_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ def load(self):
dataset_load_start_time = time.perf_counter()
if self.is_cached:
self.data, self.metadata, self.vocabulary = torch.load(self.dataset_cache_file)
# TODO?
# self.to(device)
else:
with open(self.dataset_path, "r") as file:
dataset_input = json.load(file)
Expand All @@ -42,8 +40,6 @@ def load(self):
(self.data, self.metadata, self.vocabulary),
self.dataset_cache_file,
)
# TODO?
# self.to(device)

dataset_load_end_time = time.perf_counter()
print(
Expand Down

0 comments on commit b01d699

Please sign in to comment.