AI平台中的PyTorch模型部署

时间:2020-02-26 21:51:19

标签: google-cloud-ml

我正在Google Cloud AI平台中部署Pytorch模型,出现以下错误:

ERROR: (gcloud.beta.ai-platform.versions.create) Create Version failed. Bad model detected with error: Model requires more memory than allowed. Please try to decrease the model size and re-deploy. If you continue to have error, please contact Cloud ML.

配置:

setup.py

from setuptools import setup

REQUIRED_PACKAGES = ['torch']

setup(
    name="iris-custom-model",
    version="0.1",
    scripts=["model.py"],
    install_requires=REQUIRED_PACKAGES
)

创建模型版本

MODEL_VERSION='v1'
RUNTIME_VERSION='1.15'
MODEL_CLASS='model.PyTorchIrisClassifier'

!gcloud beta ai-platform versions create {MODEL_VERSION} --model={MODEL_NAME} \
            --origin=gs://{BUCKET}/{GCS_MODEL_DIR} \
            --python-version=3.7 \
            --runtime-version={RUNTIME_VERSION} \
            --package-uris=gs://{BUCKET}/{GCS_PACKAGE_URI} \
            --prediction-class={MODEL_CLASS}

1 个答案:

答案 0 :(得分:0)

您需要使用与Cloud AI Platform软件包信息here

兼容的Pytorch编译软件包

This bucket包含与Cloud AI Platform预测兼容的PyTorch编译包。这些文件是从https://download.pytorch.org/whl/cpu/torch_stable.html

的官方版本中镜像而来的

来自文档

为了在Cloud AI Platform Online上部署PyTorch模型 预测,您必须将以下软件包之一添加到packageURIs中 您部署的版本上的字段。选择与您的Python匹配的软件包 和PyTorch版本。程序包名称遵循以下模板:

包装名称= torch-{TORCH_VERSION_NUMBER}-{PYTHON_VERSION}-linux_x86_64.whl其中 PYTHON_VERSION =带有运行时版本的Python 3的cp35-cp35m 1.15,适用于运行时版本> = 1.15

的Python 3的cp37-cp37m

例如,如果我要部署基于PyTorch的PyTorch模型 1.1.0和Python 3,我的gcloud命令如下所示:

gcloud beta ai-platform versions create {VERSION_NAME} --model {MODEL_NAME} 
 ...
--package-uris=gs://{MY_PACKAGE_BUCKET}/my_package-0.1.tar.gz,gs://cloud->ai-pytorch/torch-1.1.0-cp35-cp35m-linux_x86_64.whl

总结:

1)从torch的{​​{1}}依赖项中删除install_requires

2)创建版本模型时包括setup.py包。

torch