fixing the hangup of training after multiple back to back training processes

This commit is contained in:
Manan17 2026-02-18 08:18:13 +00:00
commit 76cd1dc24c
2 changed files with 9 additions and 0 deletions

View file

@ -115,6 +115,14 @@ class UnslothTrainer:
is_dataset_multimodal: bool = False) -> bool:
"""Load model for training (supports both text and vision models)"""
try:
if self.model is not None:
del self.model
if self.tokenizer is not None:
del self.tokenizer
if self.trainer is not None:
del self.trainer
print("\nClearing GPU memory before training...")
clear_gpu_cache()

View file

@ -120,6 +120,7 @@ def clear_gpu_cache():
if device == DeviceType.CUDA:
import torch
torch.cuda.synchronize()
torch.cuda.empty_cache()
torch.cuda.ipc_collect()
elif device == DeviceType.MLX: