研究开源gpt-2-simple项目,跑一个简单的模型,然后生成一段对话。用的是 Intel(R) Core(TM) i7-9700,8核8线程,训练最小的模型200次跑1个小时20分钟

这篇具有很好参考价值的文章主要介绍了研究开源gpt-2-simple项目,跑一个简单的模型,然后生成一段对话。用的是 Intel(R) Core(TM) i7-9700,8核8线程,训练最小的模型200次跑1个小时20分钟。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

前言


本文的原文连接是:
https://blog.csdn.net/freewebsys/article/details/108971807

未经博主允许不得转载。
博主CSDN地址是:https://blog.csdn.net/freewebsys
博主掘金地址是:https://juejin.cn/user/585379920479288
博主知乎地址是:https://www.zhihu.com/people/freewebsystem

1,关于gpt2的几个例子学习


快速使用docker 镜像进行环境搭建。
相关的chatGpt项目有:
gpt2官方模型:
https://github.com/openai/gpt-2
6.1K 星星:
https://github.com/Morizeyao/GPT2-Chinese
2.4K 星星:
https://github.com/yangjianxin1/GPT2-chitchat
1.6K 星星:
https://github.com/imcaspar/gpt2-ml

先找个简单的进行研究:
3.2K 星星:
https://github.com/minimaxir/gpt-2-simple

2,使用docker配置环境


先弄官方的例子,使用tensorflow的2.12 的镜像,因显卡驱动的问题,只能用cpu进行运算:

git clone https://github.com/minimaxir/gpt-2-simple
cd gpt-2-simple
docker run --name gpt2simple -itd -v `pwd`:/data -p 8888:8888 tensorflow/tensorflow:latest

版本说明,这边用的就是最小的版本:能跑就行。

latest: minimal image with TensorFlow Serving binary installed and ready to serve!
:latest-gpu: minimal image with TensorFlow Serving binary installed and ready to serve on GPUs!
:latest-devel - include all source/dependencies/toolchain to develop, along with a compiled binary that works on CPUs
:latest-devel-gpu - include all source dependencies/toolchain (cuda9/cudnn7) to develop, along with a compiled binary that works on NVIDIA GPUs.

然后进入docker 镜像中执行命令:
当然也可以使用Dockerfile 但是网速慢,且容易出错:

docker exec -it gpt2simple bash  

############### 以下是登陆后执行:

sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list

mkdir /root/.pip/

# 增加 pip 的源
echo "[global]" > ~/.pip/pip.conf
echo "index-url = https://mirrors.aliyun.com/pypi/simple/" >> ~/.pip/pip.conf
echo "[install]" >> ~/.pip/pip.conf
echo "trusted-host=mirrors.aliyun.com" >> ~/.pip/pip.conf

cd /data
#注释掉 tensorflow 依赖
sed -i 's/tensorflow/#tensorflow/g' requirements.txt

pip3 install -r requirements.txt

3,使用uget工具下载模型,文件大容易卡死


sudo apt install uget

然后就是网络特别的慢了。根本下载不了,就卡在进度中。几个特别大的模型,最大的6G。

一个比一个大,不知道压缩没有:
498M:
https://openaipublic.blob.core.windows.net/gpt-2/models/124M/model.ckpt.data-00000-of-00001
1.42G
https://openaipublic.blob.core.windows.net/gpt-2/models/355M/model.ckpt.data-00000-of-00001
3.10G
https://openaipublic.blob.core.windows.net/gpt-2/models/774M/model.ckpt.data-00000-of-00001
6.23G
https://openaipublic.blob.core.windows.net/gpt-2/models/1558M/model.ckpt.data-00000-of-00001

使用工具下载模型,命令行执行的时候容易卡死:

研究开源gpt-2-simple项目,跑一个简单的模型,然后生成一段对话。用的是 Intel(R) Core(TM) i7-9700,8核8线程,训练最小的模型200次跑1个小时20分钟

