Python 如何在XGBoost中释放GPU上的所有内存?

Python 如何在XGBoost中释放GPU上的所有内存?,python,gpu,xgboost,Python,Gpu,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) 我已经读了关于这个的答案,但都不起作用 我试图通过以下方式删除增压器: clf._Booster.__del__()

这是我的密码:

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
,但我不确定


如何释放整个内存?

嗯,我认为没有办法访问加载的数据矩阵,因为
fit
函数不会返回它。 您可以检查源代码:

因此,我认为最好的方法是将其包装在一个流程中并以这种方式运行,如下所示:

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