【问题标题】:Adding Intel MKL and MKL-DNN in Docker在 Docker 中添加英特尔 MKL 和 MKL-DNN
【发布时间】:2022-07-06 15:25:14
【问题描述】:

我使用 Docker 部署了机器学习代码(例如 Numpy、Scipy、LightGBM、PyTorch)。我正在使用 Python 和 Poetry,使用 pip 安装包。

我应该怎么做才能使用 MKL 和 MKL-DNN?我知道最标准的方法是使用 Anaconda,但我不能(大型企业,没有商业 Anaconda 许可证)。

pip install mkl 就够了吗?

如何安装 MKL-DNN,以便 PyTorch 使用它?

【问题讨论】:

    标签: python docker pip pytorch intel-mkl


    【解决方案1】:

    pip install mkl 就够了吗?

    不,不会,请参阅numpy install docs中的部分:

    pip 安装的 PyPI 上的 NumPy 轮子是使用 OpenBLAS 构建的。 OpenBLAS 库包含在轮子中。这使得轮子更大,如果用户也安装(例如)SciPy,他们现在将在磁盘上有两个 OpenBLAS 副本。

    所以你需要从源代码构建 numpy。

    我知道最标准的方式是使用 Anaconda,但我不能(大型企业,没有商业 Anaconda 许可证)。

    你考虑过使用 miniforge 和 miniconda 吗? IANAL,但我很确定你只是不允许在大型商业产品中使用 ana-/miniconda 发行版和 anaconda 频道,但conda-forge can still be used free of charge。您应该能够设置您在 conda-forge 中提到的所有要求。至少你可能会更容易从源代码编译 pytorch

    【讨论】:

      【解决方案2】:

      我试图将 MKL 添加到我的 docker 容器(基于 debian)阅读英特尔文档:我失败了​​。

      但是,有一个 docker 图像 OneAPI docker image 附带 numpy(1.21 是一个月前的高度)和 mkl 作为默认 BLAS。 这是 numpy 在我的机器上返回的内容(带有 i7-i10875H 的笔记本电脑)

      >>> import numpy as np
      >>> np.__config__.show()
      blas_mkl_info:
          libraries = ['mkl_rt', 'pthread']
          library_dirs = ['/opt/intel/oneapi/intelpython/latest/lib']
          define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
          include_dirs = ['/opt/intel/oneapi/intelpython/latest/include']
      blas_opt_info:
          libraries = ['mkl_rt', 'pthread']
          library_dirs = ['/opt/intel/oneapi/intelpython/latest/lib']
          define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
          include_dirs = ['/opt/intel/oneapi/intelpython/latest/include']
      lapack_mkl_info:
          libraries = ['mkl_rt', 'pthread']
          library_dirs = ['/opt/intel/oneapi/intelpython/latest/lib']
          define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
          include_dirs = ['/opt/intel/oneapi/intelpython/latest/include']
      lapack_opt_info:
          libraries = ['mkl_rt', 'pthread']
          library_dirs = ['/opt/intel/oneapi/intelpython/latest/lib']
          define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
          include_dirs = ['/opt/intel/oneapi/intelpython/latest/include']
      Supported SIMD extensions in this NumPy install:
          baseline = SSE,SSE2,SSE3,SSSE3,SSE41,POPCNT,SSE42
          found = 
          not found = AVX512_ICL
      

      但是,我尝试使用 anaconda 和一个基本的 docker 镜像,令我惊讶的是,anaconda 虚拟环境使用了 CBLAS,而我的 docker 镜像使用了 Openblas BLAS。

      我没有执行基准测试,但由于 mkl 实现使用除 AVX512_ICL 之外的所有指令集架构,我希望它会更快。

      蟒蛇

      我也很惊讶在我的 anaconda 环境中测试它,令我惊讶的是,blas 不是 mkl

      $ conda create -n test numpy --yes
      [...]
      $ conda activate test
      
      >>> import numpy as np
      >>> np.__config__.show()
      blas_info:
          libraries = ['cblas', 'blas', 'cblas', 'blas']
          library_dirs = ['/home/adrienpacifico/anaconda3/envs/test/lib']
          include_dirs = ['/home/adrienpacifico/anaconda3/envs/test/include']
          language = c
          define_macros = [('HAVE_CBLAS', None)]
      blas_opt_info:
          define_macros = [('NO_ATLAS_INFO', 1), ('HAVE_CBLAS', None)]
          libraries = ['cblas', 'blas', 'cblas', 'blas']
          library_dirs = ['/home/adrienpacifico/anaconda3/envs/test/lib']
          include_dirs = ['/home/adrienpacifico/anaconda3/envs/test/include']
          language = c
      lapack_info:
          libraries = ['lapack', 'blas', 'lapack', 'blas']
          library_dirs = ['/home/adrienpacifico/anaconda3/envs/test/lib']
          language = f77
      lapack_opt_info:
          libraries = ['lapack', 'blas', 'lapack', 'blas', 'cblas', 'blas', 'cblas', 'blas']
          library_dirs = ['/home/adrienpacifico/anaconda3/envs/test/lib']
          language = c
          define_macros = [('NO_ATLAS_INFO', 1), ('HAVE_CBLAS', None)]
          include_dirs = ['/home/adrienpacifico/anaconda3/envs/test/include']
      Supported SIMD extensions in this NumPy install:
          baseline = SSE,SSE2,SSE3
          found = SSSE3,SSE41,POPCNT,SSE42,AVX,F16C,FMA3,AVX2
          not found = AVX512F,AVX512CD,AVX512_KNL,AVX512_KNM,AVX512_SKX,AVX512_CLX,AVX512_CNL,AVX512_ICL
      

      我的base 环境使用openblas。

      我的基于python镜像的docker镜像--> Openblas

      Dockerfile:

      FROM python:3.10
      ENV SHELL=/bin/bash
      RUN apt-get update && \
          apt-get install build-essential
      RUN apt-get install -y sudo libaio1 wget unzip htop
      RUN pip install numpy
      
      openblas64__info:
          libraries = ['openblas64_', 'openblas64_']
          library_dirs = ['/usr/local/lib']
          language = c
          define_macros = [('HAVE_CBLAS', None), ('BLAS_SYMBOL_SUFFIX', '64_'), ('HAVE_BLAS_ILP64', None)]
          runtime_library_dirs = ['/usr/local/lib']
      blas_ilp64_opt_info:
          libraries = ['openblas64_', 'openblas64_']
          library_dirs = ['/usr/local/lib']
          language = c
          define_macros = [('HAVE_CBLAS', None), ('BLAS_SYMBOL_SUFFIX', '64_'), ('HAVE_BLAS_ILP64', None)]
          runtime_library_dirs = ['/usr/local/lib']
      openblas64__lapack_info:
          libraries = ['openblas64_', 'openblas64_']
          library_dirs = ['/usr/local/lib']
          language = c
          define_macros = [('HAVE_CBLAS', None), ('BLAS_SYMBOL_SUFFIX', '64_'), ('HAVE_BLAS_ILP64', None), ('HAVE_LAPACKE', None)]
          runtime_library_dirs = ['/usr/local/lib']
      lapack_ilp64_opt_info:
          libraries = ['openblas64_', 'openblas64_']
          library_dirs = ['/usr/local/lib']
          language = c
          define_macros = [('HAVE_CBLAS', None), ('BLAS_SYMBOL_SUFFIX', '64_'), ('HAVE_BLAS_ILP64', None), ('HAVE_LAPACKE', None)]
          runtime_library_dirs = ['/usr/local/lib']
      Supported SIMD extensions in this NumPy install:
          baseline = SSE,SSE2,SSE3
          found = SSSE3,SSE41,POPCNT,SSE42,AVX,F16C,FMA3,AVX2
          not found = AVX512F,AVX512CD,AVX512_KNL,AVX512_KNM,AVX512_SKX,AVX512_CLX,AVX512_CNL,AVX512_ICL
      

      【讨论】:

        猜你喜欢
        • 2019-11-19
        • 2016-09-26
        • 1970-01-01
        • 2018-02-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-01
        相关资源
        最近更新 更多