Моделирование Xgboost внутри многопроцессорной обработки. Сбой процесса при втором запуске на GPU-сервере - PullRequest
0 голосов
/ 20 сентября 2019

У меня проблемы с сочетанием xgboost, многопроцессорности и pickle на GPU-сервере.Он работает на моем Mac.

Я запускаю xgboost 0.90 в среде Python 3.7.4 Conda на сервере Linux (карта Quadro M5000 GPU), неоднократно, для настройки гиперпараметров.Чтобы освободить память GPU между запусками, я запускаю обучение xgboost внутри многопроцессорной обработки. Процесс ( Как освободить всю память на GPU в XGBoost? ).

Мне нужен объект модели из каждого прогона, поэтому я сохраняю его в файл рассола, который читается вне процесса.При втором запуске код завершается ошибкой, останавливая необходимый цикл по сетке гиперпараметров.В приведенном ниже коде я также попытался вернуть объект модели через очередь, но это не помогло.

q.put(("Finished xgb_model0()", model))

В ml_funcs.py:

# ml_funcs.py
import pickle
import xgboost as xgb
import multiprocessing as mp

def xgb_model0(params, dtrain, num_boost_round, save_folder, q):
    model = xgb.train(params=params,
                      dtrain=dtrain,
                      num_boost_round=num_boost_round
                      )
    with open(save_folder + 'model.pkl', 'wb') as fname:
        pickle.dump(model, fname)
    q.put(("Finished xgb_model0()"))

def xgb_model(params, dtrain, num_boost_round, logginglevel, save_folder):
    q = mp.Queue()
    proc = mp.Process(target=xgb_model0, name='model',
                      args=(params, dtrain, num_boost_round, save_folder, q))
    proc.start()
    proc.join()
    result = q.get()
    return result
* 1012 определены две функциикод:
import numpy as np
import xgboost as xgb
from ml_funcs import xgb_model
import os
import pickle
import multiprocessing as mp
import logging

mpl = mp.log_to_stderr()
mpl.setLevel(logging.getLevelName('INFO'))

data_folder = os.path.expanduser('~/xgboost_debugging/')
save_folder=os.path.expanduser('~/tmp/buffer/')

size = 8000
np.random.seed(seed=42)
y_train = np.random.rand(size)
X_train = np.random.rand(size, 2)
weight_train = np.random.rand(size)

dtrain = xgb.DMatrix(data=X_train, label=y_train,
                     weight=weight_train, feature_names=['x1', 'x2'])

params = {'tree_method': 'hist'}
num_boost_round = 10

result1 = xgb_model(params, dtrain, num_boost_round, 'ERROR', save_folder)
with open(save_folder + 'model.pkl', 'rb') as fname:
    model1 = pickle.load(fname)

print('First run: result1:', result1, ' model1:', model1)

result2 = xgb_model(params, dtrain, num_boost_round, 'INFO', save_folder)

Весь код работает на Mac (без карты GPU).Это также успешно выполняется на GPU-сервере, но ТОЛЬКО, если последняя строка (result2 = ...) опущена, и для «tree_method», равного «hist» и «gpu_hist».

Но включая последнююна линии на GPU-сервере произойдет сбой, завершив настройку гиперпараметра .-

Для 'tree_method': 'hist' (ошибка CUDA, даже если CUDA не используется):

terminate called after throwing an instance of 'dmlc::Error'
  what():  [13:14:44] /workspace/src/common/common.h:41: /workspace/src/common/host_device_vector.cu: 150: initialization error
