首页 > 解决方案 > 有没有办法在谷歌云 AI 平台中同时使用 GPU 加速器和 Torch 进行模型部署?

问题描述

我已经有一个 Torch 模型 (BERT),我想使用 ai-platform 服务来使用 GPU 获得在线预测,但我不知道该怎么做。

以下命令,没有加速器,工作:

gcloud alpha ai-platform versions create {VERSION} --model {MODEL_NAME} --origin=gs://{BUCKET}/models/ --python-version=3.5 --runtime-version=1.14 --package-uris=gs://{BUCKET}/packages/my-torch-package-0.1.tar.gz,gs://cloud-ai-pytorch/torch-1.0.0-cp35-cp35m-linux_x86_64.whl --machine-type=mls1-c4-m4 --prediction-class=predictor.CustomModelPrediction

但是,如果我尝试添加加速器参数:

--accelerator=^:^count=1:type=nvidia-tesla-k80

我收到以下错误消息:

ERROR: (gcloud.alpha.ai-platform.versions.create) INVALID_ARGUMENT: Field: version.machine_type Error: GPU accelerators are not supported on the requested machine type: mls1-c4-m4
- '@type': type.googleapis.com/google.rpc.BadRequest
  fieldViolations:
  - description: 'GPU accelerators are not supported on the requested machine type:
      mls1-c4-m4'
    field: version.machine_type

但是,如果我使用不同的机器类型,我知道我可以使用加速器,我会收到以下错误:

ERROR: (gcloud.alpha.ai-platform.versions.create) FAILED_PRECONDITION: Field: framework Error: Machine type n1-highcpu-4 does not support CUSTOM_CLASS.
- '@type': type.googleapis.com/google.rpc.BadRequest
  fieldViolations:
  - description: Machine type n1-highcpu-4 does not support CUSTOM_CLASS.
    field: framework

这就像任何支持 GPU 加速器的机器不支持自定义类(需要 AFAIK 才能使用 Torch),并且任何支持自定义类的机器都不支持 GPU 加速器。

有什么办法让它工作吗?

有很多关于如何在 Torch 中使用 ai-platform 的教程,但是我看不出使用 gcloud 来训练和预测是否必须在 CPU 上做所有事情的意义,所以这对我来说感觉很奇怪。

标签: pytorchgcloudgoogle-cloud-ml

解决方案


就目前而言,使用自定义预测例程处于测试阶段。此外,使用mls1-c1-m2 以外的其他机器类型也处于 Beta 阶段。

然而,正如您在之前引用的链接中看到的那样,GPU 不适用于类似 mls1 的机器。同时,这些是唯一允许在 TensorFlow 之外建立模型的机器类型。

总之,目前可能在 Torch 中部署您的预测模型并使用 GPU 可能不是一个可行的选择。


推荐阅读