GCP AI Platform:创建自定义预测器模型版本时出错训练模型 Pytorch 模型 + torchvision.transform [重要]

如何解决GCP AI Platform:创建自定义预测器模型版本时出错训练模型 Pytorch 模型 + torchvision.transform [重要]

我目前正在尝试按照 https://cloud.google.com/ai-platform/prediction/docs/deploying-models#gcloud_1 将自定义模型部署到 AI 平台。它基于 'Pytorch' 和 'torchvision.transform' 的预训练模型的组合。目前,我不断收到以下错误,这恰好与自定义预测的 500MB 限制有关。

错误:(gcloud.beta.ai-platform.versions.create) 创建版本失败。检测到错误模型错误:模型需要的内存超出允许范围。请尝试减小模型大小并重新部署。如果您继续遇到错误,请联系支持人员。

Setup.py

from setuptools import setup
from pathlib import Path

base = Path(__file__).parent
REQUIRED_PACKAGES = [line.strip() for line in open(base/"requirements.txt")]
print(f"\nPackages: {REQUIRED_PACKAGES}\n\n")

# [torch==1.3.0,torchvision==0.4.1,ImageHash==4.2.0
# Pillow==6.2.1,pyvis==0.1.8.2] installs 800mb worth of files

setup(description="Extract features of a image",author='Amrit',name='test',version='0.1',install_requires=REQUIRED_PACKAGES,project_urls={
                    'Documentation':'https://cloud.google.com/ai-platform/prediction/docs/custom-prediction-routines#tensorflow','Deploy':'https://cloud.google.com/ai-platform/prediction/docs/deploying-models#gcloud_1','Ai_platform troubleshooting':'https://cloud.google.com/ai-platform/training/docs/troubleshooting','Say Thanks!': 'https://medium.com/searce/deploy-your-own-custom-model-on-gcps-ai-platform- 
 7e42a5721b43','google Torch wheels':"http://storage.googleapis.com/cloud-ai-pytorch/readme.txt",'Torch & torchvision wheels':"https://download.pytorch.org/whl/torch_stable.html "
                    },python_requires='~=3.7',scripts=['predictor.py','preproc.py'])

采取的步骤: 尝试将 ‘torch’ 和 torchvision 直接添加到 setup.py 文件中的 ‘REQUIRED_PACKAGES’ 列表中,以便在部署时提供 PyTorch + torchvision 作为要安装的依赖项。我猜,Ai 平台内部为 PyTorch 下载了 500 MB 的 PyPI 包,这导致我们的模型部署失败。如果我仅使用“torch”部署模型并且它似乎可以正常工作(当然会因找不到库“torchvision”而引发错误)

文件大小

  • pytorchtorch-1.3.1+cpu-cp37-cp37m-linux_x86_64.whl111MB )
  • torchvisiontorchvision-0.4.1+cpu-cp37-cp37m-linux_x86_64.whl46MB ) 来自 https://download.pytorch.org/whl/torch_stable.html 并将其存储在 GKS 上。
  • 压缩的预测模型文件(.tar.gz 格式),它是 setup.py 的输出(5kb
  • 经过训练的 PyTorch 模型(大小 44MB

总的来说,模型依赖项应该小于 250MB,但仍然不断收到此错误。还尝试使用 Google 镜像包 http://storage.googleapis.com/cloud-ai-pytorch/readme.txt 提供的 torch 和 torchvision,但同样的内存问题仍然存在。人工智能平台对我们来说是全新的,希望得到专业人士的一些意见。

更多信息:

GCP CLI 输入:

我的环境变量:

BUCKET_NAME= “something”
MODEL_DIR="gs://$BUCKET_NAME/"
VERSION_NAME='v6'
MODEL_NAME="something_model"
STAGING_BUCKET=$MODEL_DIR"staging_area/"
# TORCH_PACKAGE=$MODEL_DIR"package/torch-1.3.1+cpu-cp37-cp37m-linux_x86_64.whl"
# TORCHVISION_PACKAGE=$MODEL_DIR"package/torchvision-0.4.1+cpu-cp37-cp37m-linux_x86_64.whl"
TORCH_PACKAGE="gs://cloud-ai-pytorch/torch-1.3.1+cpu-cp37-cp37m-linux_x86_64.whl"
TORCHVISION_PACKAGE="gs://cloud-ai-pytorch/torchvision-0.4.1+cpu-cp37-cp37m-linux_x86_64.whl"
CUSTOM_CODE_PATH=$STAGING_BUCKET"imt_ai_predict-0.1.tar.gz"
PREDICTOR_CLASS="predictor.MyPredictor"
REGION='europe-west1'
MACHINE_TYPE='mls1-c4-m2'
 
gcloud beta ai-platform versions create $VERSION_NAME   \
--model=$MODEL_NAME   \
--origin=$MODEL_DIR  \
 --runtime-version=2.3  \
 --python-version=3.7   \
--machine-type=$MACHINE_TYPE  \
 --package-uris=$CUSTOM_CODE_PATH,$TORCH_PACKAGE,$TORCHVISION_PACKAGE   \
--prediction-class=$PREDICTOR_CLASS \ 

GCP CLI 输出:

 **[1] global**
 [2] asia-east1
 [3] asia-northeast1
 [4] asia-southeast1
 [5] australia-southeast1
 [6] europe-west1
 [7] europe-west2
 [8] europe-west3
 [9] europe-west4
 [10] northamerica-northeast1
 [11] us-central1
 [12] us-east1
 [13] us-east4
 [14] us-west1
 [15] cancel
Please enter your numeric choice:  1
 
To make this the default region,run `gcloud config set ai_platform/region global`.
 
Using endpoint [https://ml.googleapis.com/]
Creating version (this might take a few minutes)......failed.                                                                                                                                            
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 experience errors,please contact support.**

我的发现: 找到了一些文章,人们以同样的方式为 PyTorch 包苦苦挣扎,并通过在 GCS 上安装火炬轮使其工作(https://medium.com/searce/deploy-your-own-custom-model-on-gcps-ai-platform- 7e42a5721b43)。 已经尝试了与 torch 和 torchvision 相同的方法,但到目前为止还没有运气,正在等待来自“cloudml-feedback@google.com cloudml-feedback@google.com”的回复。任何有关在 AI 平台上工作的基于自定义 torch_torchvision 的自定义预测器的帮助都会很棒。

解决方法

通过几件事的组合解决了这个问题。我坚持使用 4GB CPU MLS1 机器和自定义预测器例程 (

  • 使用 setup.py 参数安装库,而不是仅解析包名称及其版本,添加正确的火炬轮(最好
REQUIRED_PACKAGES = [line.strip() for line in open(base/"requirements.txt")] +\
['torchvision==0.5.0','torch @ https://download.pytorch.org/whl/cpu/torch-1.4.0%2Bcpu-cp37-cp37m-linux_x86_64.whl']
  • 我减少了预处理步骤。无法适应所有这些,所以 jsonify 你的 SEND 响应并从 preproc.py 和 predictor.py 中获取一个
import json
json.dump(your data to send to predictor class)
  • 从所需库的类中导入这些函数。
from torch import zeros,load 
    your code

[重要]

  • 尚未针对已训练模型测试不同类型的序列化对象,这可能与哪个(torch.save、pickle、joblib 等)节省内存有所不同。

  • 为那些组织是 GCP 合作伙伴的人找到了这个链接,他们可能能够申请更多配额(我猜从 500MB 到 2GB 左右)。不必朝这个方向发展,因为我的问题得到了解决,其他人也弹出了哈哈。 https://cloud.google.com/ai-platform/training/docs/quotas

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-