XGBoost支持GPU + Python3

时间:2018-01-16 14:37:22

标签: python xgboost

我正在尝试在Ubuntu 16.04上安装支持GPU的XGBoost& Python 3.5.2。我尝试按照XGBoost documentation执行以下步骤:

构建Ubuntu发行版

git clone --recursive https://github.com/dmlc/xgboost
cd xgboost; make -j4

启用GPU支持

cd build
cmake .. -DUSE_CUDA=ON
make -j

安装Python包

cd python-package; sudo python3 setup.py install

在我尝试构建Python包的步骤之前,一切似乎都有效,我得到的错误似乎是python 2兼容性问题。具体做法是:

...
creating build/bdist.linux-x86_64/egg/xgboost/src/data
copying build/lib/xgboost/src/data/sparse_batch_page.h -> build/bdist.linux-x86_64/egg/xgboost/src/data
copying build/lib/xgboost/src/data/simple_dmatrix.h -> build/bdist.linux-x86_64/egg/xgboost/src/data
copying build/lib/xgboost/src/data/simple_dmatrix.cc -> build/bdist.linux-x86_64/egg/xgboost/src/data
copying build/lib/xgboost/src/data/sparse_page_source.h -> build/bdist.linux-x86_64/egg/xgboost/src/data
copying build/lib/xgboost/src/data/sparse_page_dmatrix.h -> build/bdist.linux-x86_64/egg/xgboost/src/data
copying build/lib/xgboost/src/data/simple_csr_source.cc -> build/bdist.linux-x86_64/egg/xgboost/src/data
copying build/lib/xgboost/src/data/simple_csr_source.h -> build/bdist.linux-x86_64/egg/xgboost/src/data
copying build/lib/xgboost/src/data/sparse_page_source.cc -> build/bdist.linux-x86_64/egg/xgboost/src/data
copying build/lib/xgboost/src/data/sparse_page_dmatrix.cc -> build/bdist.linux-x86_64/egg/xgboost/src/data
copying build/lib/xgboost/src/data/sparse_page_writer.cc -> build/bdist.linux-x86_64/egg/xgboost/src/data
copying build/lib/xgboost/src/data/sparse_page_raw_format.cc -> build/bdist.linux-x86_64/egg/xgboost/src/data
copying build/lib/xgboost/src/data/data.cc -> build/bdist.linux-x86_64/egg/xgboost/src/data
copying build/lib/xgboost/src/cli_main.cc -> build/bdist.linux-x86_64/egg/xgboost/src
copying build/lib/xgboost/callback.py -> build/bdist.linux-x86_64/egg/xgboost
byte-compiling build/bdist.linux-x86_64/egg/xgboost/plotting.py to plotting.cpython-35.pyc
byte-compiling build/bdist.linux-x86_64/egg/xgboost/rabit/guide/broadcast.py to broadcast.cpython-35.pyc
  File "build/bdist.linux-x86_64/egg/xgboost/rabit/guide/broadcast.py", line 18
    print '@node[%d] before-broadcast: s=\"%s\"' % (rank, str(s))
                                               ^
SyntaxError: invalid syntax

byte-compiling build/bdist.linux-x86_64/egg/xgboost/rabit/guide/basic.py to basic.cpython-35.pyc
  File "build/bdist.linux-x86_64/egg/xgboost/rabit/guide/basic.py", line 20
    print '@node[%d] before-allreduce: a=%s' % (rank, str(a))
                                           ^
SyntaxError: invalid syntax

byte-compiling build/bdist.linux-x86_64/egg/xgboost/rabit/guide/lazy_allreduce.py to lazy_allreduce.cpython-35.pyc
byte-compiling build/bdist.linux-x86_64/egg/xgboost/rabit/test/local_recover.py to local_recover.cpython-35.pyc
  File "build/bdist.linux-x86_64/egg/xgboost/rabit/test/local_recover.py", line 16
    print '[%d] restart from version %d' % (rank, version)
                                       ^
SyntaxError: invalid syntax

...

creating build/bdist.linux-x86_64/egg/EGG-INFO
copying xgboost.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying xgboost.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying xgboost.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying xgboost.egg-info/not-zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
copying xgboost.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying xgboost.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
creating 'dist/xgboost-0.7-py3.5.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing xgboost-0.7-py3.5.egg
removing '/usr/local/lib/python3.5/dist-packages/xgboost-0.7-py3.5.egg' (and everything under it)
creating /usr/local/lib/python3.5/dist-packages/xgboost-0.7-py3.5.egg
Extracting xgboost-0.7-py3.5.egg to /usr/local/lib/python3.5/dist-packages
  File "/usr/local/lib/python3.5/dist-packages/xgboost-0.7-py3.5.egg/xgboost/rabit/guide/basic.py", line 20
    print '@node[%d] before-allreduce: a=%s' % (rank, str(a))
                                           ^
SyntaxError: invalid syntax

  File "/usr/local/lib/python3.5/dist-packages/xgboost-0.7-py3.5.egg/xgboost/rabit/guide/broadcast.py", line 18
    print '@node[%d] before-broadcast: s=\"%s\"' % (rank, str(s))
                                               ^
SyntaxError: invalid syntax

  File "/usr/local/lib/python3.5/dist-packages/xgboost-0.7-py3.5.egg/xgboost/rabit/test/local_recover.py", line 16
    print '[%d] restart from version %d' % (rank, version)
                                       ^
SyntaxError: invalid syntax

当我尝试运行XGBoost速度基准测试时,如here所述,我收到以下错误 - 我认为这与上述错误有关。

[14:03:24] include/dmlc/logging.h:235: [14:03:24] src/io/local_filesys.cc:61: LocalFileSystem.GetPathInfo dtest.dm Error:No such file or directory
Generating dataset: 1000000 rows * 50 columns
0.25/0.75 test/train split
Generate Time: 49.93979454040527 seconds
DMatrix Start
Exception ignored in: <bound method DMatrix.__del__ of <xgboost.core.DMatrix object at 0x7f5448daa390>>
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/xgboost/core.py", line 324, in __del__
    _check_call(_LIB.XGDMatrixFree(self.handle))
AttributeError: 'DMatrix' object has no attribute 'handle'
Traceback (most recent call last):
  File "tests/benchmark/benchmark.py", line 16, in run_benchmark
    dtest = xgb.DMatrix('dtest.dm')
  File "/usr/local/lib/python3.5/dist-packages/xgboost/core.py", line 262, in __init__
    ctypes.byref(self.handle)))
  File "/usr/local/lib/python3.5/dist-packages/xgboost/core.py", line 127, in _check_call
    raise XGBoostError(_LIB.XGBGetLastError())
xgboost.core.XGBoostError: b'[14:03:24] src/io/local_filesys.cc:61: LocalFileSystem.GetPathInfo dtest.dm Error:No such file or directory'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tests/benchmark/benchmark.py", line 65, in <module>
    run_benchmark(args)
  File "tests/benchmark/benchmark.py", line 39, in run_benchmark
    dtest = xgb.DMatrix(X_test, y_test, nthread=-1)
TypeError: __init__() got an unexpected keyword argument 'nthread'

之前有没有遇到过这个?或者人们可以看到上面的安装方法有问题吗?

1 个答案:

答案 0 :(得分:0)

  
    

打印'[%d]从版本%d'%(排名,版本)

重新启动   

这绝对是python 2的语法,你应该使用python 2或者尝试为python 3找到xgboost包