Commit 7ec49b9d authored by Rayyyyy's avatar Rayyyyy
Browse files

update readme

parent 056ecba5
......@@ -82,7 +82,7 @@ pip install mmengine==0.10.3
## 训练
### xtuner微调方法
1. 下载预训练模型,具体模型请修改 `download_models.py`
1. 下载预训练模型,具体模型请修改`download_models.py`
```bash
cd /your_code_path/llama3_pytorch
pip install modelscope
......@@ -90,7 +90,7 @@ python download_models.py
mv ~/.cache/modelscope/hub/LLM-Research ./
```
2. 修改[llama3_8b_instruct_qlora_alpaca_e3_M.py](./llama3_8b_instruct_qlora_alpaca_e3_M.py)代码中的`pretrained_model_name_or_path``data_path`为本地对应数据地址;
3. 根据硬件环境和自身训练需求来调整 `max_length``batch_size``accumulative_counts``max_epochs``lr``save_steps``evaluation_freq`、model.lora中的`r``lora_alpha`参数,默认参数支持4*32G;
3. 根据硬件环境和自身训练需求来调整`max_length``batch_size``accumulative_counts``max_epochs``lr``save_steps``evaluation_freq`、model.lora中的`r``lora_alpha`参数,默认参数支持4*32G;
4. ${DCU_NUM}参数修改为要使用的DCU卡数量,不同数据集需要修改llama3_8b_instruct_qlora_alpaca_e3_M.py中`SYSTEM``evaluation_inputs``dataset_map_fn``train_dataloader.sampler``train_cfg`参数设置,详情请参考代码注释项,当前默认alpaca数据集。
5. 执行
```bash
......@@ -116,7 +116,7 @@ NPROC_PER_NODE=${DCU_NUM} xtuner train ./llama3_8b_instruct_qlora_alpaca_e3_M.py
### Pretrained模型
这些模型都没有针对聊天或者Q&A进行微调。可以参考`example_text_completion.py`里的用例。
- Meta-Llama-3-8B 模型示例,Meta-Llama-3-70B模型仅需替换--ckpt_dir、--tokenizer_path对应模型地址即可。
- Meta-Llama-3-8B 模型示例,Meta-Llama-3-70B模型仅需替换–-nproc_per_node、--ckpt_dir、--tokenizer_path对应模型地址即可。
```bash
torchrun --nproc_per_node 1 example_text_completion.py \
--ckpt_dir Meta-Llama-3-8B/original/ \
......@@ -126,14 +126,14 @@ torchrun --nproc_per_node 1 example_text_completion.py \
### Instruction-tuned模型
经过微调的模型被训练用于对话应用程序。为了获得模型的预期特性和性能,需要遵循 [`ChatFormat`](llama/tokenizer.py#L202)中定义的特定格式:
- 提示以特殊令牌 <|begin_of_text|> 开始,之后跟随一个或多个消息。
- 每条消息以标签`<|start_header_id|>`开始,角色为`system``user`或者`assistant`、并以标签 `<|end_header_id|>` 结束。
- 提示以特殊令牌`<|begin_of_text|>`开始,之后跟随一个或多个消息。
- 每条消息以标签`<|start_header_id|>`开始,角色为`system``user`或者`assistant`、并以标签`<|end_header_id|>`结束。
- 在双换行符`\n\n`之后,消息的内容随之而来。
- 每条消息的结尾由`<|eot_id|>`令牌标记。
您还可以部署额外的分类器来过滤被认为不安全的输入和输出。有关如何向推理代码的输入和输出添加安全检查器,请参阅[llama-recipes repo](https://github.com/meta-llama/llama-recipes/blob/main/recipes/inference/local_inference/inference.py)
- Meta-Llama-3-8B-Instruct 模型示例,Meta-Llama-3-70B-Instruct模型仅需替换--ckpt_dir、--tokenizer_path对应模型地址即可。
- Meta-Llama-3-8B-Instruct 模型示例,Meta-Llama-3-70B-Instruct模型仅需替换–-nproc_per_node、--ckpt_dir、--tokenizer_path对应模型地址即可。
```bash
torchrun --nproc_per_node 1 example_chat_completion.py \
--ckpt_dir Meta-Llama-3-8B-Instruct/original/ \
......@@ -143,14 +143,14 @@ torchrun --nproc_per_node 1 example_chat_completion.py \
## 多轮对话
1. 确认环境安装及模型下载完毕;
2. 修改[chat.sh](./chat.sh)文件中的 `--ckpt_dir``--tokenizer_path` 参数为本地模型地址,`--max_seq_len` 根据自身需求进行修改,调整该值可以增加多轮对话模型的记忆长度,不过需要注意的是这可能会增加模型运算的时间和内存需求;
2. 修改[chat.sh](./chat.sh)文件中的`--ckpt_dir``--tokenizer_path`参数为本地模型地址,`--max_seq_len`根据自身需求进行修改,调整该值可以增加多轮对话模型的记忆长度,不过需要注意的是这可能会增加模型运算的时间和内存需求;
3. 执行:
```bash
bash chat.sh
```
## Evaluation
1. 安装 `llama-recipes``lm-eval`
1. 安装`llama-recipes``lm-eval`
```bash
# llama-recipes 下载
git clone https://github.com/meta-llama/llama-recipes.git
......@@ -172,7 +172,7 @@ pip install -e .
cd ../
```
2. 修改待测模型**pretrained**参数地址,例如 `/home/Meta-Llama-3-8B-Instruct`,特别地,当前仅支持`hellaswag`数据集进行测试验证。执行以下命令:
2. 修改待测模型**pretrained**参数地址,例如`/home/Meta-Llama-3-8B-Instruct`,特别地,当前仅支持`hellaswag`数据集进行测试验证。执行以下命令:
```bash
cd /path_of/llama-recipes/recipes/evaluation
python eval.py --model hf --model_args pretrained=/home/llama3/Meta-Llama-3-8B-Instruct,dtype="float" --tasks hellaswag --device cuda --batch_size 8
......@@ -195,7 +195,6 @@ python eval.py --model hf --model_args pretrained=/home/llama3/Meta-Llama-3-8B-I
### 精度
暂无
## 应用场景
### 算法类别
对话问答
......@@ -238,19 +237,47 @@ huggingface-cli download meta-llama/Meta-Llama-3-70B-Instruct --include "origina
模型目录结构如下:
```bash
├── llama3_pytorch
├── model_save_path
│ ├── Meta-Llama-3-8B
── original
── original
│ ├── consolidated.00.pth
│ ├── params.json
│ └── tokenizer.model
│ ├── config.json
│ ├── configuration.json
│ ├── generation_config.json
│ ├── LICENSE
│ ├── model-00001-of-00004.safetensors
│ ├── model-00002-of-00004.safetensors
│ ├── model-00003-of-00004.safetensors
│ ├── model-00004-of-00004.safetensors
│ ├── model.safetensors.index.json
│ ├── README.md
│ ├── special_tokens_map.json
│ ├── tokenizer_config.json
│ ├── tokenizer.json
│ └── USE_POLICY.md
│ ├── Meta-Llama-3-8B-Instruct
── original
── original
│ ├── consolidated.00.pth
│ ├── params.json
│ └── tokenizer.model
│ ├── config.json
│ ├── configuration.json
│ ├── generation_config.json
│ ├── LICENSE
│ ├── model-00001-of-00004.safetensors
│ ├── model-00002-of-00004.safetensors
│ ├── model-00003-of-00004.safetensors
│ ├── model-00004-of-00004.safetensors
│ ├── model.safetensors.index.json
│ ├── README.md
│ ├── special_tokens_map.json
│ ├── tokenizer_config.json
│ ├── tokenizer.json
│ └── USE_POLICY.md
│ ├── Meta-Llama-3-70B
── original
── original
│ ├── consolidated.00.pth
│ ├── consolidated.01.pth
│ ├── consolidated.02.pth
......@@ -261,8 +288,23 @@ huggingface-cli download meta-llama/Meta-Llama-3-70B-Instruct --include "origina
│ ├── consolidated.07.pth
│ ├── params.json
│ └── tokenizer.model
│ ├── config.json
│ ├── generation_config.json
│ ├── LICENSE
│ ├── README.md
│ ├── model-00001-of-00030.safetensors
│ ├── model-00002-of-00030.safetensors
│ ...
│ ├── model-000029-of-00030.safetensors
│ ├── model-000030-of-00030.safetensors
│ ├── model.safetensors.index.json
│ ├── tokenizer_config.json
│ ├── tokenizer.json
│ ├── tokenizer_config.json
│ ├── special_tokens_map.json
│ └── USE_POLICY.md
│ └── Meta-Llama-3-70B-Instruct
── original
── original
│ ├── consolidated.00.pth
│ ├── consolidated.01.pth
│ ├── consolidated.02.pth
......@@ -273,6 +315,21 @@ huggingface-cli download meta-llama/Meta-Llama-3-70B-Instruct --include "origina
│ ├── consolidated.07.pth
│ ├── params.json
│ └── tokenizer.model
│ ├── config.json
│ ├── generation_config.json
│ ├── LICENSE
│ ├── README.md
│ ├── model-00001-of-00030.safetensors
│ ├── model-00002-of-00030.safetensors
│ ...
│ ├── model-000029-of-00030.safetensors
│ ├── model-000030-of-00030.safetensors
│ ├── model.safetensors.index.json
│ ├── tokenizer_config.json
│ ├── tokenizer.json
│ ├── tokenizer_config.json
│ ├── special_tokens_map.json
│ └── USE_POLICY.md
```
## 源码仓库及问题反馈
......
from modelscope import snapshot_download
model_dir = snapshot_download('LLM-Research/Meta-Llama-3-8B-Instruct')
print(model_dir)
\ No newline at end of file
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