"vscode:/vscode.git/clone" did not exist on "fef257c5c50347943bb1e5e06ebb5e22fd9b69a0"
Commit e20c7f36 authored by yangql's avatar yangql
Browse files

修改为model zoo格式

parent 4c121fb5
# Generative Pre-Training2(GPT2)
# GPT2-ORT
## 论文
Language Models are Unsupervised Multitask Learners
## 模型介绍
GPT2模型:第二代生成式预训练模型(Generative Pre-Training2),使用ONNXRuntime推理框架进行推理。
- https://d4mucfpksywv.cloudfront.net/better-language-models/language-models.pdf
## 模型结构
GPT2主要使用Transformer的Decoder模块为特征提取器,并对Transformer Decoder进行了一些改动,原本的Decoder包含了两个Multi-Head Attention结构,而GPT2只保留了Mask Multi-Head Attention。
第二代生成式预训练模型(Generative Pre-Training2),GPT2主要使用Transformer的Decoder模块为特征提取器,并对Transformer Decoder进行了一些改动,原本的Decoder包含了两个Multi-Head Attention结构,而GPT2只保留了Mask Multi-Head Attention。
## Python版本推理
<img src="./Doc/Images/GPT_03.png" style="zoom:55%;" align=middle>
本次采用GPT-2模型进行诗词生成任务,模型文件下载链接:https://pan.baidu.com/s/1KWeoUuakCZ5dualK69qCcw , 提取码:4pmh ,并将GPT2_shici.onnx模型文件保存在Resource/文件夹下。下面介绍如何运行python代码示例,Python示例的详细说明见Doc目录下的Tutorial_Python.md。
### 下载镜像
## 算法原理
GPT-2中使用了掩模自注意力(masked self-attention),通过屏蔽当前位置的右边token,使模型可以更好的预测下一个token。
在光源中下载镜像:
<img src="./Doc/Images/GPT_04.png" style="zoom:70%;" align=middle>
```python
## 环境配置
### Docker
拉取镜像:
```
docker pull image.sourcefind.cn:5000/dcu/admin/base/custom:ort1.14.0_migraphx3.0.0-dtk22.10.1
```
### 设置Python环境变量
创建并启动容器,安装相关依赖:
```
docker run --shm-size 16g --network=host --name=gpt2_ort --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v $PWD/gpt2_ort:/home/gpt2_ort -it <Your Image ID> /bin/bash
# 激活dtk
source /opt/dtk/env.sh
```
## 推理
### Python版本推理
本次采用GPT-2模型进行诗词生成任务,模型文件下载链接:https://pan.baidu.com/s/1KWeoUuakCZ5dualK69qCcw , 提取码:4pmh ,并将GPT2_shici.onnx模型文件保存在Resource/文件夹下。下面介绍如何运行python代码示例,Python示例的详细说明见Doc目录下的Tutorial_Python.md。
#### 设置Python环境变量
```
export PYTHONPATH=/opt/dtk/lib:$PYTHONPATH
```
### 安装依赖
#### 安装依赖
```python
# 进入gpt2 ort工程根目录
cd <path_to_gpt2_ort>
......@@ -36,13 +46,10 @@ cd Python/
# 安装依赖
pip install -r requirements.txt
```
### 运行示例
#### 运行示例
```python
python gpt2.py
```
如下所示,采用交互式界面,通过输入开头诗词,GPT2模型可以生成后续的诗句。
```
......@@ -56,25 +63,13 @@ user:春风吹絮满江南
chatbot:春风吹絮满江南,一片离情酒半酣。记得小桥和雪看,梅花无数簇晴岚。
```
## C++版本推理
### C++版本推理
本次采用GPT-2模型进行诗词生成任务,模型文件下载链接:https://pan.baidu.com/s/1KWeoUuakCZ5dualK69qCcw , 提取码:4pmh ,并将GPT2_shici.onnx模型文件保存在Resource/文件夹下。下面介绍如何运行C++代码示例,C++示例的详细说明见Doc目录下的Tutorial_Cpp.md。
### 下载镜像
```
docker pull image.sourcefind.cn:5000/dcu/admin/base/custom:ort1.14.0_migraphx3.0.0-dtk22.10.1
```
### 构建工程
#### 构建工程
```
rbuild build -d depend
```
### 设置环境变量
#### 设置环境变量
将依赖库依赖加入环境变量LD_LIBRARY_PATH,在~/.bashrc中添加如下语句:
```
......@@ -87,9 +82,7 @@ export LD_LIBRARY_PATH=<path_to_gpt2_ort>/depend/lib64/:$LD_LIBRARY_PATH
source ~/.bashrc
source /opt/dtk/env.sh
```
### 运行示例
#### 运行示例
```cpp
# 进入gpt2 ort工程根目录
cd <path_to_gpt2_ort>
......@@ -114,10 +107,20 @@ question:春风吹絮满江南
chatbot:春风吹絮满江南,一片离情酒半酣。记得小桥和雪看,梅花无数簇晴岚。
```
## 应用场景
### 算法类别
`自然语言处理`
### 热点应用行业
`nlp`,`智能聊天助手`,`科研`
## 源码仓库及问题反馈
https://developer.hpccube.com/codes/modelzoo/gpt2_ort
## 参考
https://github.com/Morizeyao/GPT2-Chinese
\ No newline at end of file
https://github.com/Morizeyao/GPT2-Chinese
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment