Release Memory After CV Folds and Optimization Trials
Problem
During cross-validation and hyperparameter optimization, large models (especially GPU-based ones) are kept in memory across folds/trials. This leads to excessive memory consumption and potential OOM errors, particularly when using CUDA-enabled models like CatBoost on GPU or TabPFN.
Solution
Introduced a centralized release_memory() utility in mother/utils.py that:
- Runs Python garbage collection (
gc.collect())
- Synchronizes and flushes the CUDA GPU cache when PyTorch is available and a GPU is present
- Is a safe no-op when PyTorch is not installed or no GPU exists
This function is called in two key locations:
-
mother/pipeline_utils.py — mother_cv(): After each CV fold completes, the fold estimator is explicitly deleted and release_memory() is called, freeing both CPU and GPU resources between folds.
-
mother/optimization/core.py — MotherTuner: Replaced the existing bare gc.collect() call with release_memory(), adding GPU cache cleanup to the optimization loop as well.
Changes
| File |
Change |
mother/utils.py |
Added release_memory() function with gc.collect() + conditional CUDA cache flush |
mother/pipeline_utils.py |
Call del val_estimator + release_memory() after each CV fold |
mother/optimization/core.py |
Replace gc.collect() with release_memory() |
Notes
- No new dependencies — PyTorch import is optional and guarded by a try/except at module level
- Fully backward-compatible; no API changes
Release Memory After CV Folds and Optimization Trials
Problem
During cross-validation and hyperparameter optimization, large models (especially GPU-based ones) are kept in memory across folds/trials. This leads to excessive memory consumption and potential OOM errors, particularly when using CUDA-enabled models like CatBoost on GPU or TabPFN.
Solution
Introduced a centralized
release_memory()utility inmother/utils.pythat:gc.collect())This function is called in two key locations:
mother/pipeline_utils.py—mother_cv(): After each CV fold completes, the fold estimator is explicitly deleted andrelease_memory()is called, freeing both CPU and GPU resources between folds.mother/optimization/core.py—MotherTuner: Replaced the existing baregc.collect()call withrelease_memory(), adding GPU cache cleanup to the optimization loop as well.Changes
mother/utils.pyrelease_memory()function withgc.collect()+ conditional CUDA cache flushmother/pipeline_utils.pydel val_estimator+release_memory()after each CV foldmother/optimization/core.pygc.collect()withrelease_memory()Notes