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

Apply garbage collection interval to validation steps #6870

Merged
merged 2 commits into from
Jun 14, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def __init__(self, cfg: DictConfig, trainer: Trainer, no_lm_init=True):
# The automatic garbage collector sould be disabled before training starts.
if self.gc_interval > 0:
gc.disable()
self.validation_global_step = 1

def _enable_nvidia_optimizations(self):
"These optimizations are present in NVIDIA NGC PyTorch Containers"
Expand Down Expand Up @@ -218,6 +219,16 @@ def on_train_start(self) -> None:
super().on_train_start()
self.init_global_step = self.trainer.global_step

def on_validation_start(self) -> None:
super().on_validation_start()
if self.gc_interval > 0:
gc.collect()

def on_validation_end(self) -> None:
super().on_validation_end()
if self.gc_interval > 0:
gc.collect()

def _build_vocab(self):
"""
Manipulate vocabulary (e.g., pad vocabulary for increased performance)/
Expand Down Expand Up @@ -366,6 +377,14 @@ def on_train_batch_end(self, outputs, dataloader_iter: Any, batch_idx: int, unus
if self.gc_interval > 0 and (self.trainer.global_step % self.gc_interval == 0):
gc.collect()

def on_validation_batch_end(self, outputs, batch: Any, batch_idx: int, dataloader_idx: int) -> None:
super().on_validation_batch_end(outputs, batch, batch_idx, dataloader_idx)

if self.gc_interval > 0:
if self.validation_global_step % self.gc_interval == 0:
gc.collect()
self.validation_global_step += 1

def setup_optimization(
self, optim_config: Optional[Union[DictConfig, Dict]] = None, optim_kwargs: Optional[Dict[str, Any]] = None,
):
Expand Down
Loading