这个云地址不支持多线程下载,就下载了一个最小的124M的模型。
先尝个新鲜就行。

剩下的文件可以单独下载:

gpt2 里面的代码,去掉模型文件其他用脚本下载,哎网络是个大问题。
也没有国内的镜像。

download_model.py 124M
修改了代码,去掉了最大的model.ckpt.data 这个单独下载,下载了拷贝进去。

import os
import sys
import requests
from tqdm import tqdm

if len(sys.argv) != 2:
    print('You must enter the model name as a parameter, e.g.: download_model.py 124M')
    sys.exit(1)

model = sys.argv[1]

subdir = os.path.join('models', model)
if not os.path.exists(subdir):
    os.makedirs(subdir)
subdir = subdir.replace('\\','/') # needed for Windows

for filename in ['checkpoint','encoder.json','hparams.json', 'model.ckpt.index', 'model.ckpt.meta', 'vocab.bpe']:

    r = requests.get("https://openaipublic.blob.core.windows.net/gpt-2/" + subdir + "/" + filename, stream=True)

    with open(os.path.join(subdir, filename), 'wb') as f:
        file_size = int(r.headers["content-length"])
        chunk_size = 1000
        with tqdm(ncols=100, desc="Fetching " + filename, total=file_size, unit_scale=True) as pbar:
            # 1k for chunk_size, since Ethernet packet size is around 1500 bytes
            for chunk in r.iter_content(chunk_size=chunk_size):
                f.write(chunk)
                pbar.update(chunk_size)

4,研究使用gpt2-simple执行demo,训练200次


然后运行demo.py 代码
项目代码:

提前把模型和文件准备好:

https://raw.githubusercontent.com/karpathy/char-rnn/master/data/tinyshakespeare/input.txt

另存为,在工程目录
shakespeare.txt

gpt-2-simple/models$ tree 
.
└── 124M
    ├── checkpoint
    ├── encoder.json
    ├── hparams.json
    ├── model.ckpt.data-00000-of-00001
    ├── model.ckpt.index
    ├── model.ckpt.meta
    └── vocab.bpe

1 directory, 7 files

https://github.com/minimaxir/gpt-2-simple

import gpt_2_simple as gpt2
import os
import requests

model_name = "124M"
file_name = "shakespeare.txt"

sess = gpt2.start_tf_sess()

print("########### init start ###########")

gpt2.finetune(sess,
              file_name,
              model_name=model_name,
              steps=200)   # steps is max number of training steps
gpt2.generate(sess)

print("########### finish ###########")

执行:

time python demo.py

real 80m14.186s
user 513m37.158s
sys 37m45.501s

开始训练,做测试,模型训练200次。耗时是 1小时 20分钟。
用的是 Intel® Core™ i7-9700 CPU @ 3.00GHz,8核8线程的。
使用CPU训练,没有显卡。

研究开源gpt-2-simple项目,跑一个简单的模型,然后生成一段对话。用的是 Intel(R) Core(TM) i7-9700,8核8线程,训练最小的模型200次跑1个小时20分钟
cpu都是80%,load 是 7 ,风扇已经呼呼转了。
研究开源gpt-2-simple项目,跑一个简单的模型,然后生成一段对话。用的是 Intel(R) Core(TM) i7-9700,8核8线程,训练最小的模型200次跑1个小时20分钟

然后生成对话:
demo-run.py

import gpt_2_simple as gpt2

sess = gpt2.start_tf_sess()
gpt2.load_gpt2(sess)
gpt2.generate(sess)

执行结果,没有cpu/gpu 优化:

python demo_generate.py 
2023-03-03 13:11:53.801232: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-03-03 13:11:55.191519: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-03-03 13:11:57.054783: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:357] MLIR V1 optimization pass is not enabled
Loading checkpoint checkpoint/run1/model-200
Ministers' policy: policy
I am the king, and
I shall have none of you;
But, in the desire of your majesty,
I shall take your honour's honour,
And give you no better honour than
To be a king and a king's son,
And my honour shall have no more than that
Which you have given to me.

