【问题标题】:How do I free all memory on GPU in XGBoost?如何在 XGBoost 中释放 GPU 上的所有内存?
【发布时间】:2019-05-24 19:44:45
【问题描述】:

这是我的代码:

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)

我已经阅读了this question 和这个git issue 上的答案,但都没有奏效。

我尝试用这种方式删除助推器:

clf._Booster.__del__()
gc.collect()

它会删除助推器,但不会完全释放 GPU 内存。

我猜是 Dmatrix 仍然存在,但我不确定。

如何释放整个内存?

【问题讨论】:

    标签: python gpu xgboost


    【解决方案1】:

    好吧,我认为没有办法可以访问已加载的 Dmatrix,因为 fit 函数不会返回它。 可以查看源代码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
    

    【讨论】:

      猜你喜欢
      • 2021-04-24
      • 2019-02-11
      • 2022-01-27
      • 2017-04-23
      • 2016-01-01
      • 2018-09-07
      • 2019-12-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多