google-cloud-ml - 在 AI Platform 中部署 PyTorch 模型
问题描述
我在 Google Cloud AI Platform 中部署 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.
配置:
安装程序.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}
解决方案
您需要使用与 Cloud AI Platform 兼容的 Pytorch 编译包 包信息在这里
此存储桶包含与 Cloud AI Platform 预测兼容的 PyTorch 编译包。这些文件从https://download.pytorch.org/whl/cpu/torch_stable.html的官方版本镜像
从文档
为了在 Cloud AI Platform Online Predictions 上部署 PyTorch 模型,您必须将其中一个包添加到您部署的版本的 packageURIs 字段中。选择与您的 Python 和 PyTorch 版本匹配的包。包名称遵循此模板:
包名称 =
torch-{TORCH_VERSION_NUMBER}-{PYTHON_VERSION}-linux_x86_64.whl
wherePYTHON_VERSION
= cp35-cp35m 用于运行时版本 < 1.15 的 Python 3,cp37-cp37m 用于运行时版本 >= 1.15 的 Python 3例如,如果我要部署基于 PyTorch 1.1.0 和 Python 3 的 PyTorch 模型,我的 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
从您的install_requires
依赖项中删除setup.py
2)torch
创建版本模型时包含包。
!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
推荐阅读
- javascript - Javascript - 可以在 HTML 变量声明中使用简写条件吗?
- python - 在 Scrapy 中修改 request.url 爬取一个 json 文件然后返回原始请求
- python - 仅当 id 列为空时才插入 postgresql,但返回整个数据帧
- typescript - 外部类型/嵌套属性上的用户定义类型保护?
- c - 使用字符串在 C 中创建优先级队列
- html - 如何在本地 HTML 文件中捕获页面未找到错误
- javascript - 像轮子一样围绕中心点旋转三角形
- javascript - 单击某个 css 类或 ID 时使用户的视口向上滚动
- r - `levels<-`(`*tmp*`, value = as.character(levels)) 中的错误:因子级别 [3] 重复
- android-emulator - 无法在具有 Core 2 cpu 的 PC 上运行模拟器