由于“模型需要比允许的更多的内存”,因此无法使用 Google Cloud AI Platform 部署用于预测服务的小型转换器模型

如何解决由于“模型需要比允许的更多的内存”,因此无法使用 Google Cloud AI Platform 部署用于预测服务的小型转换器模型

我有一个经过微调的 distilgpt2 模型,我想使用 GCP 人工智能平台进行部署。

我遵循了在 GCP 上部署自定义预测例程的所有文档,但在创建模型时出现错误:

创建版本失败。检测到错误模型错误:模型需要的内存超出允许范围。请尝试减小模型大小并重新部署。

这是我的 setup.py 文件:

from setuptools import setup

setup(
    name="generator_package",version="0.2",include_package_data=True,scripts=["generator_class.py"],install_requires=['transformers==2.8.0']
)

然后我使用以下方法创建模型版本:

gcloud beta ai-platform versions create v1 --model my_model \
 --origin=gs://my_bucket/model/ \
 --python-version=3.7 \
 --runtime-version=2.3 \
 --package-uris=gs://my_bucket/packages/gpt2-0.1.tar.gz,gs://cloud-ai-pytorch/torch-1.3.1+cpu-cp37-cp37m-linux_x86_64.whl \
 --prediction-class=model_prediction.CustomModelPrediction

按照这个答案:PyTorch model deployment in AI Platform,我想出了如何在我的自定义预测例程中安装 pytorch,但仍然出现上述错误。我相信它可能与 transformers 包有关,因为它有 torch 作为依赖项。这会导致问题吗?

我已尝试了所有建议的路线,但无法使其正常工作,但仍然出现上述错误。我正在使用最小的 gpt2 模型并且完全在内存中。

成功部署到 GCP 的任何人都可以在这里提供一些见解。

更新:

因此,为了解决 transformers 还尝试安装 torch 的上述问题,这可能会导致问题,我从源代码重建了 .whl 文件并删除了其他软件包,下面是编辑过的 setup.py 文件并使用 python setup.py bdist_wheel 构建。

然后,我在 GCP 中创建模型版本时将此 whl 添加到所需的依赖项中,并从我自己的 transformers==2.8.0 中删除了 setup.py。但它仍然给出同样的错误模型需要更多的内存=(

import shutil

from pathlib import Path



from setuptools import find_packages,setup





# Remove stale transformers.egg-info directory to avoid https://github.com/pypa/pip/issues/5466

stale_egg_info = Path(__file__).parent / "transformers.egg-info"

if stale_egg_info.exists():

    print(

        (

            "Warning: {} exists.\n\n"

            "If you recently updated transformers to 3.0 or later,this is expected,\n"

            "but it may prevent transformers from installing in editable mode.\n\n"

            "This directory is automatically generated by Python's packaging tools.\n"

            "I will remove it now.\n\n"

            "See https://github.com/pypa/pip/issues/5466 for details.\n"

        ).format(stale_egg_info)

    )

    shutil.rmtree(stale_egg_info)





extras = {}



extras["mecab"] = ["mecab-python3"]

extras["sklearn"] = ["scikit-learn"]

# extras["tf"] = ["tensorflow"]

# extras["tf-cpu"] = ["tensorflow-cpu"]

# extras["torch"] = ["torch"]



extras["serving"] = ["pydantic","uvicorn","fastapi","starlette"]

extras["all"] = extras["serving"] + ["tensorflow","torch"]



extras["testing"] = ["pytest","pytest-xdist"]

extras["docs"] = ["recommonmark","sphinx","sphinx-markdown-tables","sphinx-rtd-theme"]

extras["quality"] = [

    "black","isort","flake8",]

extras["dev"] = extras["testing"] + extras["quality"] + ["mecab-python3","scikit-learn","tensorflow","torch"]



setup(

    name="transformers",version="2.8.0",author="Thomas Wolf,Lysandre Debut,Victor Sanh,Julien Chaumond,Sam Shleifer,Google AI Language Team Authors,Open AI team Authors,Facebook AI Authors,Carnegie Mellon University Authors",author_email="thomas@huggingface.co",description="State-of-the-art Natural Language Processing for TensorFlow 2.0 and PyTorch",long_description=open("README.md","r",encoding="utf-8").read(),long_description_content_type="text/markdown",keywords="NLP deep learning transformer pytorch tensorflow BERT GPT GPT-2 google openai CMU",license="Apache",url="https://github.com/huggingface/transformers",package_dir={"": "src"},packages=find_packages("src"),install_requires=[

        "numpy","tokenizers == 0.5.2",# dataclasses for Python versions that don't have it

        "dataclasses;python_version<'3.7'",# accessing files from S3 directly

        "boto3",# filesystem locks e.g. to prevent parallel downloads

        "filelock",# for downloading models over HTTPS

        "requests",# progress bars in model download and training scripts

        "tqdm >= 4.27",# for OpenAI GPT

        "regex != 2019.12.17",# for XLNet

        "sentencepiece",# for XLM

        "sacremoses",],extras_require=extras,scripts=["transformers-cli"],python_requires=">=3.6.0",classifiers=[

        "Development Status :: 5 - Production/Stable","Intended Audience :: Developers","Intended Audience :: Education","Intended Audience :: Science/Research","License :: OSI Approved :: Apache Software License","Operating System :: OS Independent","Programming Language :: Python :: 3","Programming Language :: Python :: 3.6","Programming Language :: Python :: 3.7","Topic :: Scientific/Engineering :: Artificial Intelligence",)

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

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 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 -&gt; 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(&quot;/hires&quot;) 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&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res