我正在 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.
配置:
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}
需要使用与云AI平台兼容的Pytorch编译包 包信息here
这个桶包含与 Cloud AI Platform 预测兼容的 PyTorch 编译包。这些文件是从官方版本镜像的https://download.pytorch.org/whl/cpu/torch_stable.html
来自文档
为了在Cloud AI Platform Online上部署PyTorch模型
预测,您必须将这些包之一添加到 packageURI 中
您部署的版本上的字段。选择与您的 Python 匹配的包
和 PyTorch 版本。包名称遵循以下模板:
包名 =torch-{TORCH_VERSION_NUMBER}-{PYTHON_VERSION}-linux_x86_64.whl
在哪里PYTHON_VERSION
= cp35-cp35m 适用于具有运行时版本的 Python 3 = 1.15 的 Python 3
例如,如果我要部署基于 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
从你的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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)