2019년 10월 8일 화요일
H2O DriverlessAI에서 큰 dataset을 학습할 때 memory를 적게 사용하도록 하는 설정 방법
H2O DriverlessAI는 서버 메모리를 많이 사용하는 솔루션입니다. 기본적인 rule of thumb은 training dataset의 10배 크기의 서버 메모리가 필요하다는 것입니다. 즉, 만약 training dataset이 30GB라면, 서버 메모리는 300GB 이상 있어야 합니다.
그런데 살다보면 training dataset이 30GB인데 서버 메모리는 100GB 밖에 안 되는 경우도 있습니다. 이런 경우에는 H2O DriverlessAI는 쓰지 못하는 것일까요? 꼭 그렇지는 않습니다.
H2O DriverlessAI는 기본적으로 'data가 너무 크다'라고 생각하면 down-sampling이라는 것을 합니다. 즉, data 중에서 일부만 발췌헤서 training에 사용하는 것입니다.
그렇다면 당연히 몇가지 의문이 생깁니다.
1. '너무 크다'라는 것의 기준은 무엇인가?
당연히 기준이 있어야 하는데, 그건 H2O DriverlessAI의 config.toml이라는 파일 속에 있습니다. 이 파일은 H2O DriverlessAI의 설치 home directory에 들어있습니다. 기본적으로는 아래와 같이 statistical_threshold_data_size_large = 500000000 라는 parameter에 의해 정해지는데, 이 값은 default가 500M으로 되어 있고, 이 값은 data의 byte 수 등이 아니라 rows * columns 의 숫자입니다. 즉, 가령 50개의 column을 가진 CSV 파일의 row수가 10M을 넘어간다면 H2O DriverlessAI는 이 dataset이 '너무 크다' 라고 판단합니다.
[user612@p612-met1 dai-1.7.1-linux-ppc64le]$ vi ./config.toml
...
# Internal threshold for number of rows x number of columns to trigger certain statistical
# techniques (fewer genes created, removal of high max_depth for tree models, etc.) that can speed up modeling.
# Also controls maximum rows used in training final model,
# by sampling statistical_threshold_data_size_large / columns number of rows
#statistical_threshold_data_size_large = 500000000
2. 이 파라미터를 어떻게 얼마나 조정해야 하는가?
만약 이 기본값으로 training할 때 서버 메모리 부족으로 error가 난다면, 이 기준값을 내려야 합니다. 제가 해보니 이 수치가 정확하게 rows * columns를 맞추는 것은 아니니, 정확하게는 try & error를 통해 경험치로 조정하셔야 합니다. 아무튼 이것을 수정하는 방법은 저 config.toml 파일을 수정한 뒤 H2O DriverlessAI를 retstart 하는 것입니다. 아래의 예는 그 기준을 1/5f로 줄인 것입니다.
[user612@p612-met1 dai-1.7.1-linux-ppc64le]$ vi ./config.toml
...
#statistical_threshold_data_size_large = 500000000
statistical_threshold_data_size_large = 100000000
3. Sampling은 어떤 기준으로 이루어지는가?
기본적으로 sampling 할 때는 알아서 적절히 하게 되어 있습니다. 특히 현재 training하려는 문제의 결과가 regression(결과가 숫자로 나오는 경우)의 경우와 classification(몇가지 정해진 카테고리 중 하나로 나오는 것)의 경우에 대해 각각 다릅니다.
- Regression의 경우 : Random sampling (마구잡이 샘플링)
- Classification의 경우 : Stratified sampling (계층별 샘플링)
그런데 특히 sparse data에 대한 classification인 경우, 즉 신용카드사의 정상/비정상 거래처럼 대부분은 정상이고 극히 일부만 비정상 거래인 경우에는 그렇쟎아도 부족한 비정상 거래 data 건수가 더 줄어들지 않을까 염려됩니다. 만약 그렇게 class별로 record 수가 5배 이상 차이가 날 경우, H2O DriverlessAI는 알아서 그 dataset을 imbalanced dataset이라고 판단하고 그에 따라 sampling을 진행합니다.
이런 imbalanced sampling는 "Expert Settings" tab의 "MODEL" 메뉴에서 조정이 가능하며, 다음과 같이 여러가지 방법을 제공합니다.
어떤 sampling 방법이 가장 좋은지에는 정답이 없습니다만, 위에서 언급한 신용카드 사기 거래 dataset과 같이 imbalance가 심한 dataset에서는 잘 판단이 서지 않을 때는 일단 Over_under_sampling을 택하는 것이 낫지 않을까 합니다. (저는 일일이 테스트 해보지는 못했습니다.)
Automatic : 모든 class를 필요에 따라 적절히 sampling (default)
Over_sampling : 소수 class를 더 많이 sampling하여 균형을 맞춤
Under_sampling : 다수 class를 더 적게 sampling하여 균형을 맞춤
Over_under_sampling : 소수 class는 over sampling하고 다수 class는 under sampling하여 균형을 맞춤
Off : Sampling을 하지 않음
4. 이렇게 down-sampling하면 결과로 만들어지는 accuracy에 저하가 발생하지 않는가 ?
당연히 일부 발생할 수도 있습니다. 그런 저하를 용납할 수 없는 상황이시라면 서버 메모리를 더 사셔야 합니다...
## Training의 메모리 필요량을 줄이는 다른 기본적인 방법들
1. Accuracy Dial을 낮춘다
- Accuracy를 높일 수록 좀더 많은 model을 적용해보기 때문에 당연히 메모리 사용량이 늘어납니다. Accuracy dial을 3~4 정도로 낮게 두면 메모리 사용량이 극적으로 줄어듭니다. 그럴 경우 당연히 accuracy도 떨어진다는 단점이 있습니다.
2. Expert Settings tab 중 'MODEL' 메뉴에서 lightGBM을 제외한 모든 model을 off 시킨다
- 무조건 많은 model을 적용한다고 accuracy가 다 높아지는 것은 아닙니다. 실제로 대부분의 경우 lightGBM과 XGBoost에서 가장 좋은 accuracy가 나옵니다. 따라서, Rulefit이나 GLM, Tensorflow 등의 모델들을 off 시켜 놓으면 역시 메모리 사용량이 극적으로 줄어듭니다. 물론 accuracy도 좀 떨어지긴 합니다.
2018년 8월 6일 월요일
H2O DriverlessAI에 포함된 h2o4gpu를 python과 R에서 사용하는 방법
H2O DriverlessAI를 ppc64le 아키텍처인 AC922에 설치하는 것은 매우 간단합니다. 다음 manual대로 하시면 되는데, 여기서는 매뉴얼 보시기 귀찮으신 분들을 위해 초간단으로 정리했습니다.
http://docs.h2o.ai/driverless-ai/latest-stable/docs/userguide/UsingDriverlessAI.pdf
먼저 DriverlessAI의 rpm package를 다음과 같이 download 받습니다.
[root@ING data]# wget https://s3.amazonaws.com/artifacts.h2o.ai/releases/ai/h2o/dai/rel-1.2.2-6/ppc64le-centos7/dai-1.2.2-1.ppc64le.rpm
rpm 명령으로 설치합니다.
[root@ING data]# rpm -Uvh dai-1.2.2-1.ppc64le.rpm
Preparing... ################################# [100%]
Updating / installing...
1:dai-1.2.2-1 ################################# [100%]
User configuration file /etc/dai/User.conf already exists.
Group configuration file /etc/dai/Group.conf already exists.
Configured user in /etc/dai/User.conf is 'dai'.
Configured group in /etc/dai/Group.conf is 'dai'.
Group 'dai' already exists.
User 'dai' already exists.
Adding systemd configuration files in /etc/systemd/system...
Created symlink from /etc/systemd/system/dai.service.wants/dai-dai.service to /usr/lib/systemd/system/dai-dai.service.
Created symlink from /etc/systemd/system/dai.service.wants/dai-h2o.service to /usr/lib/systemd/system/dai-h2o.service.
Created symlink from /etc/systemd/system/dai.service.wants/dai-procsy.service to /usr/lib/systemd/system/dai-procsy.service.
Calling 'systemctl enable dai'...
Created symlink from /etc/systemd/system/multi-user.target.wants/dai.service to /usr/lib/systemd/system/dai.service.
Installation complete.
DAI의 구동도 매우 간단합니다. 아래와 같이 dai.service만 start 해주면 main process와 보조 h2o process, proxy process인 dai-procsy까지 모두 자동으로 뜹니다.
[root@ING ~]# systemctl start dai
[root@ING ~]# systemctl status dai-dai
● dai-dai.service - Driverless AI (Main Application Process)
Loaded: loaded (/usr/lib/systemd/system/dai-dai.service; enabled; vendor preset: disabled)
[root@ING ~]# systemctl status dai-h2o
● dai-h2o.service - Driverless AI (H2O Process)
Loaded: loaded (/usr/lib/systemd/system/dai-h2o.service; enabled; vendor preset: disabled)
[root@ING ~]# systemctl status dai-procsy
● dai-procsy.service - Driverless AI (Procsy Process)
Loaded: loaded (/usr/lib/systemd/system/dai-procsy.service; enabled; vendor preset: disabled)
그리고 test1이라는 user를 만들고, 그 user를 DAI의 기본 user/group인 dai라는 group에 포함시킵니다.
[root@ING ~]# usermod -a -G dai test1
[root@ING ~]# cat /etc/group | grep dai
dai:x:980:test1
다음과 같이 t1.py와 t1.R을 준비합니다. 이것들은 python과 R에서 h2o4gpu를 사용할 수 있는지 확인하는 python 및 R script입니다.
[test1@ING ~]$ cat t1.py
import h2o4gpu
import numpy as np
X = np.array([[1.,1.], [1.,4.], [1.,0.]])
model = h2o4gpu.KMeans(n_clusters=2,random_state=1234).fit(X)
model.cluster_centers_
[test1@ING ~]$ cat t1.R
library(reticulate)
library(h2o4gpu)
use_python("/opt/h2oai/dai/python/bin/python")
x <- iris[1:4]
y <- as.integer(iris$Species)
model <- h2o4gpu.random_forest_classifier() %>% fit(x, y)
pred <- model %>% predict(x)
library(Metrics)
ce(actual = y, predicted = pred)
이제 test1에서 DAI에 포함된 h2o4gpu를 사용하는 방법입니다. 한줄 요약하면, PATH 등 환경변수를 설정하여 DAI에서 제공하는 python 및 PYTHONPATH를 사용하기만 하면 됩니다.
[test1@ING ~]$ export PATH=/opt/h2oai/dai/python/bin:$PATH
[test1@ING ~]$ export LD_LIBRARY_PATH=/opt/h2oai/dai/python/lib:/opt/h2oai/dai/lib:$LD_LIBRARY_PATH
[test1@ING ~]$ export PYTHONPATH=/opt/h2oai/dai/cuda-9.2/lib/python3.6/site-packages
[test1@ING ~]$ pip list | grep h2o
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
h2o (3.20.0.2)
h2o4gpu (0.2.0.9999+master.eb6295c)
h2oai (1.2.2)
h2oai-client (1.2.2)
h2oaicore (1.2.2)
DAI에서 제공하는 python은 3.6이며, 일반 anaconda에서 제공되는 것과 동일합니다. 제가 source로부터 build한 tensorflow 1.8도 pip로 정상적으로 설치해서 동일하게 사용할 수 있습니다.
[test1@ING ~]$ pip install /tmp/tensorflow-1.8.0-cp36-cp36m-linux_ppc64le.whl
[test1@ING ~]$ pip list | grep tensorflow
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
tensorflow (1.8.0)
[test1@ING ~]$ which python
/opt/h2oai/dai/python/bin/python
이제 python에서 저 위의 t1.py를 수행하겠습니다. 여기서는 그냥 line by line으로 copy & paste 했습니다.
[test1@ING ~]$ python
Python 3.6.4 (default, Jun 30 2018, 13:42:46)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import h2o4gpu
>>> import numpy as np
>>> X = np.array([[1.,1.], [1.,4.], [1.,0.]])
>>> model = h2o4gpu.KMeans(n_clusters=2,random_state=1234).fit(X)
>>> model.cluster_centers_
array([[1. , 0.5],
[1. , 4. ]])
>>>
다음으로 R에서 저 위의 t1.R을 수행하겠습니다. 여기서는 그냥 line by line으로 copy & paste 했습니다.
[test1@ING ~]$ R
R version 3.4.1 (2017-06-30) -- "Single Candle"
> library(reticulate)
y <- as.integer(iris$Species)
model <- h2o4gpu.random_forest_classifier() %>% fit(x, y)
pred <- model %>% predict(x)
library(Metrics)
ce(actual = y, predicted = pred)> library(h2o4gpu)
Attaching package: ‘h2o4gpu’
The following object is masked from ‘package:base’:
transform
> use_python("/opt/h2oai/dai/python/bin/python")
> x <- iris[1:4]
> y <- as.integer(iris$Species)
> model <- h2o4gpu.random_forest_classifier() %>% fit(x, y)
> pred <- model %>% predict(x)
/opt/h2oai/dai/python/lib/python3.6/site-packages/sklearn/preprocessing/label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
if diff:
> library(Metrics)
> ce(actual = y, predicted = pred)
[1] 0.02666667
>
또한 tensorflow가 제대로 GPU를 물고 올라오는지 시험해보겠습니다. 물론 잘 됩니다.
[test1@ING ~]$ python
Python 3.6.4 (default, Jun 30 2018, 13:42:46)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
/opt/h2oai/dai/python/lib/python3.6/site-packages/h5py-2.7.1-py3.6-linux-ppc64le.egg/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
>>> sess=tf.Session()
2018-08-06 10:21:44.054091: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 0 with properties:
name: Tesla V100-SXM2-16GB major: 7 minor: 0 memoryClockRate(GHz): 1.53
pciBusID: 0004:04:00.0
totalMemory: 15.75GiB freeMemory: 15.34GiB
2018-08-06 10:21:44.568612: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 1 with properties:
name: Tesla V100-SXM2-16GB major: 7 minor: 0 memoryClockRate(GHz): 1.53
pciBusID: 0004:05:00.0
totalMemory: 15.75GiB freeMemory: 15.34GiB
2018-08-06 10:21:45.033482: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 2 with properties:
name: Tesla V100-SXM2-16GB major: 7 minor: 0 memoryClockRate(GHz): 1.53
pciBusID: 0035:03:00.0
totalMemory: 15.75GiB freeMemory: 15.34GiB
2018-08-06 10:21:45.461878: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 3 with properties:
name: Tesla V100-SXM2-16GB major: 7 minor: 0 memoryClockRate(GHz): 1.53
pciBusID: 0035:04:00.0
totalMemory: 15.75GiB freeMemory: 15.34GiB
2018-08-06 10:21:45.462104: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1435] Adding visible gpu devices: 0, 1, 2, 3
2018-08-06 10:21:47.427824: I tensorflow/core/common_runtime/gpu/gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-08-06 10:21:47.427960: I tensorflow/core/common_runtime/gpu/gpu_device.cc:929] 0 1 2 3
2018-08-06 10:21:47.427989: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 0: N Y Y Y
2018-08-06 10:21:47.428012: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 1: Y N Y Y
2018-08-06 10:21:47.428034: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 2: Y Y N Y
2018-08-06 10:21:47.428055: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 3: Y Y Y N
2018-08-06 10:21:47.431083: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 14857 MB memory) -> physical GPU (device: 0, name: Tesla V100-SXM2-16GB, pci bus id: 0004:04:00.0, compute capability: 7.0)
2018-08-06 10:21:47.987194: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:1 with 14857 MB memory) -> physical GPU (device: 1, name: Tesla V100-SXM2-16GB, pci bus id: 0004:05:00.0, compute capability: 7.0)
2018-08-06 10:21:48.813286: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:2 with 14856 MB memory) -> physical GPU (device: 2, name: Tesla V100-SXM2-16GB, pci bus id: 0035:03:00.0, compute capability: 7.0)
2018-08-06 10:21:49.397252: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:3 with 14861 MB memory) -> physical GPU (device: 3, name: Tesla V100-SXM2-16GB, pci bus id: 0035:04:00.0, compute capability: 7.0)
>>>
http://docs.h2o.ai/driverless-ai/latest-stable/docs/userguide/UsingDriverlessAI.pdf
먼저 DriverlessAI의 rpm package를 다음과 같이 download 받습니다.
[root@ING data]# wget https://s3.amazonaws.com/artifacts.h2o.ai/releases/ai/h2o/dai/rel-1.2.2-6/ppc64le-centos7/dai-1.2.2-1.ppc64le.rpm
rpm 명령으로 설치합니다.
[root@ING data]# rpm -Uvh dai-1.2.2-1.ppc64le.rpm
Preparing... ################################# [100%]
Updating / installing...
1:dai-1.2.2-1 ################################# [100%]
User configuration file /etc/dai/User.conf already exists.
Group configuration file /etc/dai/Group.conf already exists.
Configured user in /etc/dai/User.conf is 'dai'.
Configured group in /etc/dai/Group.conf is 'dai'.
Group 'dai' already exists.
User 'dai' already exists.
Adding systemd configuration files in /etc/systemd/system...
Created symlink from /etc/systemd/system/dai.service.wants/dai-dai.service to /usr/lib/systemd/system/dai-dai.service.
Created symlink from /etc/systemd/system/dai.service.wants/dai-h2o.service to /usr/lib/systemd/system/dai-h2o.service.
Created symlink from /etc/systemd/system/dai.service.wants/dai-procsy.service to /usr/lib/systemd/system/dai-procsy.service.
Calling 'systemctl enable dai'...
Created symlink from /etc/systemd/system/multi-user.target.wants/dai.service to /usr/lib/systemd/system/dai.service.
Installation complete.
DAI의 구동도 매우 간단합니다. 아래와 같이 dai.service만 start 해주면 main process와 보조 h2o process, proxy process인 dai-procsy까지 모두 자동으로 뜹니다.
[root@ING ~]# systemctl start dai
[root@ING ~]# systemctl status dai-dai
● dai-dai.service - Driverless AI (Main Application Process)
Loaded: loaded (/usr/lib/systemd/system/dai-dai.service; enabled; vendor preset: disabled)
[root@ING ~]# systemctl status dai-h2o
● dai-h2o.service - Driverless AI (H2O Process)
Loaded: loaded (/usr/lib/systemd/system/dai-h2o.service; enabled; vendor preset: disabled)
[root@ING ~]# systemctl status dai-procsy
● dai-procsy.service - Driverless AI (Procsy Process)
Loaded: loaded (/usr/lib/systemd/system/dai-procsy.service; enabled; vendor preset: disabled)
그리고 test1이라는 user를 만들고, 그 user를 DAI의 기본 user/group인 dai라는 group에 포함시킵니다.
[root@ING ~]# usermod -a -G dai test1
[root@ING ~]# cat /etc/group | grep dai
dai:x:980:test1
다음과 같이 t1.py와 t1.R을 준비합니다. 이것들은 python과 R에서 h2o4gpu를 사용할 수 있는지 확인하는 python 및 R script입니다.
[test1@ING ~]$ cat t1.py
import h2o4gpu
import numpy as np
X = np.array([[1.,1.], [1.,4.], [1.,0.]])
model = h2o4gpu.KMeans(n_clusters=2,random_state=1234).fit(X)
model.cluster_centers_
[test1@ING ~]$ cat t1.R
library(reticulate)
library(h2o4gpu)
use_python("/opt/h2oai/dai/python/bin/python")
x <- iris[1:4]
y <- as.integer(iris$Species)
model <- h2o4gpu.random_forest_classifier() %>% fit(x, y)
pred <- model %>% predict(x)
library(Metrics)
ce(actual = y, predicted = pred)
이제 test1에서 DAI에 포함된 h2o4gpu를 사용하는 방법입니다. 한줄 요약하면, PATH 등 환경변수를 설정하여 DAI에서 제공하는 python 및 PYTHONPATH를 사용하기만 하면 됩니다.
[test1@ING ~]$ export PATH=/opt/h2oai/dai/python/bin:$PATH
[test1@ING ~]$ export LD_LIBRARY_PATH=/opt/h2oai/dai/python/lib:/opt/h2oai/dai/lib:$LD_LIBRARY_PATH
[test1@ING ~]$ export PYTHONPATH=/opt/h2oai/dai/cuda-9.2/lib/python3.6/site-packages
[test1@ING ~]$ pip list | grep h2o
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
h2o (3.20.0.2)
h2o4gpu (0.2.0.9999+master.eb6295c)
h2oai (1.2.2)
h2oai-client (1.2.2)
h2oaicore (1.2.2)
DAI에서 제공하는 python은 3.6이며, 일반 anaconda에서 제공되는 것과 동일합니다. 제가 source로부터 build한 tensorflow 1.8도 pip로 정상적으로 설치해서 동일하게 사용할 수 있습니다.
[test1@ING ~]$ pip install /tmp/tensorflow-1.8.0-cp36-cp36m-linux_ppc64le.whl
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
tensorflow (1.8.0)
[test1@ING ~]$ which python
/opt/h2oai/dai/python/bin/python
이제 python에서 저 위의 t1.py를 수행하겠습니다. 여기서는 그냥 line by line으로 copy & paste 했습니다.
[test1@ING ~]$ python
Python 3.6.4 (default, Jun 30 2018, 13:42:46)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import h2o4gpu
>>> import numpy as np
>>> X = np.array([[1.,1.], [1.,4.], [1.,0.]])
>>> model = h2o4gpu.KMeans(n_clusters=2,random_state=1234).fit(X)
>>> model.cluster_centers_
array([[1. , 0.5],
[1. , 4. ]])
>>>
다음으로 R에서 저 위의 t1.R을 수행하겠습니다. 여기서는 그냥 line by line으로 copy & paste 했습니다.
[test1@ING ~]$ R
R version 3.4.1 (2017-06-30) -- "Single Candle"
> library(reticulate)
y <- as.integer(iris$Species)
model <- h2o4gpu.random_forest_classifier() %>% fit(x, y)
pred <- model %>% predict(x)
library(Metrics)
ce(actual = y, predicted = pred)> library(h2o4gpu)
Attaching package: ‘h2o4gpu’
The following object is masked from ‘package:base’:
transform
> use_python("/opt/h2oai/dai/python/bin/python")
> x <- iris[1:4]
> y <- as.integer(iris$Species)
> model <- h2o4gpu.random_forest_classifier() %>% fit(x, y)
> pred <- model %>% predict(x)
/opt/h2oai/dai/python/lib/python3.6/site-packages/sklearn/preprocessing/label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
if diff:
> library(Metrics)
> ce(actual = y, predicted = pred)
[1] 0.02666667
>
또한 tensorflow가 제대로 GPU를 물고 올라오는지 시험해보겠습니다. 물론 잘 됩니다.
[test1@ING ~]$ python
Python 3.6.4 (default, Jun 30 2018, 13:42:46)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
/opt/h2oai/dai/python/lib/python3.6/site-packages/h5py-2.7.1-py3.6-linux-ppc64le.egg/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
>>> sess=tf.Session()
2018-08-06 10:21:44.054091: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 0 with properties:
name: Tesla V100-SXM2-16GB major: 7 minor: 0 memoryClockRate(GHz): 1.53
pciBusID: 0004:04:00.0
totalMemory: 15.75GiB freeMemory: 15.34GiB
2018-08-06 10:21:44.568612: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 1 with properties:
name: Tesla V100-SXM2-16GB major: 7 minor: 0 memoryClockRate(GHz): 1.53
pciBusID: 0004:05:00.0
totalMemory: 15.75GiB freeMemory: 15.34GiB
2018-08-06 10:21:45.033482: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 2 with properties:
name: Tesla V100-SXM2-16GB major: 7 minor: 0 memoryClockRate(GHz): 1.53
pciBusID: 0035:03:00.0
totalMemory: 15.75GiB freeMemory: 15.34GiB
2018-08-06 10:21:45.461878: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 3 with properties:
name: Tesla V100-SXM2-16GB major: 7 minor: 0 memoryClockRate(GHz): 1.53
pciBusID: 0035:04:00.0
totalMemory: 15.75GiB freeMemory: 15.34GiB
2018-08-06 10:21:45.462104: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1435] Adding visible gpu devices: 0, 1, 2, 3
2018-08-06 10:21:47.427824: I tensorflow/core/common_runtime/gpu/gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-08-06 10:21:47.427960: I tensorflow/core/common_runtime/gpu/gpu_device.cc:929] 0 1 2 3
2018-08-06 10:21:47.427989: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 0: N Y Y Y
2018-08-06 10:21:47.428012: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 1: Y N Y Y
2018-08-06 10:21:47.428034: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 2: Y Y N Y
2018-08-06 10:21:47.428055: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 3: Y Y Y N
2018-08-06 10:21:47.431083: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 14857 MB memory) -> physical GPU (device: 0, name: Tesla V100-SXM2-16GB, pci bus id: 0004:04:00.0, compute capability: 7.0)
2018-08-06 10:21:47.987194: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:1 with 14857 MB memory) -> physical GPU (device: 1, name: Tesla V100-SXM2-16GB, pci bus id: 0004:05:00.0, compute capability: 7.0)
2018-08-06 10:21:48.813286: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:2 with 14856 MB memory) -> physical GPU (device: 2, name: Tesla V100-SXM2-16GB, pci bus id: 0035:03:00.0, compute capability: 7.0)
2018-08-06 10:21:49.397252: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:3 with 14861 MB memory) -> physical GPU (device: 3, name: Tesla V100-SXM2-16GB, pci bus id: 0035:04:00.0, compute capability: 7.0)
>>>
2018년 7월 26일 목요일
ppc64le 환경에서 pyarrow wheel 파일 build하기
h2o 및 h2o4gpu를 open source로부터 build하려면 xgboost4j_gpu.so가 필요합니다. 그런데 그걸 build하려면 또 pyarrow가 필요하지요. 하지만, ppc64le 아키텍처에서 pyarrow를 설치하려면 다음과 같이 error가 나는 것을 보셨을 것입니다.
$ pip install pyarrow
Collecting pyarrow
Using cached https://files.pythonhosted.org/packages/be/2d/11751c477e4e7f4bb07ac7584aafabe0d0608c170e4bff67246d695ebdbe/pyarrow-0.9.0.tar.gz
...
[ 66%] Building CXX object CMakeFiles/lib.dir/lib.cxx.o
/tmp/pip-install-kil31a/pyarrow/build/temp.linux-ppc64le-2.7/lib.cxx:592:35: fatal error: arrow/python/platform.h: No such file or directory
#include "arrow/python/platform.h"
^
compilation terminated.
make[2]: *** [CMakeFiles/lib.dir/lib.cxx.o] Error 1
make[1]: *** [CMakeFiles/lib.dir/all] Error 2
make: *** [all] Error 2
error: command 'make' failed with exit status 2
이 문제에 대해서 최근에 arrow community 도움을 받아 해결을 했습니다.
https://github.com/apache/arrow/issues/2281
좀더 간단하게는 다음과 같이 정리할 수 있습니다.
먼저, Redhat에서는 다음과 같이 사전 필요 fileset들을 설치합니다.
[dhkim@ING ~]$ sudo yum install jemalloc jemalloc-devel boost boost-devel flex flex-devel bison bison-devel
[dhkim@ING ~]$ mkdir imsi
[dhkim@ING ~]$ cd imsi
이 error를 해결하는 핵심은 먼저 arrow와 parquet-cpp를 source에서 build 하는 것입니다.
[dhkim@ING imsi]$ git clone https://github.com/apache/arrow.git
[dhkim@ING imsi]$ git clone https://github.com/apache/parquet-cpp.git
[dhkim@ING imsi]$ which python
~/anaconda2/bin/python
여기서는 anaconda2를 사용하는데, anaconda3도 동일하게 build할 수 있습니다. 먼저 conda 명령어로 다음과 같은 package들을 설치합니다.
[dhkim@ING imsi]$ conda install numpy six setuptools cython pandas pytest cmake flatbuffers rapidjson boost-cpp thrift snappy zlib gflags brotli lz4-c zstd -c conda-forge
여기서는 user home directory 밑에 dist라는 directory에 arrow와 parquet-cpp를 설치하겠습니다.
[dhkim@ING imsi]$ mkdir dist
[dhkim@ING imsi]$ export ARROW_BUILD_TYPE=release
[dhkim@ING imsi]$ export ARROW_HOME=$(pwd)/dist
[dhkim@ING imsi]$ export PARQUET_HOME=$(pwd)/dist
[dhkim@ING imsi]$ mkdir arrow/cpp/build && cd arrow/cpp/build
[dhkim@ING build]$ cmake3 -DCMAKE_BUILD_TYPE=$ARROW_BUILD_TYPE -DCMAKE_INSTALL_PREFIX=$ARROW_HOME -DARROW_PYTHON=on -DARROW_PLASMA=on -DARROW_BUILD_TESTS=OFF -DARROW_PARQUET=ON ..
[dhkim@ING build]$ make -j 8
[dhkim@ING build]$ make install
...
-- Installing: /home/dhkim/imsi/dist/include/arrow/python/platform.h
-- Installing: /home/dhkim/imsi/dist/include/arrow/python/pyarrow.h
-- Installing: /home/dhkim/imsi/dist/include/arrow/python/type_traits.h
-- Installing: /home/dhkim/imsi/dist/lib64/pkgconfig/arrow-python.pc
[dhkim@ING build]$ cd ~/imsi/arrow/python
[dhkim@ING python]$ MAKEFLAGS=-j8 ARROW_HOME=/home/dhkim/imsi/dist PARQUET_HOME=/home/dhkim/imsi/dist python setup.py build_ext --build-type=$ARROW_BUILD_TYPE --with-parquet --inplace
[dhkim@ING python]$ export LD_LIBRARY_PATH=/home/dhkim/imsi/dist/lib64:$LD_LIBRARY_PATH
이제 pyarrow를 build할 준비가 끝났습니다. 다만, arrow 쪽의 사소한 bug로 인해, 다음과 같이 끝에 점(.)이 달린 *.so. 라는 soft link들을 만들어주어야 합니다.
[dhkim@ING python]$ ln -s /home/dhkim/imsi/dist/lib64/libarrow_python.so.11.0.0 /home/dhkim/imsi/dist/lib64/libarrow_python.so.
[dhkim@ING python]$ ln -s /home/dhkim/imsi/dist/lib64/libarrow.so.11.0.0 /home/dhkim/imsi/dist/lib64/libarrow.so.
[dhkim@ING python]$ ln -s /home/dhkim/imsi/dist/lib64/libparquet.so.1.4.1 /home/dhkim/imsi/dist/lib64/libparquet.so.
이제 wheel file을 build 합니다.
[dhkim@ING python]$ python setup.py build_ext --build-type=release --with-parquet --bundle-arrow-cpp bdist_wheel
다음과 같이 dist directory 밑에 만들어집니다.
[dhkim@ING python]$ ls -l dist/pyarrow-0.10.1.dev687+g18a61f6-cp36-cp36m-linux_ppc64le.whl
-rw-rw-r-- 1 dhkim dhkim 7195829 Jul 26 16:03 dist/pyarrow-0.10.1.dev687+g18a61f6-cp36-cp36m-linux_ppc64le.whl
이걸 pip로 설치하고, import까지 잘 되는 것을 확인하실 수 있습니다.
[dhkim@ING python]$ pip install dist/pyarrow-0.10.1.dev687+g18a61f6-cp36-cp36m-linux_ppc64le.whl
[dhkim@ING python]$ pip list | grep pyarrow
pyarrow 0.10.1.dev687+g18a61f6
$ pip install pyarrow
Collecting pyarrow
Using cached https://files.pythonhosted.org/packages/be/2d/11751c477e4e7f4bb07ac7584aafabe0d0608c170e4bff67246d695ebdbe/pyarrow-0.9.0.tar.gz
...
[ 66%] Building CXX object CMakeFiles/lib.dir/lib.cxx.o
/tmp/pip-install-kil31a/pyarrow/build/temp.linux-ppc64le-2.7/lib.cxx:592:35: fatal error: arrow/python/platform.h: No such file or directory
#include "arrow/python/platform.h"
^
compilation terminated.
make[2]: *** [CMakeFiles/lib.dir/lib.cxx.o] Error 1
make[1]: *** [CMakeFiles/lib.dir/all] Error 2
make: *** [all] Error 2
error: command 'make' failed with exit status 2
이 문제에 대해서 최근에 arrow community 도움을 받아 해결을 했습니다.
https://github.com/apache/arrow/issues/2281
좀더 간단하게는 다음과 같이 정리할 수 있습니다.
먼저, Redhat에서는 다음과 같이 사전 필요 fileset들을 설치합니다.
[dhkim@ING ~]$ sudo yum install jemalloc jemalloc-devel boost boost-devel flex flex-devel bison bison-devel
[dhkim@ING ~]$ mkdir imsi
[dhkim@ING ~]$ cd imsi
이 error를 해결하는 핵심은 먼저 arrow와 parquet-cpp를 source에서 build 하는 것입니다.
[dhkim@ING imsi]$ git clone https://github.com/apache/arrow.git
[dhkim@ING imsi]$ git clone https://github.com/apache/parquet-cpp.git
[dhkim@ING imsi]$ which python
~/anaconda2/bin/python
여기서는 anaconda2를 사용하는데, anaconda3도 동일하게 build할 수 있습니다. 먼저 conda 명령어로 다음과 같은 package들을 설치합니다.
[dhkim@ING imsi]$ conda install numpy six setuptools cython pandas pytest cmake flatbuffers rapidjson boost-cpp thrift snappy zlib gflags brotli lz4-c zstd -c conda-forge
여기서는 user home directory 밑에 dist라는 directory에 arrow와 parquet-cpp를 설치하겠습니다.
[dhkim@ING imsi]$ mkdir dist
[dhkim@ING imsi]$ export ARROW_BUILD_TYPE=release
[dhkim@ING imsi]$ export ARROW_HOME=$(pwd)/dist
[dhkim@ING imsi]$ export PARQUET_HOME=$(pwd)/dist
[dhkim@ING imsi]$ mkdir arrow/cpp/build && cd arrow/cpp/build
[dhkim@ING build]$ cmake3 -DCMAKE_BUILD_TYPE=$ARROW_BUILD_TYPE -DCMAKE_INSTALL_PREFIX=$ARROW_HOME -DARROW_PYTHON=on -DARROW_PLASMA=on -DARROW_BUILD_TESTS=OFF -DARROW_PARQUET=ON ..
[dhkim@ING build]$ make -j 8
[dhkim@ING build]$ make install
...
-- Installing: /home/dhkim/imsi/dist/include/arrow/python/platform.h
-- Installing: /home/dhkim/imsi/dist/include/arrow/python/pyarrow.h
-- Installing: /home/dhkim/imsi/dist/include/arrow/python/type_traits.h
-- Installing: /home/dhkim/imsi/dist/lib64/pkgconfig/arrow-python.pc
[dhkim@ING build]$ cd ~/imsi/arrow/python
[dhkim@ING python]$ MAKEFLAGS=-j8 ARROW_HOME=/home/dhkim/imsi/dist PARQUET_HOME=/home/dhkim/imsi/dist python setup.py build_ext --build-type=$ARROW_BUILD_TYPE --with-parquet --inplace
[dhkim@ING python]$ export LD_LIBRARY_PATH=/home/dhkim/imsi/dist/lib64:$LD_LIBRARY_PATH
이제 pyarrow를 build할 준비가 끝났습니다. 다만, arrow 쪽의 사소한 bug로 인해, 다음과 같이 끝에 점(.)이 달린 *.so. 라는 soft link들을 만들어주어야 합니다.
[dhkim@ING python]$ ln -s /home/dhkim/imsi/dist/lib64/libarrow_python.so.11.0.0 /home/dhkim/imsi/dist/lib64/libarrow_python.so.
[dhkim@ING python]$ ln -s /home/dhkim/imsi/dist/lib64/libarrow.so.11.0.0 /home/dhkim/imsi/dist/lib64/libarrow.so.
[dhkim@ING python]$ ln -s /home/dhkim/imsi/dist/lib64/libparquet.so.1.4.1 /home/dhkim/imsi/dist/lib64/libparquet.so.
이제 wheel file을 build 합니다.
[dhkim@ING python]$ python setup.py build_ext --build-type=release --with-parquet --bundle-arrow-cpp bdist_wheel
다음과 같이 dist directory 밑에 만들어집니다.
[dhkim@ING python]$ ls -l dist/pyarrow-0.10.1.dev687+g18a61f6-cp36-cp36m-linux_ppc64le.whl
-rw-rw-r-- 1 dhkim dhkim 7195829 Jul 26 16:03 dist/pyarrow-0.10.1.dev687+g18a61f6-cp36-cp36m-linux_ppc64le.whl
이걸 pip로 설치하고, import까지 잘 되는 것을 확인하실 수 있습니다.
[dhkim@ING python]$ pip install dist/pyarrow-0.10.1.dev687+g18a61f6-cp36-cp36m-linux_ppc64le.whl
[dhkim@ING python]$ pip list | grep pyarrow
pyarrow 0.10.1.dev687+g18a61f6
[dhkim@ING python]$ python
Python 2.7.15 |Anaconda, Inc.| (default, May 1 2018, 23:32:32)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyarrow
>>>
이 과정 안 겪으셔도 되도록, 아래에 pyarrow의 python2.7용 whl과 python3.6용 whl을 google drive에 올려두겠습니다.
python3.6용 wheel
For some gentlemen who got errors like "ImportError: libarrow.so.10: cannot open shared object file: No such file or directory" from the wheel file I uploaded here...
What we need is just perseverance.
1. First, you need to install the pyarrow*.whl in my blog, and then...
2. Make soft links as needed. My wheel file places awkward names like "libarrow.so." due to a bug of https://github.com/apache/arrow/issues/2281 .
[u0017649@sys-96013 pyarrow]$ ln -s /home/u0017649/anaconda3/lib/python3.6/site-packages/pyarrow/libarrow.so. /home/u0017649/anaconda3/lib/python3.6/site-packages/pyarrow/libarrow.so.10
[u0017649@sys-96013 ~]$ ln -s /home/u0017649/anaconda3/lib/python3.6/site-packages/pyarrow/libarrow_python.so. /home/u0017649/anaconda3/lib/python3.6/site-packages/pyarrow/libarrow_python.so.10
[u0017649@sys-96013 ~]$ ln -s /home/u0017649/anaconda3/lib/python3.6/site-packages/pyarrow/libplasma.so. /home/u0017649/anaconda3/lib/python3.6/site-packages/pyarrow/libplasma.so.10
3. Still you might get some more errors. These will be addressed by installing OS packages.
ImportError: libboost_system-mt.so.1.53.0: cannot open shared object file: No such file or directory
ImportError: libboost_filesystem-mt.so.1.53.0: cannot open shared object file: No such file or directory
[u0017649@sys-96013 ~]$ sudo yum install boost-system
[u0017649@sys-96013 ~]$ sudo yum install boost-filesystem
[u0017649@sys-96013 ~]$ sudo yum install boost-regex
4. You might and might not get the following weird error. This can be addressed by upgrading numpy. Pls refer to
https://issues.apache.org/jira/browse/ARROW-3141 .
>>> import pyarrow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/u0017649/anaconda3/lib/python3.6/site-packages/pyarrow/__init__.py", line 50, in <module>
import pyarrow.compat as compat
AttributeError: module 'pyarrow' has no attribute 'compat'
[u0017649@sys-96013 ~]$ pip install numpy --upgrade
Collecting numpy
Downloading https://files.pythonhosted.org/packages/2d/80/1809de155bad674b494248bcfca0e49eb4c5d8bee58f26fe7a0dd45029e2/numpy-1.15.4.zip (4.5MB)
100% |████████████████████████████████| 4.5MB 271kB/s
Building wheels for collected packages: numpy
Running setup.py bdist_wheel for numpy ... done
Stored in directory: /home/u0017649/.cache/pip/wheels/13/6b/70/4b5d7861227307f91716c31698240e08c6ec5486d9ee82a97b
Successfully built numpy
Installing collected packages: numpy
Found existing installation: numpy 1.13.1
Uninstalling numpy-1.13.1:
Successfully uninstalled numpy-1.13.1
Successfully installed numpy-1.15.4
5. And finally, Voila !
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyarrow
>>>
For some gentlemen who got errors like "ImportError: libarrow.so.10: cannot open shared object file: No such file or directory" from the wheel file I uploaded here...
What we need is just perseverance.
1. First, you need to install the pyarrow*.whl in my blog, and then...
2. Make soft links as needed. My wheel file places awkward names like "libarrow.so." due to a bug of https://github.com/apache/arrow/issues/2281 .
[u0017649@sys-96013 pyarrow]$ ln -s /home/u0017649/anaconda3/lib/python3.6/site-packages/pyarrow/libarrow.so. /home/u0017649/anaconda3/lib/python3.6/site-packages/pyarrow/libarrow.so.10
[u0017649@sys-96013 ~]$ ln -s /home/u0017649/anaconda3/lib/python3.6/site-packages/pyarrow/libarrow_python.so. /home/u0017649/anaconda3/lib/python3.6/site-packages/pyarrow/libarrow_python.so.10
[u0017649@sys-96013 ~]$ ln -s /home/u0017649/anaconda3/lib/python3.6/site-packages/pyarrow/libplasma.so. /home/u0017649/anaconda3/lib/python3.6/site-packages/pyarrow/libplasma.so.10
3. Still you might get some more errors. These will be addressed by installing OS packages.
ImportError: libboost_system-mt.so.1.53.0: cannot open shared object file: No such file or directory
ImportError: libboost_filesystem-mt.so.1.53.0: cannot open shared object file: No such file or directory
[u0017649@sys-96013 ~]$ sudo yum install boost-system
[u0017649@sys-96013 ~]$ sudo yum install boost-filesystem
[u0017649@sys-96013 ~]$ sudo yum install boost-regex
4. You might and might not get the following weird error. This can be addressed by upgrading numpy. Pls refer to
https://issues.apache.org/jira/browse/ARROW-3141 .
>>> import pyarrow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/u0017649/anaconda3/lib/python3.6/site-packages/pyarrow/__init__.py", line 50, in <module>
import pyarrow.compat as compat
AttributeError: module 'pyarrow' has no attribute 'compat'
[u0017649@sys-96013 ~]$ pip install numpy --upgrade
Collecting numpy
Downloading https://files.pythonhosted.org/packages/2d/80/1809de155bad674b494248bcfca0e49eb4c5d8bee58f26fe7a0dd45029e2/numpy-1.15.4.zip (4.5MB)
100% |████████████████████████████████| 4.5MB 271kB/s
Building wheels for collected packages: numpy
Running setup.py bdist_wheel for numpy ... done
Stored in directory: /home/u0017649/.cache/pip/wheels/13/6b/70/4b5d7861227307f91716c31698240e08c6ec5486d9ee82a97b
Successfully built numpy
Installing collected packages: numpy
Found existing installation: numpy 1.13.1
Uninstalling numpy-1.13.1:
Successfully uninstalled numpy-1.13.1
Successfully installed numpy-1.15.4
5. And finally, Voila !
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyarrow
>>>
2017년 3월 27일 월요일
IBM Minsky에서의 H2O Deep Learning 설치
H2O는 확장성이 좋고 Spark, Hadoop, R 등 big data platform과 연동하여 사용하기 좋은 machine learning platform입니다. 물론 open source입니다. H2O도 ppc64le 아키텍처, 즉 IBM Minsky (S822LC for HPC) 서버에서 사용 가능합니다. 여기서는 H2O를 R과 함께 Minsky 서버에 설치하는 방법을 정리했으며, 원본은 아래 link에 있는 내용을 참조했습니다.
http://h2o-release.s3.amazonaws.com/h2o/rel-tibshirani/8/index.html#R
먼저, 아래 주소에서 H2O를 Minsky 서버로 download 합니다.
test@minsky:~/R$ wget http://h2o-release.s3.amazonaws.com/h2o/rel-tibshirani/8/h2o-3.6.0.8.zip
test@minsky:~/R$ unzip h2o-3.10.4.2.zip
test@minsky:~/R$ cd h2o-3.10.4.2
test@minsky:~/R/h2o-3.10.4.2$ java -jar h2o.jar
03-27 17:04:32.866 172.18.229.117:54321 49868 main INFO: ----- H2O started -----
03-27 17:04:32.890 172.18.229.117:54321 49868 main INFO: Build git branch: rel-ueno
...
03-27 17:04:34.787 172.18.229.117:54321 49868 main INFO: Open H2O Flow in your web browser: http://172.18.229.117:54321
03-27 17:04:34.787 172.18.229.117:54321 49868 main INFO:
이렇게 H2O 서버를 구동한 뒤에, 아래와 같이 web browser에서 54321 port로 접속이 가능합니다.
R은 Ubuntu 16.04에 포함된 r-base-core package에서 나온 3.2.3을 써도 되고, 앞선 포스팅에서 설명한 대로 MS open R server 3.3.2를 직접 build해서 써도 됩니다.
test@minsky:~/R/h2o-3.10.4.2$ which R
/usr/local/lib/R/bin/R
먼저, R을 구동하여 R에 h2o 패키지가 설치되어 있는지 확인하여 만약 기존 것이 있으면 제거합니다.
test@minsky:~/R/h2o-3.10.4.2$ sudo R
> if ("package:h2o" %in% search()) { detach("package:h2o", unload=TRUE) }
> if ("h2o" %in% rownames(installed.packages())) { remove.packages("h2o") }
이어서 methods, statmod, stats, RCurl 등의 R 패키지를 설치합니다.
> if (! ("methods" %in% rownames(installed.packages()))) { install.packages("methods") }
> if (! ("statmod" %in% rownames(installed.packages()))) { install.packages("statmod") }
> if (! ("stats" %in% rownames(installed.packages()))) { install.packages("stats") }
> if (! ("graphics" %in% rownames(installed.packages()))) { install.packages("graphics") }
> if (! ("RCurl" %in% rownames(installed.packages()))) { install.packages("RCurl") }
> if (! ("jsonlite" %in% rownames(installed.packages()))) { install.packages("jsonlite") }
> if (! ("tools" %in% rownames(installed.packages()))) { install.packages("tools") }
> if (! ("utils" %in% rownames(installed.packages()))) { install.packages("utils") }
이 과정에서 필요시 다음과 같이 internet에서 이 package들을 download 받아옵니다.
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
HTTPS CRAN mirror
...
49: USA (CA 1) [https] 50: USA (IA) [https]
51: USA (IN) [https] 52: USA (KS) [https]
53: USA (MI 1) [https] 54: USA (OR) [https]
55: USA (TN) [https] 56: USA (TX 1) [https]
57: USA (TX 2) [https] 58: (HTTP mirrors)
Selection: 49
trying URL 'https://cran.cnr.berkeley.edu/src/contrib/statmod_1.4.29.tar.gz'
Content type 'application/x-gzip' length 56932 bytes (55 KB)
==================================================
downloaded 55 KB
이 과정이 성공적으로 완료되면 이제 H2O 패키지를 설치합니다. 다만, 저 원본 URL에 나온 것과 같은 아래 tibshirani 버전은 H2O 버전과 맞지 않아 아래와 같은 error를 냅니다.
> install.packages("h2o", type="source", repos=(c("http://h2o-release.s3.amazonaws.com/h2o/rel-tibshirani/8/R")))
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
trying URL 'http://h2o-release.s3.amazonaws.com/h2o/rel-tibshirani/8/R/src/contrib/h2o_3.6.0.8.tar.gz'
Content type 'application/x-tar; charset=binary' length 46482663 bytes (44.3 MB)
==================================================
downloaded 44.3 MB
...
> localH2O = h2o.init(nthreads=-1)
...
Error in h2o.init(nthreads = -1) :
Version mismatch! H2O is running version 3.10.4.2 but R package is version 3.6.0.8
따라서 아래와 같이 tverberg 버전을 설치해야 합니다.
> install.packages("h2o", type="source", repos=(c("http://h2o-release.s3.amazonaws.com/h2o/rel-tverberg/6/R")))
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
trying URL 'http://h2o-release.s3.amazonaws.com/h2o/rel-tverberg/6/R/src/contrib/h2o_3.10.3.6.tar.gz'
Content type 'application/x-tar' length 59595766 bytes (56.8 MB)
==================================================
downloaded 56.8 MB
...
설치가 완료되면 h2o를 load하고 h2o.init을 수행합니다.
> library(h2o)
----------------------------------------------------------------------
Your next step is to start H2O:
> h2o.init()
For H2O package documentation, ask for help:
> ??h2o
After starting H2O, you can use the Web UI at http://localhost:54321
For more information visit http://docs.h2o.ai
----------------------------------------------------------------------
Attaching package: ‘h2o’
....
> localH2O = h2o.init(nthreads=-1)
...
Starting H2O JVM and connecting: ... Connection successful!
R is connected to the H2O cluster:
H2O cluster uptime: 3 seconds 392 milliseconds
H2O cluster version: 3.10.3.6
H2O cluster version age: 1 month and 6 days
H2O cluster name: H2O_started_from_R_root_uwo022
H2O cluster total nodes: 1
H2O cluster total memory: 0.89 GB
H2O cluster total cores: 128
H2O cluster allowed cores: 128
H2O cluster healthy: TRUE
H2O Connection ip: localhost
H2O Connection port: 54321
H2O Connection proxy: NA
R Version: R version 3.2.3 (2015-12-10)
이어서 demo로 kmeans를 수행해봅니다. 사전에 tightvncserver 등을 구동시켜 plot이 되도록 해놓습니다.
> demo(h2o.kmeans)
demo(h2o.kmeans)
---- ~~~~~~~~~~
Type <Return> to start :
...
> prostate.hex = h2o.uploadFile(path = system.file("extdata", "prostate.csv", package="h2o"), destination_frame = "prostate")
|======================================================================| 100%
> summary(prostate.hex)
ID CAPSULE AGE RACE
Min. : 1.00 Min. :0.0000 Min. :43.00 Min. :0.000
1st Qu.: 95.75 1st Qu.:0.0000 1st Qu.:62.00 1st Qu.:1.000
Median :190.50 Median :0.0000 Median :67.00 Median :1.000
Mean :190.50 Mean :0.4026 Mean :66.04 Mean :1.087
3rd Qu.:285.25 3rd Qu.:1.0000 3rd Qu.:71.00 3rd Qu.:1.000
Max. :380.00 Max. :1.0000 Max. :79.00 Max. :2.000
DPROS DCAPS PSA VOL
Min. :1.000 Min. :1.000 Min. : 0.300 Min. : 0.00
1st Qu.:1.000 1st Qu.:1.000 1st Qu.: 4.900 1st Qu.: 0.00
Median :2.000 Median :1.000 Median : 8.664 Median :14.20
Mean :2.271 Mean :1.108 Mean : 15.409 Mean :15.81
3rd Qu.:3.000 3rd Qu.:1.000 3rd Qu.: 17.063 3rd Qu.:26.40
Max. :4.000 Max. :2.000 Max. :139.700 Max. :97.60
GLEASON
Min. :0.000
1st Qu.:6.000
Median :6.000
Mean :6.384
3rd Qu.:7.000
Max. :9.000
....
Total Within SS: 537.6507
Between SS: 1357.349
Total SS: 1895
Centroid Statistics:
centroid size within_cluster_sum_of_squares
1 1 156.00000 165.18206
2 2 6.00000 10.15081
3 3 2.00000 5.89369
4 4 1.00000 0.00000
5 5 60.00000 114.01143
6 6 2.00000 0.04695
7 7 11.00000 18.54178
8 8 30.00000 82.95187
9 9 23.00000 35.24021
10 10 89.00000 105.63191
> plot(prostate.ctrs[,1:2])
Hit <Return> to see next plot:
> plot(prostate.ctrs[,3:4])
> title("K-Means Centers for k = 10", outer = TRUE, line = -2.0)
Warning message:
In summary.H2OFrame(prostate.hex) :
Approximated quantiles computed! If you are interested in exact quantiles, please pass the `exact_quantiles=TRUE` parameter.
결과로서 아래와 같은 그래프가 그려지는 것을 보실 수 있습니다.
피드 구독하기:
글 (Atom)





