如何在 XGBoost 中释放 GPU 上的所有内存?
How do I free all memory on GPU in XGBoost?
这是我的代码:
clf = xgb.XGBClassifier(
tree_method = 'gpu_hist',
gpu_id = 0,
n_gpus = 4,
random_state = 55,
n_jobs = -1
)
clf.set_params(**params)
clf.fit(X_train, y_train, **fit_params)
我已经阅读了 and this git issue 上的答案,但都没有用。
我试过这样删除助推器:
clf._Booster.__del__()
gc.collect()
它会删除助推器,但不会完全释放 GPU 内存。
我想 Dmatrix
仍然存在,但我不确定。
如何释放整个内存?
好吧,我认为您无法访问已加载的 Dmatrix,因为 fit
函数没有 return 它。
你可以查看源代码 here on this github link:
所以我认为最好的方法是将它包装在一个进程中,然后 运行 那样,就像这样:
from multiprocessing import Process
def fitting(args):
clf = xgb.XGBClassifier(tree_method = 'gpu_hist',gpu_id = 0,n_gpus = 4, random_state = 55,n_jobs = -1)
clf.set_params(**params)
clf.fit(X_train, y_train, **fit_params)
#save the model here on the disk
fitting_process = Process(target=fitting, args=(args))
fitting process.start()
fitting_process.join()
# load the model from the disk here
这是我的代码:
clf = xgb.XGBClassifier(
tree_method = 'gpu_hist',
gpu_id = 0,
n_gpus = 4,
random_state = 55,
n_jobs = -1
)
clf.set_params(**params)
clf.fit(X_train, y_train, **fit_params)
我已经阅读了
我试过这样删除助推器:
clf._Booster.__del__()
gc.collect()
它会删除助推器,但不会完全释放 GPU 内存。
我想 Dmatrix
仍然存在,但我不确定。
如何释放整个内存?
好吧,我认为您无法访问已加载的 Dmatrix,因为 fit
函数没有 return 它。
你可以查看源代码 here on this github link:
所以我认为最好的方法是将它包装在一个进程中,然后 运行 那样,就像这样:
from multiprocessing import Process
def fitting(args):
clf = xgb.XGBClassifier(tree_method = 'gpu_hist',gpu_id = 0,n_gpus = 4, random_state = 55,n_jobs = -1)
clf.set_params(**params)
clf.fit(X_train, y_train, **fit_params)
#save the model here on the disk
fitting_process = Process(target=fitting, args=(args))
fitting process.start()
fitting_process.join()
# load the model from the disk here