Ehs*_*thi 8 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)
Run Code Online (Sandbox Code Playgroud)
我尝试用这种方式删除助推器:
clf._Booster.__del__()
gc.collect()
Run Code Online (Sandbox Code Playgroud)
它会删除助推器,但不会完全释放 GPU 内存。
我想它Dmatrix仍然在那里,但我不确定。
我怎样才能释放整个内存?
好吧,我认为没有办法可以访问加载的 Dmatrix,因为该fit函数不会返回它。你可以在这个 github 链接上查看源代码:
所以我认为最好的方法是将其包装在一个进程中并以这种方式运行它,如下所示:
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3887 次 |
| 最近记录: |