win10专业版+Python3.7的CatBoost的GPU安装&支持 -多处采坑小结 -提速40%+

开篇小结

本文在安装时,已经安装好lightgbm的gpu环境支持了。
具体可参考:

最终按照官方教程来走,只完成了99.9%,最后0.1%因未知原因并未生效,显示了failure;不过到这里,gpu*catboost已经可以简单支持了。

catboost的官方教程地址

https://catboost.ai/docs/installation/python-installation-method-build-from-source-windows.html#python-installation-method-build-from-source-windows

(我初步按照上述教程并没有成功执行,又加上后续大量阅读安装源码+搜索采坑,完成了99.9%)

后知后觉

cudnn我准备装个7.6.5的版本,结果装了个8.0.5,想着向上一般都支持兼容的(粗心大意了);

cuda是10.1版本,lgb倒是兼容了,cat不行, 后面就有了下面这篇cat文章。

再后面装tensorflow-gpu,各种阴间报错,欲哭无泪。(╥╯^╰╥) (╥╯^╰╥) (╥╯^╰╥) (╥╯^╰╥) (╥╯^╰╥) (╥╯^╰╥)

所以 ,先确保你的tensorflow-gpu版本可以安装成功,再进行后续安装;(具体适配的各种环境tensorflow官网写的都有,地址: https://tensorflow.google.cn/install/source_windows#gpu)

后来经过一阵子折腾,我的tensorflow-gpu的环境配置:win10+3070显卡+vs2019+cudnn7.6.5+cuda-10.1+python-3.6+tensorflow-gpu-2.1.0。

此环境配置是从vs2017升级到vs2019、cudnn8降到cudnn7.6.5,无缝衔接支持了之前编译好的lgb-gpu模式+cat-gpu模式。

新起一个独立的env, 装tensorflow的一行代码小结:

conda install tensorflow-gpu

以下为部分采坑小结 (此时环境为vs2017+cuda-10.1+cudnn-8.0.5)


1. 检查配置

  • NVIDIA Driver of version 418.xx or higher. 支持

2. Clone the repository:

gitee加速版: https://gitee.com/renlle/catboost

3. Install Visual Studio Community 2017

已安装

4. cuda版本

具体已支持

5. Open

open the catboost/catboost/python-package/catboost directory from the local copy of the CatBoost repository.

建议使用powershell,必须使用管理员模式启动。

6. 编译

Compile the packages using one of the following methods:

最终我的成功命令为: (走的是教程里的第二种说明,具体属性改为自己的配置, /I不要省略, 统一用/而不是反斜杠)

PS E:\github\catboost\catboost\python-package\catboost>  ../../../ya make -r -DUSE_ARCADIA_PYTHON=no -DOS_SDK=local -DPYTHON_INCLUDE="/I D:/Anaconda3/include/" -DPYTHON_LIBRARIES="D:/Anaconda3/libs/python37.lib" -DCUDA_ROOT="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/" -o="E:/github/catboost/catboost/python-package/catboost/" -k

以下为有记录的报错分析和简单处理:

'..' 不是内部或外部命令...

'..' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

处理:
改为powershell,管理员。

ConfigureError: Could not determine custom compiler version: cl.exe

新问题:
Config was not generated due to errors in E:\github\catboost\build\ymake_conf.py
Traceback (most recent call last):
  File "E:\github\catboost\build\ymake_conf.py", line 3054, in <module>
    main()
  File "E:\github\catboost\build\ymake_conf.py", line 3047, in main
    build = Build(arcadia, options.build_type, options.toolchain_params, force_ignore_local_files=not options.local_distbuild)
  File "E:\github\catboost\build\ymake_conf.py", line 443, in __init__
    self.tc = self._get_toolchain_options()
  File "E:\github\catboost\build\ymake_conf.py", line 565, in _get_toolchain_options
    detector.detect(self.params['params'].get('c_compiler'), self.params['params'].get('cxx_compiler'))
  File "E:\github\catboost\build\ymake_conf.py", line 863, in detect
    raise ConfigureError('Could not determine custom compiler version: {}'.format(c_compiler))
ConfigureError: Could not determine custom compiler version: cl.exe

翻E:\github\catboost\build\ymake_conf.py:

"""
  def detect(self, c_compiler=None, cxx_compiler=None):
        c_compiler = c_compiler or os.environ.get('CC')
        cxx_compiler = cxx_compiler or os.environ.get('CXX') or c_compiler
        c_compiler = c_compiler or cxx_compiler

        logger.debug('e=%s', os.environ)
        if c_compiler is None:
            raise ConfigureError('Custom compiler was requested but not specified')

        c_compiler_path = which(c_compiler)

        clang_vars = ['__clang_major__', '__clang_minor__', '__clang_patchlevel__']
        gcc_vars = ['__GNUC__', '__GNUC_MINOR__', '__GNUC_PATCHLEVEL__']
        msvc_vars = ['_MSC_VER']
        apple_var = '__apple_build_version__'

        compiler_vars = self.get_compiler_vars(c_compiler_path, clang_vars + [apple_var] + gcc_vars + msvc_vars)

        if not compiler_vars:
            raise ConfigureError('Could not determine custom compiler version: {}'.format(c_compiler))

"""

处理:

看最后一行,没有cl.exe文件,无法执行cl文件;
按照https://zhuanlan.zhihu.com/p/98384105, 中的教程在命令行中使用 cl.exe 编译器.

重启powershell,并管理员启动,尽到catboost的源码目录下。

验证: 使用cl来构建一个c文件.

解决 ConfigureError: No %WindowsSdkDir%, %WindowsSDKVersion%

解决 ConfigureError: No %WindowsSdkDir%, %WindowsSDKVersion% or %VCINSTALLDIR% present. Please, run vcvars64.bat to setup preferred environment.

方案:

百度找到vcvars64.bat的路径,执行后没有效果。

%WindowsSdkDir%, %WindowsSDKVersion% or %VCINSTALLDIR%是windows的cmd下的变量输出,对等于环境变量的配置;

这三个都是windows的sdk的配置:

AttributeError: 'NoneType' object has no attribute 'replace'

Config was not generated due to errors in E:\github\catboost\build\ymake_conf.py
Traceback (most recent call last):
  File "E:\github\catboost\build\ymake_conf.py", line 3054, in <module>
    main()
  File "E:\github\catboost\build\ymake_conf.py", line 3047, in main
    build = Build(arcadia, options.build_type, options.toolchain_params, force_ignore_local_files=not options.local_distbuild)
  File "E:\github\catboost\build\ymake_conf.py", line 443, in __init__
    self.tc = self._get_toolchain_options()
  File "E:\github\catboost\build\ymake_conf.py", line 571, in _get_toolchain_options
    return MSVCToolchainOptions(self, detector)
  File "E:\github\catboost\build\ymake_conf.py", line 2036, in __init__
    self.sdk_version = os.environ.get('WindowsSDKVersion').replace('\\', '')
AttributeError: 'NoneType' object has no attribute 'replace'

处理:

看报错的代码,
os.environ.get('WindowsSDKVersion').replace('\', '')

environ 是python的api,获取当前的所有环境变量的集合; 按照上一步走完即可.
更多还是参考: https://zhuanlan.zhihu.com/p/98384105
重启powershell,并管理员启动,进入catboost的源码目录下。

ya.make: WARNING System JDK required

Warn[-WUserWarn]: in $S/catboost/jvm-packages/catboost4j-prediction/src/native_impl/ya.make: WARNING System JDK required
Error[-WBadFile]: in $B/contrib/python/numpy/py3/numpy/random/pypy3-numpy-random.lib: cannot find source file: _bounded_integers.pyx
Error[-WBadIncl]: in $B/contrib/python/numpy/py3/numpy/random/pypy3-numpy-random.lib: could not resolve include file: contrib/python/numpy/py3/numpy/random/_bounded_integers.pxd included from here: $S/contrib/python/numpy/py3/numpy/random/_generator.pyx
Error[-WBadIncl]: in $B/contrib/python/numpy/py3/numpy/random/pypy3-numpy-random.lib: could not resolve include file: contrib/python/numpy/py3/numpy/random/_bounded_integers.pxd included from here: $S/contrib/python/numpy/py3/numpy/random/mtrand.pyx
Configure error (use -k to proceed)

处理措施: (最后一行报错提示了)

Configure error (use -k to proceed)

处理命令加上 -k.
就是我的最终命令:

PS E:\github\catboost\catboost\python-package\catboost>  ../../../ya make -r -DUSE_ARCADIA_PYTHON=no -DOS_SDK=local -DPYTHON_INCLUDE="/I D:/Anaconda3/include/" -DPYTHON_LIBRARIES="D:/Anaconda3/libs/python37.lib" -DCUDA_ROOT="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/" -o="E:/github/catboost/catboost/python-package/catboost/" -k

重启powershell,并管理员启动,进入catboost的源码目录下。

Windows Kits 下缺少 inttypes.h文件

e:\github\catboost\contrib\libs\cxxsupp\libcxx\include\inttypes.h(252): fatal error C1083: ????: D:\Windows Kits\10\Lib\Include\10.0.17134.0\ucrt/inttypes.h: No such file or directory
------- [CC] {FAILED} $(S)/catboost/cuda/cuda_util/fill.cpp

inttypes.h

这个, 貌似是添加-k后, catboost安装时自动修复了

corecrt.h文件缺少vcruntime.h 文件

vcruntime.h 文件是在vs2017目录下的, 安装lgb的gpu版本时,是把win10的sdk的lib复制过去, 这里需要反向也复制一次.

处理办法:

全局搜索这两个文件夹: 你的vs2017和win10的sdk目录:

把文件存在的目录复制一份到报错缺少文件的目录.

其他缺少文件的地方, 同上, 记得备份

文件是没有交集的, 所以你把一个文件夹复制进另一个文件夹是没有冲突的

容易忽视的报错原因

正确的是这个样子:

当出现其他的红色字样时, 快速按两次ctrl+c, 终止powershell, 观察内部的Error.

祝好运, warning一概忽略, Error和fatal Error 仔细看!

测试效果对比

使用GPU的catboost: (cpu 15%占用, gpu 8%作用占用)

    params = {
              'learning_rate': 0.03,
              'depth': 5,
              'l2_leaf_reg': 10,
              'bootstrap_type': 'Bernoulli',
              'od_type': 'Iter',
              'od_wait': 50,
              'random_seed': 2020,
              'allow_writing_files': False,
              'eval_metric': "AUC",
              'task_type': "GPU",
              # 'devices': 0,
              }

cpu版本: (cpu 100%占用)

  params = {
              'learning_rate': 0.03,
              'depth': 5,
              'l2_leaf_reg': 10,
              'bootstrap_type': 'Bernoulli',
              'od_type': 'Iter',
              'od_wait': 50,
              'random_seed': 2020,
              'allow_writing_files': False,
              'eval_metric': "AUC",
              # 'task_type': "GPU",
              # 'devices': 0,
              }

易得:

GPU貌似加速40%以上.

测试数据集为15万行*20列。

posted @ 2021-03-08 21:50  山枫叶纷飞  阅读(792)  评论(10编辑  收藏  举报