Stack trace:
  [bt] (0) /home/geiringe/miniconda3/envs/env-74-conda-pip-090/xgboost/libxgboost.so(dh::ThrowOnCudaError(cudaError, char const*, int)+0x3b5) [0x7efe30d32b95]
  [bt] (1) /home/geiringe/miniconda3/envs/env-74-conda-pip-090/xgboost/libxgboost.so(xgboost::HostDeviceVectorImpl<int>::DeviceShard::LazyResize(unsigned long)+0xdd) [0x7efe30d6778d]
  [bt] (2) /home/geiringe/miniconda3/envs/env-74-conda-pip-090/xgboost/libxgboost.so(xgboost::HostDeviceVectorImpl<int>::DeviceShard::Init(xgboost::HostDeviceVectorImpl<int>*, int)+0xc8) [0x7efe30d67858]
  [bt] (3) /home/geiringe/miniconda3/envs/env-74-conda-pip-090/xgboost/libxgboost.so(+0x2c19a4) [0x7efe30d679a4]
  [bt] (4) /home/geiringe/miniconda3/envs/env-74-conda-pip-090/bin/../lib/libgomp.so.1(GOMP_parallel+0x42) [0x7efeac014e92]
  [bt] (5) /home/geiringe/miniconda3/envs/env-74-conda-pip-090/xgboost/libxgboost.so(xgboost::HostDeviceVectorImpl<int>::InitShards()+0x153) [0x7efe30d6fab3]
  [bt] (6) /home/geiringe/miniconda3/envs/env-74-conda-pip-090/xgboost/libxgboost.so(xgboost::HostDeviceVectorImpl<int>::Shard(xgboost::GPUDistribution const&)+0xa2) [0x7efe30d702d2]
  [bt] (7) /home/geiringe/miniconda3/envs/env-74-conda-pip-090/xgboost/libxgboost.so(xgboost::obj::RegLossObj<xgboost::obj::LinearSquareLoss>::GetGradient(xgboost::HostDeviceVector<float> const&, xgboost::MetaInfo const&, int, xgboost::HostDeviceVector<xgboost::detail::GradientPairInternal<float> >*)+0x4d9) [0x7efe30db1b09]
  [bt] (8) /home/geiringe/miniconda3/envs/env-74-conda-pip-090/xgboost/libxgboost.so(xgboost::LearnerImpl::UpdateOneIter(int, xgboost::DMatrix*)+0x345) [0x7efe30c40505]

Для 'tree_method': 'gpu_hist':

terminate called after throwing an instance of 'dmlc::Error'
  what():  [13:17:26] /workspace/src/common/common.h:41: /workspace/src/predictor/../common/device_helpers.cuh: 113: initialization error
Stack trace:
  [bt] (0) /home/geiringe/miniconda3/envs/env-74-conda-pip-090/xgboost/libxgboost.so(dh::ThrowOnCudaError(cudaError, char const*, int)+0x3b5) [0x7f5bd894bb95]
  [bt] (1) /home/geiringe/miniconda3/envs/env-74-conda-pip-090/xgboost/libxgboost.so(dh::MaxSharedMemory(int)+0x24) [0x7f5bd89ce0a4]
  [bt] (2) /home/geiringe/miniconda3/envs/env-74-conda-pip-090/xgboost/libxgboost.so(+0x30f1a7) [0x7f5bd89ce1a7]
  [bt] (3) /home/geiringe/miniconda3/envs/env-74-conda-pip-090/bin/../lib/libgomp.so.1(GOMP_parallel+0x42) [0x7f5c4401ce92]
  [bt] (4) /home/geiringe/miniconda3/envs/env-74-conda-pip-090/xgboost/libxgboost.so(void dh::ExecuteIndexShards<xgboost::predictor::GPUPredictor::DeviceShard, xgboost::predictor::GPUPredictor::ConfigureShards(xgboost::GPUSet)::{lambda(unsigned long, xgboost::predictor::GPUPredictor::DeviceShard&)#1}>(std::vector<xgboost::predictor::GPUPredictor::DeviceShard, std::allocator<std::vector> >*, xgboost::predictor::GPUPredictor::ConfigureShards(xgboost::GPUSet)::{lambda(unsigned long, xgboost::predictor::GPUPredictor::DeviceShard&)#1})+0xab) [0x7f5bd89ce78b]
  [bt] (5) /home/geiringe/miniconda3/envs/env-74-conda-pip-090/xgboost/libxgboost.so(xgboost::predictor::GPUPredictor::Init(std::vector<std::pair<std::string, std::string>, std::allocator<std::pair<std::string, std::string> > > const&, std::vector<std::shared_ptr<xgboost::DMatrix>, std::allocator<std::shared_ptr<xgboost::DMatrix> > > const&)+0x69e) [0x7f5bd89d41fe]
  [bt] (6) /home/geiringe/miniconda3/envs/env-74-conda-pip-090/xgboost/libxgboost.so(xgboost::gbm::GBTree::Configure(std::vector<std::pair<std::string, std::string>, std::allocator<std::pair<std::string, std::string> > > const&)+0x472) [0x7f5bd8844822]
  [bt] (7) /home/geiringe/miniconda3/envs/env-74-conda-pip-090/xgboost/libxgboost.so(void xgboost::GradientBooster::Configure<std::_Rb_tree_iterator<std::pair<std::string const, std::string> > >(std::_Rb_tree_iterator<std::pair<std::string const, std::string> >, std::_Rb_tree_iterator<std::pair<std::string const, std::string> >)+0xd1) [0x7f5bd884d711]
  [bt] (8) /home/geiringe/miniconda3/envs/env-74-conda-pip-090/xgboost/libxgboost.so(xgboost::LearnerImpl::LazyInitModel()+0x45e) [0x7f5bd885508e]
...