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列。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM