Commit d66a6886 authored by xiabo's avatar xiabo
Browse files

Update README.md

parent 12a155e5
# LLama_lmdeploy
# Baichuan_lmdeploy
## 论文
- [https://arxiv.org/pdf/2302.13971.pdf](https://arxiv.org/pdf/2302.13971.pdf)
## 模型结构
LLAMA网络基于 Transformer 架构。提出了各种改进,并用于不同的模型,例如 PaLM。以下是与原始架构的主要区别:
预归一化。为了提高训练稳定性,对每个transformer 子层的输入进行归一化,而不是对输出进行归一化。使用 RMSNorm 归一化函数。
SwiGLU 激活函数 [PaLM]。使用 SwiGLU 激活函数替换 ReLU 非线性以提高性能。使用 2 /3 4d 的维度而不是 PaLM 中的 4d。
旋转嵌入。移除了绝对位置嵌入,而是添加了旋转位置嵌入 (RoPE),在网络的每一层。
Baichuan系列模型是由百川智能开发的开源大规模预训练模型,包含7B和13B等规模。其中,Baichuan-7B在大约1.2万亿tokens上训练的70亿参数模型,支持中英双语,上下文窗口长度为4096。Baichuan-13B是由百川智能继Baichuan-7B之后开发的包含130亿参数模型,它在高质量的语料上训练了1.4万亿tokens,超过LLaMA-13B 40%,是当前开源 13B 尺寸下训练数据量最多的模型。此外,百川智能还发布了对齐模型(Baichuan-13B-Chat),具有很强的对话能力。
模型具体参数:
| 模型名称 | 隐含层维度 | 层数 | 头数 | 词表大小 | 总参数量 | 训练数据(tokens) | 位置编码 | 最大长 |
| -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
| Baichuan-7B | 4,096 | 32 | 32 | 64,000 | 7,000,559,616 | 1.2万亿 | RoPE | 4096 |
| Baichuan-13B | 5,120 | 40 | 40 | 64,000 | 13,264,901,120 | 1.4万亿 | ALiBi | 4096 |
![img](./docs/llama.png)
![img](./docs/baichuan.jpg)
## 算法原理
LLama是一个基础语言模型的集合,参数范围从7B到65B。在数万亿的tokens上训练出的模型,并表明可以专门使用公开可用的数据集来训练最先进的模型,而不依赖于专有的和不可访问的数据集。
Baichuan整体模型基于标准的Transformer结构,采用了和LLaMA一样的模型设计。其中,Baichuan-7B在结构上采用Rotary Embedding位置编码方案、SwiGLU激活函数、基于RMSNorm的Pre-Normalization。Baichuan-13B使用了ALiBi线性偏置技术,相对于Rotary Embedding计算量更小,对推理性能有显著提升。
![img](./docs/baichuan.png)
![img](./docs/llama_1.png)
## 环境配置
......@@ -47,11 +52,12 @@ cd .. && python3 setup.py install
```
### 模型下载
[LLama](https://huggingface.co/meta-llama)
[baichuan-7b](https://huggingface.co/baichuan-inc/Baichuan-7B)
支持模型包括:LLama-7B、LLama-13B、LLama-30B、LLama-65B、LLama2-7B、LLama2-13B、LLama2-70B
[baichuan2-7b-chat](https://huggingface.co/baichuan-inc/Baichuan2-7B-Chat)
### 运行 LLama-7b
### 运行 baichuan-7b
```
# 模型转换
# <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 +67,10 @@ cd .. && python3 setup.py install
# <model_format> 保存输出的目标路径(默认./workspace)
# <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 baichuan-7b --model_path /path/to/model --model_format hf --tokenizer_path None --dst_path ./workspace_baichuan7b --tp 1
# bash界面运行
lmdeploy chat turbomind --model_path ./workspace_llama7b --tp 1 # 输入问题后执行2次回车进行推理
lmdeploy chat turbomind --model_path ./workspace_baichuan7b --tp 1 # 输入问题后执行2次回车进行推理
# 服务器网页端运行
......@@ -76,108 +82,29 @@ lmdeploy chat turbomind --model_path ./workspace_llama7b --tp 1 # 输入问
# <tp> 用于张量并行的GPU数量应该是2^n (和模型转换的时候保持一致)
# <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
在网页上输入{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}即可进行对话
```
### 运行 LLama-65b
```
# 模型转换
lmdeploy convert --model_name llama --model_path /path/to/model --model_format hf --tokenizer_path None --dst_path ./workspace_llama65b --tp 8
# bash界面运行
lmdeploy chat turbomind --model_path ./workspace_llama65b --tp 8
# 服务器网页端运行
在bash端运行:
lmdeploy serve gradio --model_path_or_server ./workspace_llama65b --server_name {ip} --server_port {pord} --batch_size 32 --tp 8 --restful_api False
在网页上输入{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
lmdeploy serve gradio --model_path_or_server ./workspace_baichuan7b --server_name {ip} --server_port {pord} --batch_size 32 --tp 1 --restful_api False
在网页上输入{ip}:{pord}即可进行对话
```
### 运行 LLama2-70b
### 运行 baichuan2-7b
```
# 模型转换
lmdeploy convert --model_name llama2 --model_path /path/to/model --model_format hf --tokenizer_path None --dst_path ./workspace_llama2-70b --tp 8
lmdeploy convert --model_name baichuan2-7b --model_path /path/to/model --model_format hf --tokenizer_path None --dst_path ./workspace_baichuan2-7b --tp 1
# bash界面运行
lmdeploy chat turbomind --model_path ./workspace_llama2-70b --tp 8
lmdeploy chat turbomind --model_path ./workspace_baichuan2-7b --tp 1
# 服务器网页端运行
在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
lmdeploy serve gradio --model_path_or_server ./workspace_baichuan2-7b --server_name {ip} --server_port {pord} --batch_size 32 --tp 1 --restful_api False
在网页上输入{ip}:{pord}即可进行对话
```
## result
![qwen推理](docs/llama.gif)
![baichuan](docs/baichuan.gif)
### 精度
......@@ -192,11 +119,11 @@ 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/baichuan_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