首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >人工智能平台下的PyTorch模型部署

人工智能平台下的PyTorch模型部署
EN

Stack Overflow用户
提问于 2020-02-26 21:51:19
回答 1查看 1.2K关注 0票数 3

我在Google平台上部署了Pytorch模型,我得到了以下错误:

代码语言:javascript
复制
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

代码语言:javascript
复制
from setuptools import setup

REQUIRED_PACKAGES = ['torch']

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

模型版本创建

代码语言:javascript
复制
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}
EN

回答 1

Stack Overflow用户

发布于 2020-02-26 21:51:19

您需要使用Pytorch编译的软件包,与Cloud平台包信息这里兼容

这个水桶包含与Cloud平台预测兼容的PyTorch编译包。这些文件在stable.html的正式构建中被镜像

从文件

为了在Cloud平台在线预测上部署PyTorch模型,必须将其中一个包添加到您部署的版本的packageURIs字段中。选择与Python和PyTorch版本相匹配的包。包名遵循此模板: 包名= torch-{TORCH_VERSION_NUMBER}-{PYTHON_VERSION}-linux_x86_64.whl,其中PYTHON_VERSION = cp35-cp35m用于运行时版本< 1.15,cp37-cp37m用于Python 3,运行时版本为>= 1.15。 例如,如果我要部署一个基于PyTorch 1.1.0和Python3的PyTorch模型,我的gcloud命令如下所示: 平台版本创建{VERSION_NAME} -模型{MODEL_NAME} .MODEL_NAME

总结如下:

1)从torch中的install_requires依赖项中删除setup.py

2)在创建版本模型时包含torch包。

代码语言:javascript
复制
!gcloud beta ai-platform versions create {VERSION_NAME} --model {MODEL_NAME} \
 --origin=gs://{BUCKET}/{MODEL_DIR}/ \
 --python-version=3.7 \
 --runtime-version={RUNTIME_VERSION} \
 --package-uris=gs://{BUCKET}/{PACKAGES_DIR}/text_classification-0.1.tar.gz,gs://cloud-ai-pytorch/torch-1.3.1+cpu-cp37-cp37m-linux_x86_64.whl \
 --prediction-class=model_prediction.CustomModelPrediction
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60423140

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档