From 8dd7cfab931c8c98ac8ab33a213e309c7c2f737c Mon Sep 17 00:00:00 2001 From: CyberWon Date: Wed, 26 Jun 2024 22:26:32 +0800 Subject: [PATCH] =?UTF-8?q?Optimize=EF=BC=9A=20=E6=8E=A8=E7=90=86=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E5=90=8E=E8=87=AA=E5=8A=A8=E8=A7=A6=E5=8F=91gc?= =?UTF-8?q?=E5=9B=9E=E6=94=B6=20(#1221)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在推理完成之后,使用gc控制器对内存进行回收。 #1218 --- GPT_SoVITS/TTS_infer_pack/TTS.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/GPT_SoVITS/TTS_infer_pack/TTS.py b/GPT_SoVITS/TTS_infer_pack/TTS.py index e36edeb..c86a077 100644 --- a/GPT_SoVITS/TTS_infer_pack/TTS.py +++ b/GPT_SoVITS/TTS_infer_pack/TTS.py @@ -1,6 +1,6 @@ from copy import deepcopy import math -import os, sys +import os, sys, gc import random import traceback @@ -869,7 +869,8 @@ class TTS: self.empty_cache() def empty_cache(self): - try: + try: + gc.collect() # 触发gc的垃圾回收。避免内存一直增长。 if "cuda" in str(self.configs.device): torch.cuda.empty_cache() elif str(self.configs.device) == "mps": @@ -939,4 +940,4 @@ def speed_change(input_audio:np.ndarray, speed:float, sr:int): # 将管道输出解码为 NumPy 数组 processed_audio = np.frombuffer(out, np.int16) - return processed_audio \ No newline at end of file + return processed_audio