GLOUCESTER:

MONTAGUE:

Mistress:
Go, go, go, go, go, go, go, go, go!

GLOUCESTER:
You have done well, my lord;
I was but a piece of a body;
And, if thou meet me, I'll take thy pleasure;
And, if thou be not satisfied
I'll give thee another way, or let
My tongue hope that thou wilt find a friend:
I'll be your business, my lord.

MONTAGUE:
Go, go, go, go!

GLOUCESTER:
Go, go, go!

MONTAGUE:
Go, go, go!

GLOUCESTER:
You have been so well met, my lord,
I'll look you to the point:
If thou wilt find a friend, I'll be satisfied;
Thou hast no other choice but to be a king.

MONTAGUE:
Go, go, go!

GLOUCESTER:
Go, go, go!

MONTAGUE:
Go, go, go!

GLOUCESTER:
Go, go, go!

MONTAGUE:
Go, go, go!

GLOUCESTER:
Go, go, go!

KING RICHARD II:
A villain, if you have any, is a villain without a villain.

WARWICK:
I have seen the villain, not a villain,
But--

KING RICHARD II:
Here is the villain.

WARWICK:
A villain.

KING RICHARD II:
But a villain, let him not speak with you.

WARWICK:
Why, then, is there in this house no man of valour?

KING RICHARD II:
The Lord Northumberland, the Earl of Wiltshire,
The noble Earl of Wiltshire, and the Duke of Norfolk
All villainous.

WARWICK:
And here comes the villain?

KING RICHARD II:
He is a villain, if you be a villain.

每次生成的对话都不一样呢。可以多运行几次,生成的内容都是不一样的。

5,总结


ai果然是高技术含量的东西,代码啥的不多,就是没有太看懂。
然后消耗CPU和GPU资源,也是非常消耗硬件的。
这个很小的模型训练200次,都这么费时间,更何况是大数据量多参数的模型呢!!

同时这个基础设施也要搭建起来呢,有个项目要研究下了,就是
https://www.kubeflow.org/

得去研究服务器集群了,因为Nvidia的限制,服务器上跑的都是又贵又性能低的显卡。
但是可以本地跑集群做训练呢!!!

本文的原文连接是:
https://blog.csdn.net/freewebsys/article/details/108971807

研究开源gpt-2-simple项目,跑一个简单的模型,然后生成一段对话。用的是 Intel(R) Core(TM) i7-9700,8核8线程,训练最小的模型200次跑1个小时20分钟文章来源地址https://www.toymoban.com/news/detail-484193.html

