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.

Update vision.py

Daniel Han1444b1011a0d
diff --git a/unsloth/models/vision.py b/unsloth/models/vision.py
index f0b0bdff1ea..788df4c74ec 100644
--- a/unsloth/models/vision.py
+++ b/unsloth/models/vision.py
@@ -435,8 +435,20 @@ class FastBaseModel:
# Edit data-types
if custom_datatype is not None:
- for name, module in model.named_modules():
+ for jj, (name, module) in enumerate(model.named_modules()):
exec(custom_datatype)
+ if jj % 10 == 0:
+ gc.collect()
+ if DEVICE_TYPE == "cuda": torch.cuda.empty_cache()
+ elif DEVICE_TYPE == "xpu": torch.xpu.empty_cache()
+ pass
+ pass
+ # Clear deleted GPU items
+ for _ in range(3):
+ gc.collect()
+ if DEVICE_TYPE == "cuda": torch.cuda.empty_cache()
+ elif DEVICE_TYPE == "xpu": torch.xpu.empty_cache()
+ pass
pass
# Counteract saved tokenizers