textgen教程(持续更新ing...)

文章介绍了TextGen项目,一个实现多种文本生成模型如LLaMA、BLOOM和GPT2的库。作者建议使用虚拟环境进行安装,并提到了protobuf版本问题的解决方法。此外,还分享了在线对联生成器的链接以及LLaMA模型的测试代码。
部署运行你感兴趣的模型镜像

诸神缄默不语-个人优快云博文目录

官方GitHub项目:shibing624/textgen: TextGen: Implementation of Text Generation models, include LLaMA, BLOOM, GPT2, BART, T5, SongNet and so on. 文本生成模型,实现了包括LLaMA,ChatGLM,BLOOM,GPT2,Seq2Seq,BART,T5,UDA等模型的训练和预测,开箱即用。

注意:由于这个包及其依赖的很多包都更新很快,因此博主只能保证在撰写博文时代码可用。

最近更新时间:2023.6.25
最早更新时间:2023.6.20

1. 安装

我一开始没意识到它requirements这么复杂,所以直接安装了……
事实上建议新建一个虚拟环境来安装。

别的包都在用pypi时会自动安装,这个包不会,需要手动安装:pip install sentencepiece
https://github.com/google/sentencepiece

另外建议将protobuf包downgrade:pip install protobuf==3.20.*
如果不这么干的话会出现报错:

TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

另一种解决方案是设置PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python(可以直接在Python解释器前面加这个),但是太麻烦了。
解决方案参考自:python - TypeError: Descriptors cannot not be created directly - Stack Overflow

官方GitHub项目上提供了两种安装方式,一是直接用pip install,二是安装develop版。建议用后者,因为更新很快,pypi没跟上:

git clone https://github.com/shibing624/textgen.git
cd textgen
python setup.py install

顺便给一个用源码安装时手动满足requirements.txt的代码(与系统和环境版本有关,仅供参考)(还没写完,等一下我在装新服务器一边装一边写):

conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
pip install loguru
pip install jieba
pip install cpm-kernels
pip install datasets
pip install gensim
pip install peft
pip install rouge
pip install sacremoses
pip install tensorboard
pip install text2vec
pip install wandb

2. 在线应用

官方提供了一个对联生成器:https://huggingface.co/spaces/shibing624/chinese-couplet-generate
在这里插入图片描述

3. LLaMA

英文版(即LLaMA原版)直接测试:https://github.com/PolarisRisingWar/llm-throught-ages/blob/master/models/LLaMA/textgen_llama1.py

中文版(LLaMA的checkpoint和chinese-alpaca-lora-7b)直接测试:
缓慢版(在代码中合并checkpoint):https://github.com/PolarisRisingWar/llm-throught-ages/blob/master/models/LLaMA/textgen_llama2.py
快速版(提前合并好checkpoint):https://github.com/PolarisRisingWar/llm-throught-ages/blob/master/models/LLaMA/textgen_llama3.py

您可能感兴趣的与本文相关的镜像

GPT-oss:20b

GPT-oss:20b

图文对话
Gpt-oss

GPT OSS 是OpenAI 推出的重量级开放模型,面向强推理、智能体任务以及多样化开发场景

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

诸神缄默不语

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值