Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

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

Manan1776cd1dc24c70
diff --git a/studio/backend/core/training/trainer.py b/studio/backend/core/training/trainer.py
index df742f64f0d..396c6c4956d 100644
--- a/studio/backend/core/training/trainer.py
+++ b/studio/backend/core/training/trainer.py
@@ -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()
diff --git a/studio/backend/utils/hardware/hardware.py b/studio/backend/utils/hardware/hardware.py
index 754ef6fdaeb..0d7cc97cfbf 100644
--- a/studio/backend/utils/hardware/hardware.py
+++ b/studio/backend/utils/hardware/hardware.py
@@ -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: