如何使用深度学习平台发布的VM映像获取NVIDIA驱动程序?

时间:2019-09-16 21:14:04

标签: docker google-cloud-platform deep-learning google-dl-platform

我遇到了需要安装NVIDIA驱动程序的问题。

我最初基于此创建了一个计算引擎VM:

export IMAGE_FAMILY="pytorch-latest-cu100"
export ZONE="us-west1-b"
export INSTANCE_NAME="my-instance"

gcloud compute instances create $INSTANCE_NAME \
  --zone=$ZONE \
  --image-family=$IMAGE_FAMILY \
  --image-project=deeplearning-platform-release \
  --maintenance-policy=TERMINATE \
  --accelerator="type=nvidia-tesla-v100,count=1" \
  --metadata="install-nvidia-driver=True"`

我在此VM上部署的代码运行正常。现在,我需要在其上创建一个REST API层,因此根据this,我需要使用docker对应用程序进行容器化。

我尝试从以下位置构建docker映像:     gcr.io/deeplearning-platform-release/pytorch-latest-cu100 (通过上面的命令),但该图片似乎不存在。

然后我尝试从以下位置构建另一个图像:     gcr.io/deeplearning-platform-release/pytorch-gpu.1-1

但是现在当我运行代码时,出现以下错误:

Traceback (most recent call last):
  File "model.py", line 297, in run
    data = main(filepath)
  File "model.py", line 52, in main
    model = model.cuda()
  File "/root/miniconda3/lib/python3.7/site- 
packages/torch/nn/modules/module.py", line 260, in cuda
    return self._apply(lambda t: t.cuda(device))
  File "/root/miniconda3/lib/python3.7/site- 
packages/torch/nn/modules/module.py", line 187, in _apply
    module._apply(fn)
  File "/root/miniconda3/lib/python3.7/site- 
packages/torch/nn/modules/module.py", line 187, in _apply
module._apply(fn)
  File "/root/miniconda3/lib/python3.7/site- 
packages/torch/nn/modules/module.py", line 187, in _apply
    module._apply(fn)
  File "/root/miniconda3/lib/python3.7/site- 
 packages/torch/nn/modules/module.py", line 193, in _apply
    param.data = fn(param.data)
  File "/root/miniconda3/lib/python3.7/site- 
packages/torch/nn/modules/module.py", line 260, in <lambda>
    return self._apply(lambda t: t.cuda(device))
  File "/root/miniconda3/lib/python3.7/site- 
packages/torch/cuda/__init__.py", line 161, in _lazy_init
    _check_driver()
  File "/root/miniconda3/lib/python3.7/site- 
packages/torch/cuda/__init__.py", line 82, in _check_driver
    http://www.nvidia.com/Download/index.aspx""")
AssertionError: 
Found no NVIDIA driver on your system. Please check that you
have an NVIDIA GPU and installed a driver from
http://www.nvidia.com/Download/index.aspx

我的Dockerfile:

   FROM gcr.io/deeplearning-platform-release/pytorch-gpu.1-1
   WORKDIR /app
   COPY requirements.txt /app
   RUN pip install --no-cache-dir -r requirements.txt
   EXPOSE 8080
   COPY . /app/
   CMD [ "python","main.py" ]

我的main.py:

from flask import Flask, request

import model

app = Flask(__name__)

@app.route('/getduration', methods=['POST'])
def get_duration():
    try:
        data = request.args.get('param')
    except:
        data = None
    try:
        duration = model.run(data)
        return duration, 200
    except Exception as e:
        error = f"There was an error: {e}"
        return error, 500

if __name__ == '__main__':
    app.run(host='127.0.0.1', port=8080, debug=True)

如何更新Dockerfile以便可以使用Nvidia驱动程序?

1 个答案:

答案 0 :(得分:1)

您是否正在使用NVIDIA Docker?如果没有,那可能是您的问题。完全像nvidia-docker一样使用docker,它将使NVIDIA驱动程序在容器内可用。

https://github.com/NVIDIA/nvidia-docker