main
黄海 1 year ago
parent 17af74295c
commit f63fdc2720

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

@ -0,0 +1,33 @@
# pip install pynvml
from pynvml import *
import torch
import gc
# 显示GPU显存使用情况
def getVRam():
# 初始化
nvmlInit()
# GPU 0 ,一般都只有一张显卡
h = nvmlDeviceGetHandleByIndex(0)
info = nvmlDeviceGetMemoryInfo(h)
print(f'total: {round(info.total / 1024 / 1024 / 1024, 1)} GB')
print(f'free : {round(info.free / 1024 / 1024 / 1024, 1)} GB')
print(f'used : {round(info.used / 1024 / 1024 / 1024, 1)} GB')
nvmlShutdown()
# 输出一下显存的占用
getVRam()
# 如果输出的结果是False那么说明当前的Pytorch版本无法使用显卡。
if torch.cuda.is_available():
# GPU可用启动显存清理
gc.collect()
torch.cuda.empty_cache()
torch.cuda.ipc_collect()
gc.collect()
# 再显示一下显存的占用
getVRam()
else:
print("当前机器不支持显卡清理!")

@ -218,8 +218,7 @@ def get_task():
vjson_data = json.load(file)
# 利用三元表达式输出
printf("发现需要处理的" + ("WebUI" if model_type_id in [1,
2] else "ComfyUI") + "任务,model_type_id=" + str(
printf("发现需要处理的" + ("WebUI" if model_type_id in [1, 2] else "ComfyUI") + "任务,model_type_id=" + str(
model_type_id) + ",model_id=" + str(
model_id) + ",prompt_id=" + str(prompt_id) + ",task_id=" + str(task_id))

Loading…
Cancel
Save