Commit 68ebcaec authored by xiabo's avatar xiabo
Browse files

Update README.md

parent 56e507e0
# LLama_lmdeploy # InterLm_lmdeploy
## 论文 ## 论文
- [https://arxiv.org/pdf/2302.13971.pdf](https://arxiv.org/pdf/2302.13971.pdf)
## 模型结构 ## 模型结构
LLAMA网络基于 Transformer 架构。提出了各种改进,并用于不同的模型,例如 PaLM。以下是与原始架构的主要区别: InternLM 是一个开源的轻量级训练框架,旨在支持模型预训练,而不需要大量的依赖。InternLM深度整合了Flash-attention,Apex等高性能模型算子,提高了训练效率。通过架构Hybrid Zero技术,实现计算和通信的高效重叠,大幅降低了训练过程中的跨节点通信流量。
预归一化。为了提高训练稳定性,对每个transformer 子层的输入进行归一化,而不是对输出进行归一化。使用 RMSNorm 归一化函数。
SwiGLU 激活函数 [PaLM]。使用 SwiGLU 激活函数替换 ReLU 非线性以提高性能。使用 2 /3 4d 的维度而不是 PaLM 中的 4d。
旋转嵌入。移除了绝对位置嵌入,而是添加了旋转位置嵌入 (RoPE),在网络的每一层。
![img](./docs/llama.png) ![img](./docs/interlm.jpg)
## 算法原理 ## 算法原理
LLama是一个基础语言模型的集合,参数范围从7B到65B。在数万亿的tokens上训练出的模型,并表明可以专门使用公开可用的数据集来训练最先进的模型,而不依赖于专有的和不可访问的数据集。 InterLM是一个基础语言模型的集合,参数范围从7B到20B。在数万亿的tokens上训练出的模型,并表明可以专门使用公开可用的数据集来训练最先进的模型,而不依赖于专有的和不可访问的数据集。
![img](./docs/llama_1.png) ![img](./docs/interlm.png)
## 环境配置 ## 环境配置
提供[光源](https://www.sourcefind.cn/#/service-details)拉取推理的docker镜像: 提供光源拉取推理的docker镜像:
``` ```
docker pull image.sourcefind.cn:5000/dcu/admin/base/custom:lmdeploy0.0.13_dtk23.04_torch1.13_py38 docker pull image.sourcefind.cn:5000/dcu/admin/base/custom:lmdeploy0.0.13_dtk23.04_torch1.13_py38
# <Image ID>用上面拉取docker镜像的ID替换 # <Image ID>用上面拉取docker镜像的ID替换
# <Host Path>主机端路径 # <Host Path>主机端路径
# <Container Path>容器映射路径 # <Container Path>容器映射路径
docker run -it --name qwen --shm-size=1024G --device=/dev/kfd --device=/dev/dri/ --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --ulimit memlock=-1:-1 --ipc=host --network host --group-add video -v <Host Path>:<Container Path> <Image ID> /bin/bash docker run -it --name interlm --shm-size=1024G --device=/dev/kfd --device=/dev/dri/ --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --ulimit memlock=-1:-1 --ipc=host --network host --group-add video -v <Host Path>:<Container Path> <Image ID> /bin/bash
``` ```
镜像版本依赖: 镜像版本依赖:
* DTK驱动:dtk23.04 * DTK驱动:dtk23.04
...@@ -47,11 +44,11 @@ cd .. && python3 setup.py install ...@@ -47,11 +44,11 @@ cd .. && python3 setup.py install
``` ```
### 模型下载 ### 模型下载
[LLama](https://huggingface.co/meta-llama) [internlm-chat-7b](https://huggingface.co/internlm/internlm-chat-7b)
支持模型包括:LLama-7B、LLama-13B、LLama-30B、LLama-65B、LLama2-7B、LLama2-13B、LLama2-70B [internlm-chat-20b](https://huggingface.co/internlm/internlm-chat-20b)
### 运行 LLama-7b ### 运行 internlm-chat-7
``` ```
# 模型转换 # 模型转换
# <model_name> 模型的名字 ('llama', 'internlm', 'vicuna', 'internlm-chat-7b', 'internlm-chat', 'internlm-chat-7b-8k', 'internlm-chat-20b', 'internlm-20b', 'baichuan-7b', 'baichuan2-7b', 'llama2', 'qwen-7b', 'qwen-14b') # <model_name> 模型的名字 ('llama', 'internlm', 'vicuna', 'internlm-chat-7b', 'internlm-chat', 'internlm-chat-7b-8k', 'internlm-chat-20b', 'internlm-20b', 'baichuan-7b', 'baichuan2-7b', 'llama2', 'qwen-7b', 'qwen-14b')
...@@ -61,10 +58,10 @@ cd .. && python3 setup.py install ...@@ -61,10 +58,10 @@ cd .. && python3 setup.py install
# <model_format> 保存输出的目标路径(默认./workspace) # <model_format> 保存输出的目标路径(默认./workspace)
# <tp> 用于张量并行的GPU数量应该是2^n # <tp> 用于张量并行的GPU数量应该是2^n
lmdeploy convert --model_name llama --model_path /path/to/model --model_format hf --tokenizer_path None --dst_path ./workspace_llama7b --tp 1 lmdeploy convert --model_name internlm-chat-7b --model_path /path/to/model --model_format hf --tokenizer_path None --dst_path ./workspace_interlm7b --tp 1
# bash界面运行 # bash界面运行
lmdeploy chat turbomind --model_path ./workspace_llama7b --tp 1 # 输入问题后执行2次回车进行推理 lmdeploy chat turbomind --model_path ./workspace_interlm7b --tp 1 # 输入问题后执行2次回车进行推理
# 服务器网页端运行 # 服务器网页端运行
...@@ -76,108 +73,30 @@ lmdeploy chat turbomind --model_path ./workspace_llama7b --tp 1 # 输入问 ...@@ -76,108 +73,30 @@ lmdeploy chat turbomind --model_path ./workspace_llama7b --tp 1 # 输入问
# <tp> 用于张量并行的GPU数量应该是2^n (和模型转换的时候保持一致) # <tp> 用于张量并行的GPU数量应该是2^n (和模型转换的时候保持一致)
# <restful_api> modelpath_or_server的标志(默认是False) # <restful_api> modelpath_or_server的标志(默认是False)
lmdeploy serve gradio --model_path_or_server ./workspace_llama7b --server_name {ip} --server_port {pord} --batch_size 32 --tp 1 --restful_api False lmdeploy serve gradio --model_path_or_server ./workspace_interlm7b --server_name {ip} --server_port {pord} --batch_size 32 --tp 1 --restful_api False
在网页上输入{ip}:{pord}即可进行对话
```
### 运行 LLama-13b
```
# 模型转换
lmdeploy convert --model_name llama --model_path /path/to/model --model_format hf --tokenizer_path None --dst_path ./workspace_llama13b --tp 1
# bash界面运行
lmdeploy chat turbomind --model_path ./workspace_llama13b --tp 1
# 服务器网页端运行
在bash端运行:
lmdeploy serve gradio --model_path_or_server ./workspace_llama13b --server_name {ip} --server_port {pord} --batch_size 32 --tp 1 --restful_api False
在网页上输入{ip}:{pord}即可进行对话
```
### 运行 LLama-33b
```
# 模型转换
lmdeploy convert --model_name llama --model_path /path/to/model --model_format hf --tokenizer_path None --dst_path ./workspace_llama33b --tp 4
# bash界面运行
lmdeploy chat turbomind --model_path ./workspace_llama33b --tp 4
# 服务器网页端运行
在bash端运行:
lmdeploy serve gradio --model_path_or_server ./workspace_llama33b --server_name {ip} --server_port {pord} --batch_size 32 --tp 4 --restful_api False
在网页上输入{ip}:{pord}即可进行对话 在网页上输入{ip}:{pord}即可进行对话
``` ```
### 运行 LLama-65b ### 运行 internlm-chat-20b
``` ```
# 模型转换 # 模型转换
lmdeploy convert --model_name llama --model_path /path/to/model --model_format hf --tokenizer_path None --dst_path ./workspace_llama65b --tp 8 lmdeploy convert --model_name internlm-chat-20b --model_path /path/to/model --model_format hf --tokenizer_path None --dst_path ./workspace_interlm20b --tp 4
# bash界面运行 # bash界面运行
lmdeploy chat turbomind --model_path ./workspace_llama65b --tp 8 lmdeploy chat turbomind --model_path ./workspace_interlm20b --tp 4
# 服务器网页端运行 # 服务器网页端运行
在bash端运行: 在bash端运行:
lmdeploy serve gradio --model_path_or_server ./workspace_llama65b --server_name {ip} --server_port {pord} --batch_size 32 --tp 8 --restful_api False lmdeploy serve gradio --model_path_or_server ./workspace_interlm20b --server_name {ip} --server_port {pord} --batch_size 32 --tp 4 --restful_api False
在网页上输入{ip}:{pord}即可进行对话 在网页上输入{ip}:{pord}即可进行对话
``` ```
### 运行 LLama2-7b
```
# 模型转换
lmdeploy convert --model_name llama2 --model_path /path/to/model --model_format hf --tokenizer_path None --dst_path ./workspace_llama2-7b --tp 1
# bash界面运行
lmdeploy chat turbomind --model_path ./workspace_llama2-7b --tp 1
# 服务器网页端运行
在bash端运行:
lmdeploy serve gradio --model_path_or_server ./workspace_llama2-7b --server_name {ip} --server_port {pord} --batch_size 32 --tp 1 --restful_api False
在网页上输入{ip}:{pord}即可进行对话
```
### 运行 LLama2-13b
```
# 模型转换
lmdeploy convert --model_name llama2 --model_path /path/to/model --model_format hf --tokenizer_path None --dst_path ./workspace_llama2-13b --tp 1
# bash界面运行
lmdeploy chat turbomind --model_path ./workspace_llama2-13b --tp 1
# 服务器网页端运行
在bash端运行:
lmdeploy serve gradio --model_path_or_server ./workspace_llama2-13b --server_name {ip} --server_port {pord} --batch_size 32 --tp 1 --restful_api False
在网页上输入{ip}:{pord}即可进行对话
```
### 运行 LLama2-70b
```
# 模型转换
lmdeploy convert --model_name llama2 --model_path /path/to/model --model_format hf --tokenizer_path None --dst_path ./workspace_llama2-70b --tp 8
# bash界面运行
lmdeploy chat turbomind --model_path ./workspace_llama2-70b --tp 8
# 服务器网页端运行
在bash端运行:
lmdeploy serve gradio --model_path_or_server ./workspace_llama2-70b --server_name {ip} --server_port {pord} --batch_size 32 --tp 8 --restful_api False
在网页上输入{ip}:{pord}即可进行对话
```
## result ## result
![qwen推理](docs/llama.gif) ![interlm](docs/interlm.gif)
### 精度 ### 精度
...@@ -196,7 +115,7 @@ lmdeploy serve gradio --model_path_or_server ./workspace_llama2-70b --server_nam ...@@ -196,7 +115,7 @@ lmdeploy serve gradio --model_path_or_server ./workspace_llama2-70b --server_nam
## 源码仓库及问题反馈 ## 源码仓库及问题反馈
https://developer.hpccube.com/codes/modelzoo/llama_lmdeploy https://developer.hpccube.com/codes/modelzoo/internlm_lmdeploy
## 参考资料 ## 参考资料
https://github.com/InternLM/LMDeploy https://github.com/InternLM/LMDeploy
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