Humphreykowl commited on
Commit
93586eb
·
verified ·
1 Parent(s): 5861720

Update models/model_manager.py

Browse files
Files changed (1) hide show
  1. models/model_manager.py +17 -7
models/model_manager.py CHANGED
@@ -197,10 +197,20 @@ class ModelManager:
197
  color = (random.randint(120, 200), random.randint(120, 200), random.randint(120, 200))
198
  return Image.new('RGB', (width, height), color=color)
199
 
200
- def cleanup(self):
201
- logger.info("释放模型占用显存和缓存...")
202
- try:
203
-
204
- # ...清理代码不变...
205
- except Exception as e:
206
- logger.error(f"清理显存失败: {e}")
 
 
 
 
 
 
 
 
 
 
 
197
  color = (random.randint(120, 200), random.randint(120, 200), random.randint(120, 200))
198
  return Image.new('RGB', (width, height), color=color)
199
 
200
+ def cleanup(self):
201
+ logger.info("释放模型占用显存和缓存...")
202
+ try:
203
+ # 清理模型引用
204
+ del self.caption_model
205
+ del self.clip_model
206
+ del self.sd_pipeline
207
+ del self.controlnet
208
+ del self.controlnet_pipeline
209
+
210
+ # 清理缓存
211
+ if torch.cuda.is_available():
212
+ torch.cuda.empty_cache()
213
+
214
+ logger.info("显存和缓存清理完成")
215
+ except Exception as e:
216
+ logger.error(f"清理显存失败: {e}")