그래디언트 부스팅 (gradient goosting) 을 사용하기 쉽게 구현해둔 패키지는 LightGBM 이나 XGBoost가 있다.
XGBoost 의 경우 콘다 환경에서 간단하게 pip install xgboost 로 설치해도 GPU 사용 방법이 매우 단순하다.
예를 들어 아래와 같이 생성하려는 모델의 tree_method 에 'gpu_hist' 만 넣어주면 된다.
model = XGBRegressor(tree_method='gpu_hist') |
그러나 LightGBM 의 경우 GPU 가속을 사용하려면 설치 방법이 비교적 단순하지 않아서 방법을 정리해둔다.
LightGBM 을 빌드하기 위해서 필요한 툴을 아래와 같이 설치한다. 이 때 리눅스 sudo 권한이 필요하다.
sudo apt-get install --no-install-recommends git cmake build-essential libboost-dev libboost-system-dev libboost-filesystem-dev |
빌드 환경이 구축되었다면 아래와 같이, 깃 저장소의 코드를 다운 받아 빌드를 완료한다.
git clone --recursive https://github.com/Microsoft/LightGBM | |
cd LightGBM && mkdir build && cd build | |
cmake -DUSE_GPU=1 .. | |
make -j4 | |
pip uninstall lightgbm | |
cd ../python-package/ && python setup.py install |
모델 생성할 때 device 에 'gpu'를 주면 된다.
model = lgbm.LGBMRegressor(device='gpu') |
아래를 참고하여 작성하였습니다.
https://lightgbm.readthedocs.io/en/latest/GPU-Tutorial.html
LightGBM GPU Tutorial — LightGBM 3.3.1 documentation
© Copyright 2021, Microsoft Corporation. Revision d4851c33.
lightgbm.readthedocs.io
https://stackoverflow.com/questions/60360750/lightgbm-classifier-with-gpu
Lightgbm classifier with gpu
model = lgbm.LGBMClassifier(n_estimators=1250, num_leaves=128,learning_rate=0.009,verbose=1)`enter code here` using the LGBM classifier is there way to use this with gpu this days?
stackoverflow.com
'노트정리 > 머신러닝 machine leanring' 카테고리의 다른 글
허깅페이스 (huggingface) 모델 다운로드 받기 (1) | 2024.10.19 |
---|---|
케라스 (keras) 에서 모델 저장 또는 가중치 저장 (1) | 2018.08.24 |
케라스(keras) 에서 leaky_relu 쓰기 (0) | 2018.04.01 |