mirror of
https://github.com/kohya-ss/sd-scripts.git
synced 2026-04-08 22:35:09 +00:00
Refactor memory cleaning into a single function
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import argparse
|
||||
import gc
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
@@ -12,6 +11,7 @@ import toml
|
||||
from tqdm import tqdm
|
||||
import torch
|
||||
|
||||
from library.device_utils import clean_memory
|
||||
from library.ipex_interop import init_ipex
|
||||
|
||||
init_ipex()
|
||||
@@ -163,9 +163,7 @@ def train(args):
|
||||
accelerator.is_main_process,
|
||||
)
|
||||
vae.to("cpu")
|
||||
if torch.cuda.is_available():
|
||||
torch.cuda.empty_cache()
|
||||
gc.collect()
|
||||
clean_memory()
|
||||
|
||||
accelerator.wait_for_everyone()
|
||||
|
||||
@@ -264,8 +262,7 @@ def train(args):
|
||||
# move Text Encoders for sampling images. Text Encoder doesn't work on CPU with fp16
|
||||
text_encoder1.to("cpu", dtype=torch.float32)
|
||||
text_encoder2.to("cpu", dtype=torch.float32)
|
||||
if torch.cuda.is_available():
|
||||
torch.cuda.empty_cache()
|
||||
clean_memory()
|
||||
else:
|
||||
# make sure Text Encoders are on GPU
|
||||
text_encoder1.to(accelerator.device)
|
||||
|
||||
Reference in New Issue
Block a user