Skip to content

Commit

Permalink
Run garbage collector between batches.
Browse files Browse the repository at this point in the history
  • Loading branch information
james-choncholas committed Nov 10, 2024
1 parent 0c0ecac commit 364c448
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tf_shell_ml/model_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import tf_shell
import tf_shell_ml
import time
import gc


class SequentialBase(keras.Sequential):
Expand Down Expand Up @@ -213,6 +214,8 @@ def fit(
features_dataset, labels_dataset = self.prep_dataset_for_model(
features_dataset, labels_dataset
)
tf.keras.backend.clear_session()
gc.collect()

# Calculate samples if possible.
if steps_per_epoch is None:
Expand Down Expand Up @@ -251,6 +254,7 @@ def fit(
callback_list.on_train_batch_begin(step, logs)
logs, num_slots = self.train_step_tf_func(batch_x, batch_y)
callback_list.on_train_batch_end(step, logs)
gc.collect()
if steps_per_epoch is not None and step + 1 >= steps_per_epoch:
break

Expand Down

0 comments on commit 364c448

Please sign in to comment.