Machine Learning

LightGBM, XGBoost gpu 가속 설정

yssy431 2020. 7. 22. 23:24

회사내에서 머신러닝 작업을 하며 쓰는 모듈로 점차 데이터량이 늘어나게 되며 cpu의 한계를 느끼게 됨

그래서 사용하는 모듈들의 GPU사용 방법을 찾아보게되며 검색한 결과

차후에 또 설정을 할 일이 있을 것 같기에 간단하게 정리해본다.

 

LightGBM gpu install 관련 Document - https://lightgbm.readthedocs.io/en/latest/GPU-Tutorial.html

XGBoost gpu install 관련 Document - https://xgboost.readthedocs.io/en/release_0.81/build.html

위의 해당 두개 문서를 참고하며 설치를 진행 

Linux - Ubuntu 16.04 LST 버전에서 진행하였으며 Virtualenv로 설치한 Jupyter Server에 설치를 하려다보니 생각보다 많은 시행착오를 겪음

 

첫번째 단계

- git clone --recursive https://github.com/microsoft/LightGBM 

- git clone --recursive https://github.com/dmlc/xgboost  

둘다 git으로 pakage를 가져온다.

 

두번째 단계

- install을 진행하기에 앞서서 여러 의존성 툴들을 설치해야한다. (CUDA설치 필수)

sudo apt-get install --no-install-recommends git cmake build-essential libboost-dev libboost-system-dev libboost-filesystem-dev

● 여기서 xgboost를 install 할 때 cmake 버전이 낮다면서 안될때가 있기에 직접 최신 버전을 설치했었다.

1) 기존 cmake를 제거

sudo apt purge cmake

2)  https://cmake.org/download/에서 wget으로 file 다운

tar -zxf cmake-버젼
cd 압축 푼 폴더
./bootstrap
make
sudo make install

설치 완료 후 cmake --version을 했을 시 버전이 나오지 않을때 vi ~/.bashrc 파일에 경로 추가를 해준다.

 

세번째 단계

- 해당 폴더내에 python-package 폴더내에 들어 간 후 sudo python setup.py install --gpu를 하게 되면 둘다 자동으로 설치 된다.

● virtualenv등 가상에서 설치할때에 sudo python setup.py install에서 python의 경로를 강제로 가상의 파이썬 버젼으로 경로를 주어 실행하면 해당 가상환경으로 설치가 완료된다.

● 만약에 설치가 안될 시 직접 build를 해야한다.

git clone --recursive https://github.com/Microsoft/LightGBM
cd LightGBM
mkdir build ; cd build
cmake -DUSE_GPU=1 ..
make -j$(nproc)
git clone --recursive https://github.com/dmlc/xgboost
cd xgboost
mkdir build
cd build
cmake .. -DUSE_CUDA=ON
make -j4