Commit f6ecdce1 authored by liucong's avatar liucong
Browse files

修改readme文档

parent 4e0028ec
...@@ -46,7 +46,7 @@ ErrorCode GPT2::Preprocessing(cuBERT::FullTokenizer tokenizer, ...@@ -46,7 +46,7 @@ ErrorCode GPT2::Preprocessing(cuBERT::FullTokenizer tokenizer,
std::vector<long unsigned int> &input_id) std::vector<long unsigned int> &input_id)
{ {
// 对问题进行分词操作 // 对问题进行分词操作
int max_seq_length =1024; int max_seq_length =1000;
std::vector<std::string> tokens_question; std::vector<std::string> tokens_question;
tokens_question.reserve(max_seq_length); tokens_question.reserve(max_seq_length);
tokenizer.tokenize(question, &tokens_question, max_seq_length); tokenizer.tokenize(question, &tokens_question, max_seq_length);
......
...@@ -8,21 +8,23 @@ GPT2主要使用Transformer的Decoder模块为特征提取器,并对Transforme ...@@ -8,21 +8,23 @@ GPT2主要使用Transformer的Decoder模块为特征提取器,并对Transforme
## Python版本推理 ## Python版本推理
本次采用GPT-2模型进行诗词生成任务,模型文件下载链接:https://pan.baidu.com/s/1KWeoUuakCZ5dualK69qCcw , 提取码:4pmh ,并将GPT2_shici.onnx模型文件保存在Resource/文件夹下。下面介绍如何运行python代码示例,具体推理代码解析,在Doc/Tutorial_Python.md目录中有详细说明 本次采用GPT-2模型进行诗词生成任务,模型文件下载链接:https://pan.baidu.com/s/1KWeoUuakCZ5dualK69qCcw , 提取码:4pmh ,并将GPT2_shici.onnx模型文件保存在Resource/文件夹下。下面介绍如何运行python代码示例,Python示例的详细说明见Doc目录下的Tutorial_Python.md。
### 安装镜像 ### 下载镜像
在光源可拉取推理的docker镜像,GPT2模型推理的镜像如下 在光源中下载MIGraphX镜像
```python ```python
docker pull image.sourcefind.cn:5000/dcu/admin/base/custom:ort1.14.0_migraphx3.0.0-dtk22.10.1 docker pull image.sourcefind.cn:5000/dcu/admin/base/custom:ort1.14.0_migraphx3.0.0-dtk22.10.1
``` ```
### 执行推理 ### 设置Python环境变量
1.参考《MIGraphX教程》设置好PYTHONPATH ```
export PYTHONPATH=/opt/dtk/lib:$PYTHONPATH
```
2.安装依赖 ### 安装依赖
```python ```python
# 进入gpt2 migraphx工程根目录 # 进入gpt2 migraphx工程根目录
...@@ -35,14 +37,15 @@ cd ./Python/ ...@@ -35,14 +37,15 @@ cd ./Python/
pip install -r requirements.txt pip install -r requirements.txt
``` ```
3.设置环境变量: ### 设置动态shape模式
```python ```python
# 设置动态shape模式
export MIGRAPHX_DYNAMIC_SHAPE=1 export MIGRAPHX_DYNAMIC_SHAPE=1
``` ```
4.在Python目录下执行如下命令运行该示例程序: ### 运行示例
在Python目录下执行如下命令运行该示例程序:
```python ```python
python gpt2.py python gpt2.py
...@@ -54,16 +57,18 @@ python gpt2.py ...@@ -54,16 +57,18 @@ python gpt2.py
## C++版本推理 ## C++版本推理
下面介绍如何运行python代码示例,具体推理代码解析,在Doc/Tutorial_Cpp目录中有详细说明 本次采用GPT-2模型进行诗词生成任务,模型文件下载链接:https://pan.baidu.com/s/1KWeoUuakCZ5dualK69qCcw , 提取码:4pmh ,并将GPT2_shici.onnx模型文件保存在Resource/文件夹下。下面介绍如何运行C++代码示例,C++示例的详细说明见Doc目录下的Tutorial_Cpp.md
参考Python版本推理中的构建安装,在光源中拉取推理的docker镜像 ### 下载镜像
### 修改CMakeLists.txt ```
docker pull image.sourcefind.cn:5000/dcu/admin/base/custom:ort1.14.0_migraphx3.0.0-dtk22.10.1
```
- 如果使用ubuntu系统,需要修改CMakeLists.txt中依赖库路径: ### 修改CMakeLists.txt
将"${CMAKE_CURRENT_SOURCE_DIR}/depend/lib64/"修改为"${CMAKE_CURRENT_SOURCE_DIR}/depend/lib/"
- **MIGraphX2.3.0及以上版本需要c++17** 如果使用ubuntu系统,需要修改CMakeLists.txt中依赖库路径:
将"${CMAKE_CURRENT_SOURCE_DIR}/depend/lib64/"修改为"${CMAKE_CURRENT_SOURCE_DIR}/depend/lib/"
### 构建工程 ### 构建工程
...@@ -94,9 +99,13 @@ export LD_LIBRARY_PATH=<path_to_gpt2_migraphx>/depend/lib/:$LD_LIBRARY_PATH ...@@ -94,9 +99,13 @@ export LD_LIBRARY_PATH=<path_to_gpt2_migraphx>/depend/lib/:$LD_LIBRARY_PATH
source ~/.bashrc source ~/.bashrc
``` ```
### 执行推理 ### 设置动态shape模式
运行GPT2示例程序,具体执行如下命令: ```
export MIGRAPHX_DYNAMIC_SHAPE=1
```
### 运行示例
```python ```python
# 进入gpt2 migraphx工程根目录 # 进入gpt2 migraphx工程根目录
...@@ -105,9 +114,6 @@ cd <path_to_gpt2_migraphx> ...@@ -105,9 +114,6 @@ cd <path_to_gpt2_migraphx>
# 进入build目录 # 进入build目录
cd ./build/ cd ./build/
# 设置动态shape模式
export MIGRAPHX_DYNAMIC_SHAPE=1
# 执行示例程序 # 执行示例程序
./GPT2 ./GPT2
``` ```
...@@ -122,6 +128,4 @@ https://developer.hpccube.com/codes/modelzoo/gpt2_migraphx ...@@ -122,6 +128,4 @@ https://developer.hpccube.com/codes/modelzoo/gpt2_migraphx
## 参考资料 ## 参考资料
https://github.com/yangjianxin1/GPT2-chitchat
https://github.com/Morizeyao/GPT2-Chinese https://github.com/Morizeyao/GPT2-Chinese
\ No newline at end of file
...@@ -113,7 +113,7 @@ ErrorCode GPT2::Preprocessing(cuBERT::FullTokenizer tokenizer, ...@@ -113,7 +113,7 @@ ErrorCode GPT2::Preprocessing(cuBERT::FullTokenizer tokenizer,
std::vector<long unsigned int> &input_id) std::vector<long unsigned int> &input_id)
{ {
// 分词操作 // 分词操作
int max_seq_length =1024; int max_seq_length =1000;
std::vector<std::string> tokens_question; std::vector<std::string> tokens_question;
tokens_question.reserve(max_seq_length); tokens_question.reserve(max_seq_length);
tokenizer.tokenize(question, &tokens_question, max_seq_length); tokenizer.tokenize(question, &tokens_question, max_seq_length);
......
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