到了这里,关于研究开源gpt-2-simple项目,跑一个简单的模型,然后生成一段对话。用的是 Intel(R) Core(TM) i7-9700,8核8线程,训练最小的模型200次跑1个小时20分钟的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 本地构建自己的chatgpt已成为可能,国外团队从GPT3.5提取大规模数据完成本地机器人训练,并开源项目源码和模型支持普通在笔记上运行chatgpt

    国外团队从GPT3.5提取大规模数据完成本地机器人训练,并开源项目源码和模型支持,普通在笔记上运行chatgpt。下面是他们分享的:收集到的数据、数据管理程序、训练代码和最终模型,以促进开放研究和可重复性。 在 2023 年 3 月 20 日至 2023 年 3 月 26 日期间,该团队使用 GPT

    2023年04月21日
    浏览(43)
  • GPT-2 开源模型本地搭建(一)

    ChatGPT (gpt-35-turbo) 和 GPT-4 模型是针对对话接口进行了优化的语言模型,都是输入对话和输出消息模式。 以上模型的行为与旧的 GPT-3、GPT-2 模型不同,旧的模型是文本输入和文本输出,这意味着它们接受了提示字符串并返回了一个会追加到提示的补全,旧的模型属于文本补全类

    2023年04月26日
    浏览(35)
  • 微软最新研究成果:使用GPT-4合成数据来训练AI模型,实现SOTA!

    文本嵌入是各项NLP任务的基础,用于将自然语言转换为向量表示。现有的大部分方法通常采用 复杂的多阶段训练流程 ,先在大规模数据上训练,再在小规模标注数据上微调。此过程依赖于手动收集数据制作正负样本对,缺乏任务的多样性和语言多样性。 此外,大部分方法采

    2024年02月02日
    浏览(38)
  • GPT4All 一个开源 ChatGPT

    ChatGPT 正在迅速发展与传播,新的大型语言模型 (LLM) 正在以越来越快的速度开发。就在过去几个月,有了颠覆性的 ChatGPT 和现在的 GPT-4。明确定义,GPT 代表(Generative Pre-trained Transformer),是底层语言模型,而 ChatGPT是为会话设计的具体实现。比尔·盖茨 (Bill Gates) 回顾 OpenAI

    2023年04月17日
    浏览(34)
  • 开源了,我做了一个基于GPT的桌宠聊天系统:Pet-GPT!

    最近chatgpt的热度高居不下。作为一个深度成谜者,发现大部分开发者在调用GPT的时候要不就是基于Tauri做本地窗口外接网页,要不就是web直接展示。在沉思苦想一段时间后,才发现好像没啥什么人用pyqt做啊?特别是没人用桌面宠物(想起了当初QQ宠物,怀念啊)来访问。 既然

    2023年04月17日
    浏览(28)
  • 文本生成高精准3D模型,北京智源AI研究院等出品—3D-GPT

    北京智源AI研究院、牛津大学、澳大利亚国立大学联合发布了一项研究—3D-GPT,通过文本问答方式就能创建高精准3D模型。 据悉,3D-GPT使用了大语言模型的多任务推理能力,通过任务调度代理、概念化代理和建模代理三大模块,简化了3D建模的开发流程实现技术民主化。 但3D-

    2024年02月03日
    浏览(34)
  • 本地运行 LLAMA & GPT-3.5-TURBO开源项目

    git: nomic-ai/gpt4all: gpt4all: an ecosystem of open-source chatbots trained on a massive collections of clean assistant data including code, stories and dialogue (github.com) 下载好源码后,的目录结构:  视频中说的 chat 目录在: gpt4all-training/chat  下载 gpt4all 使用的模型地址:https://the-eye.eu/public/AI/models/nomic-

    2024年02月11日
    浏览(41)
  • 我的创作纪念日兼GPT模型简单介绍

    目录 一、引言 二、收获与开端 2.1 问题:在创作的过程中都有哪些收获? 2.2 模型开端 三、日常与深入 3.1 问题:当前创作和你的学习是什么样的关系? 3.2 模型深入介绍 3.2.1 无监督预训练 3.2.2 有监督下游任务精调 四、憧憬与应用 4.1 问题:你的创作规划和终极目标是什

    2024年02月13日
    浏览(25)
  • 用 GPT-4 给开源项目 GoPool 重构测试代码 - 每天5分钟玩转 GPT 编程系列(8)

    目录 1. 好险,差点被喷 2. 重构测试代码 2.1 引入 Ginkgo 测试框架 2.2 尝试改造旧的测试用例 2.3 重构功能测试代码 3. 总结 早几天发了一篇文章:《仅三天,我用 GPT-4 生成了性能全网第一的 Golang Worker Pool,轻松打败 GitHub 万星项目》,这标题是挺容易被怼,哇咔咔;不过最终“

    2024年02月12日
    浏览(30)
  • Meta Llama 3强势来袭:迄今最强开源大模型,性能媲美GPT-4

    前言 Meta的最新语言模型Llama 3已经发布,标志着在大型语言模型(LLM)领域的一次重大突破,其性能在行业内与GPT-4相媲美。此次更新不仅提升了模型的处理能力和精确性,还将开源模型的性能推向了一个新的高度。 Huggingface模型下载: https://huggingface.co/meta-llama AI 快站模型免

    2024年04月26日
    浏览(38)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包