2018년 7월 26일 목요일

ppc64le에서 xgboost4j build하기

먼저 http://hwengineer.blogspot.com/2018/07/ppc64le-pyarrow-wheel-build.html 의 안내에 따라 pyarrow를 설치해야 합니다.  그 다음에 xgboost의 source를 받습니다. 

[root@ING data]# git clone -b h2oai  https://github.com/h2oai/xgboost.git
Cloning into 'xgboost'...
remote: Counting objects: 25961, done.
remote: Compressing objects: 100% (86/86), done.
remote: Total 25961 (delta 83), reused 78 (delta 45), pack-reused 25828
Receiving objects: 100% (25961/25961), 9.44 MiB | 4.67 MiB/s, done.
Resolving deltas: 100% (15316/15316), done.

[root@ING data]# cd xgboost

[root@ING xgboost]# git submodule init
Submodule 'cub' (https://github.com/NVlabs/cub) registered for path 'cub'
Submodule 'dmlc-core' (https://github.com/dmlc/dmlc-core) registered for path 'dmlc-core'
Submodule 'rabit' (https://github.com/dmlc/rabit) registered for path 'rabit'

[root@ING xgboost]# git submodule update --recursive
Cloning into 'cub'...
remote: Counting objects: 32642, done.
remote: Total 32642 (delta 0), reused 0 (delta 0), pack-reused 32642
Receiving objects: 100% (32642/32642), 16.46 MiB | 6.82 MiB/s, done.
Resolving deltas: 100% (28620/28620), done.
Submodule path 'cub': checked out 'b20808b1b04ec3d6a625e51fbc1eb76f337754ad'
Cloning into 'dmlc-core'...
remote: Counting objects: 4975, done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 4975 (delta 7), reused 9 (delta 2), pack-reused 4952
Receiving objects: 100% (4975/4975), 1.22 MiB | 1.44 MiB/s, done.
Resolving deltas: 100% (2976/2976), done.
Submodule path 'dmlc-core': checked out '459ab734d15acd68fd437abf845c7c1730b5a38f'
Cloning into 'rabit'...
remote: Counting objects: 3174, done.
remote: Total 3174 (delta 0), reused 0 (delta 0), pack-reused 3173
Receiving objects: 100% (3174/3174), 905.56 KiB | 378.00 KiB/s, done.
Resolving deltas: 100% (2058/2058), done.
Submodule path 'rabit': checked out '87143deb4c0a34302f727ba35497e3380b2cced8'

처음에 해줄 것은 build.sh 수행, 그 다음에 make -f Makefile2 libxgboost 입니다.  여기까지 해주면 xgboost의 wheel 파일이 build 됩니다.  그 다음에 jvm-packages에 들어가서 create_jni.py를 수행하여 libxgboost4j.so를 만들어 줍니다.

[root@ING xgboost]# ./build.sh
...
build/linear/updater_coordinate.o dmlc-core/libdmlc.a rabit/lib/librabit.a  -pthread -lm  -fopenmp -lrt  -lrt
Successfully build multi-thread xgboost


[root@ING xgboost]# make -f Makefile2 libxgboost
...
copying build/lib/xgboost/build-python.sh -> build/bdist.linux-ppc64le/wheel/xgboost
copying build/lib/xgboost/libxgboost.so -> build/bdist.linux-ppc64le/wheel/xgboost
running install_egg_info
Copying xgboost.egg-info to build/bdist.linux-ppc64le/wheel/xgboost-0.72-py3.6.egg-info
running install_scripts
creating build/bdist.linux-ppc64le/wheel/xgboost-0.72.dist-info/WHEEL

[root@ING xgboost]# ls -l ./python-package/dist/xgboost-0.72-py3-none-any.whl
-rw-r--r-- 1 root root 77640590 Jul 23 14:52 ./python-package/dist/xgboost-0.72-py3-none-any.whl

[root@ING xgboost]# pip install ./python-package/dist/xgboost-0.72-py3-none-any.whl

[root@ING xgboost]# cd jvm-packages

[root@ING jvm-packages]# python create_jni.py
...
[100%] Linking CXX shared library ../lib/libxgboost4j.so
[100%] Built target xgboost4j
cd demo/regression
/root/anaconda3/bin/python mapfeat.py
/root/anaconda3/bin/python mknfold.py machine.txt 1
copying native library
mkdir -p xgboost4j/src/main/resources/lib
cp ../lib/libxgboost4j.so xgboost4j/src/main/resources/lib
copying pure-Python tracker
cp ../dmlc-core/tracker/dmlc_tracker/tracker.py xgboost4j/src/main/resources
copying train/test files
mkdir -p xgboost4j-spark/src/test/resources
cd ../demo/regression
/root/anaconda3/bin/python mapfeat.py
/root/anaconda3/bin/python mknfold.py machine.txt 1
cp ../demo/regression/machine.txt.train xgboost4j-spark/src/test/resources
cp ../demo/regression/machine.txt.test xgboost4j-spark/src/test/resources
cp ../demo/data/agaricus.txt.test xgboost4j-spark/src/test/resources
cp ../demo/data/agaricus.txt.train xgboost4j-spark/src/test/resources

[root@ING jvm-packages]# ls -l ./xgboost4j/src/main/resources/lib/libxgboost4j.so
-rwxr-xr-x 1 root root 158562656 Jul 23 15:49 ./xgboost4j/src/main/resources/lib/libxgboost4j.so

[root@ING jvm-packages]# file ./xgboost4j/src/main/resources/lib/libxgboost4j.so
./xgboost4j/src/main/resources/lib/libxgboost4j.so: ELF 64-bit LSB shared object, 64-bit PowerPC or cisco 7500, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=510aede1975d463804199edd1b74457b8e48c4f8, not stripped

위에서 생성된 libxgboost4j.so을 h2o.jar에 lib/linux64/libxgboost4j_gpu.so라는 이름으로 update해주면 됩니다.

$ mkdir -p lib/linux64

$ cp ./xgboost4j/src/main/resources/lib/libxgboost4j.so lib/linux64/libxgboost4j.so

$ jar uf h2o.jar lib/linux64/libxgboost4j.so

------------------------------

아래는 위의 build하는 과정에서 만났던 몇가지 error 및 그 회피 방법입니다.

[root@ING xgboost]# make -f Makefile2 libxgboost
...
Collecting jmespath<1.0.0,>=0.7.1 (from botocore==1.10.62->awscli>=1.11.148->-r requirements_runtime.txt (line 74))
  Using cached https://files.pythonhosted.org/packages/b7/31/05c8d001f7f87f0f07289a5fc0fc3832e9a57f2dbd4d3b0fee70e0d51365/jmespath-0.9.3-py2.py3-none-any.whl
recommonmark 0.4.0 has requirement commonmark<=0.5.4, but you'll have commonmark 0.7.5 which is incompatible.
Installing collected packages: html5lib, bleach, execnet, qtconsole, tabulate, testpath, pyasn1, rsa, jmespath, botocore, s3transfer, awscli, feather-format, graphviz
  Found existing installation: html5lib 0.9999999
Cannot uninstall 'html5lib'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
make: *** [libxgboostp2nccl] Error 1


[root@ING xgboost]# rm -rf /root/anaconda3/lib/python3.6/site-packages/html5lib*

[root@ING xgboost]# make -f Makefile2 libxgboost
...
Installing collected packages: testpath, jmespath, botocore, pyasn1, rsa, s3transfer, awscli, feather-format, graphviz
Successfully installed awscli-1.15.63 botocore-1.10.62 feather-format-0.4.0 graphviz-0.8.4 jmespath-0.9.3 pyasn1-0.4.3 rsa-3.4.2 s3transfer-0.1.13 testpath-0.3.1
pip install -r requirements_build.txt
Could not open requirements file: [Errno 2] No such file or directory: 'requirements_build.txt'
make: *** [libxgboostp2nccl] Error 1

[root@ING xgboost]# find . -name "requirement*.txt"
./doc/requirements.txt
./requirements_buildonly.txt
./requirements_runtime.txt


[root@ING xgboost]# cp ./requirements_buildonly.txt ./requirements_build.txt

[root@ING xgboost]# make -f Makefile2 libxgboost
...
Collecting cmake>=0.8.0 (from -r requirements_build.txt (line 9))
  Cache entry deserialization failed, entry ignored
  Downloading https://files.pythonhosted.org/packages/79/06/e89052a7e65ab765bc5e279542853d043ec857e61f253973c05a80f2490f/cmake-3.11.4.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-cu87aoqb/cmake/setup.py", line 7, in <module>
        from skbuild import setup
    ModuleNotFoundError: No module named 'skbuild'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-cu87aoqb/cmake/
make: *** [libxgboostp2nccl] Error 1


[root@ING xgboost]# vi requirements_build.txt
#cmake>=0.8.0



댓글 없음:

댓글 쓰기