---
title: chinese-alpaca-plus-13b-hf
canonical_url: "https://www.modelscope.cn/models/AI-ModelScope/chinese-alpaca-plus-13b-hf"
md_url: "https://www.modelscope.cn/models/AI-ModelScope/chinese-alpaca-plus-13b-hf.md"
repository: AI-ModelScope/chinese-alpaca-plus-13b-hf
last_updated: 2023-08-09
license: other
pipeline_tag: text-generation
tasks:
  - text-generation
model_type:
  - llama
architectures:
  - LlamaForCausalLM
library_name:
  - pytorch
  - transformer
frameworks:
  - pytorch
language:
  - ch
domain:
  - nlp
inference_backends:
  - "deploy_task text/emb"
  - "lmdeploy 0.9.1"
  - "lmdeploy_turbomind 0.9.1"
  - "sglang 0.5.2"
  - "vllm 0.9.2"
downloads: 207
stars: 2
tags:
  - transformer
  - LLM
  - ChatGPT
  - generation
---

# chinese-alpaca-plus-13b-hf

> chinese-alpaca-plus-13b-hf - AI-ModelScope 在 ModelScope 开源的模型。Chinese Alpaca Plus 13B Model

AI-ModelScope/chinese-alpaca-plus-13b-hf 是 ModelScope 魔搭社区上的text-generation模型，采用 other 许可，可用 deploy_task text/emb、lmdeploy 0.9.1、lmdeploy_turbomind 0.9.1 部署。

- **Repository**: AI-ModelScope/chinese-alpaca-plus-13b-hf
- **License**: other
- **Tasks**: text-generation
- **Inference backends**: deploy_task text/emb, lmdeploy 0.9.1, lmdeploy_turbomind 0.9.1, sglang 0.5.2, vllm 0.9.2
- **Tags**: transformer, LLM, ChatGPT, generation
- **Downloads**: 207
- **Stars**: 2
- **Last updated**: 2023-08-09

Source: https://www.modelscope.cn/models/AI-ModelScope/chinese-alpaca-plus-13b-hf

---

# Chinese Alpaca Plus 13B Model

**发布中文LLaMA-Plus, Alpaca-Plus 13B版本模型**

发布中文LLaMA-Plus, Alpaca-Plus 13B版本，改进点如下：

- 相比基础版进一步扩充了训练数据，其中LLaMA扩充至120G文本，Alpaca扩充至4.3M指令数据，重点增加了科学领域数据，涵盖：物理、化学、生物、医学、地球科学等
- Alpaca训练时采用了更大的rank，相比基础版具有更低的验证集损失
- Alpaca评测结果：13B获得74.3分，Plus-7B获得78.2分，Plus-13B获得80.8分，具体评测结果请参考[效果评测](https://github.com/ymcui/Chinese-LLaMA-Alpaca/blob/main/examples)
- 多轮回复长度相比旧模型提升明显（可适当增大温度系数）
- 知识问答、写作、翻译等方面效果显著提升

本模型是 [decapoda-research/llama-13b-hf](https://huggingface.co/decapoda-research/llama-13b-hf) 
底座模型 合并 [ziqingyang/chinese-llama-plus-lora-13b](https://huggingface.co/ziqingyang/chinese-llama-plus-lora-13b) 
和 [ziqingyang/chinese-alpaca-plus-lora-13b](https://huggingface.co/ziqingyang/chinese-alpaca-plus-lora-13b) 两个LoRA权重，
并转化为HuggingFace版本权重（.bin文件），可以直接使用或者继续训练。



test case:

|input_text|predict|
|:-- |:--- |
|为什么天空是蓝色的？|天空是蓝色的是因为大气中的气体分子散射了太阳光中的短波长蓝光，使得我们看到的天空呈现出蓝色。|

## release model weight

- chinese-llama-plus-7b 模型权重链接：https://huggingface.co/minlik/chinese-llama-plus-7b-merged
- chinese-alpaca-plus-7b 模型权重链接：https://huggingface.co/shibing624/chinese-alpaca-plus-7b-hf
- chinese-llama-plus-13b 模型权重链接：https://huggingface.co/shibing624/chinese-llama-plus-13b-hf
- chinese-aplaca-plus-13b 模型权重链接：https://huggingface.co/shibing624/chinese-alpaca-plus-13b-hf

## Usage

本项目开源在textgen项目：[textgen](https://github.com/shibing624/textgen)，可支持llama模型，通过如下命令调用：

Install package:
```shell
pip install -U textgen
```

```python
from textgen import LlamaModel
model = LlamaModel("llama", "shibing624/chinese-alpaca-plus-13b-hf")
r = model.predict(["用一句话描述地球为什么是独一无二的。"])
print(r) # ['地球是独一无二的，因为它拥有独特的大气层、水循环、生物多样性以及其他自然资源，这些都使它成为一个独特的生命支持系统。']
```

## Usage (HuggingFace Transformers)
Without [textgen](https://github.com/shibing624/textgen), you can use the model like this: 

First, you pass your input through the transformer model, then you get the generated sentence.

Install package:
```
pip install sentencepiece
pip install transformers>=4.28.0
```

```python
import torch
import transformers
from transformers import LlamaTokenizer, LlamaForCausalLM

def generate_prompt(text):
    return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.

### Instruction:
{text}

### Response:"""


tokenizer = LlamaTokenizer.from_pretrained('shibing624/chinese-alpaca-plus-13b-hf')
model = LlamaForCausalLM.from_pretrained('shibing624/chinese-alpaca-plus-13b-hf').half().cuda()
model.eval()

text = '为什么天空是蓝色的？'
prompt = generate_prompt(text)
input_ids = tokenizer.encode(prompt, return_tensors='pt').to('cuda')


with torch.no_grad():
    output_ids = model.generate(
        input_ids=input_ids,
        max_new_tokens=128,
        temperature=1,
        top_k=40,
        top_p=0.9,
        repetition_penalty=1.15
    ).cuda()
output = tokenizer.decode(output_ids[0], skip_special_tokens=True)
print(output.replace(text, '').strip())
```


output:
```shell
为什么天空是蓝色的？
天空是蓝色的是因为大气中的气体分子散射了太阳光中的短波长蓝光，使得我们看到的天空呈现出蓝色。
```

## 示例代码
```python
from modelscope.utils.constant import Tasks
from modelscope.pipelines import pipeline
pipe = pipeline(task=Tasks.text_generation, model='AI-ModelScope/chinese-alpaca-plus-13b-hf', model_revision='v1.0.0', device_map='auto')
inputs="请猜一猜: 我闻起来很香，但吃起来却很辣。是什么?"
result = pipe(inputs, max_new_tokens=128, temperature=0.4, top_k=20, top_p=0.8, repetition_penalty=2.0, do_sample=True)
print(result['text'])
```

## 模型来源
release合并后的模型权重，一步到位直接使用，省电、减少碳排放。


基于 [多LoRA权重合并（适用于Chinese-Alpaca-Plus ）](https://github.com/ymcui/Chinese-LLaMA-Alpaca/wiki/%E6%89%8B%E5%8A%A8%E6%A8%A1%E5%9E%8B%E5%90%88%E5%B9%B6%E4%B8%8E%E8%BD%AC%E6%8D%A2#%E5%A4%9Alora%E6%9D%83%E9%87%8D%E5%90%88%E5%B9%B6%E9%80%82%E7%94%A8%E4%BA%8Echinese-alpaca-plus)方法手动合并而成，具体是使用 [decapoda-research/llama-13b-hf](https://huggingface.co/decapoda-research/llama-13b-hf) 
底座模型 合并 [ziqingyang/chinese-llama-plus-lora-13b](https://huggingface.co/ziqingyang/chinese-llama-plus-lora-13b) 和 [ziqingyang/chinese-alpaca-plus-lora-13b](https://huggingface.co/ziqingyang/chinese-alpaca-plus-lora-13b) 两个LoRA权重 得到，并转化为HuggingFace版本权重（.bin文件）。

HuggingFace版本权重（.bin文件）可用于：
- 使用Transformers进行训练和推理
- 使用text-generation-webui搭建界面

PyTorch版本权重（.pth文件）可用于：
- 使用llama.cpp工具进行量化和部署

PyTorch版本权重（.pth文件）链接：[shibing624/chinese-alpaca-plus-13b-pth](https://huggingface.co/shibing624/chinese-alpaca-plus-13b-pth)

模型文件组成：
```
chinese-alpaca-plus-13b-hf
|-- config.json
|-- generation_config.json
|-- LICENSE
|-- pytorch_model-00001-of-00003.bin
|-- pytorch_model-00002-of-00003.bin
|-- pytorch_model-00003-of-00003.bin
|-- pytorch_model.bin.index.json
|-- README.md
|-- special_tokens_map.json
|-- tokenizer_config.json
`-- tokenizer.model
```

硬件要求：25G显存

### 微调数据集
我整理部分公开微调数据集：

1. 50万条中文ChatGPT指令Belle数据集：[BelleGroup/train_0.5M_CN](https://huggingface.co/datasets/BelleGroup/train_0.5M_CN)
2. 100万条中文ChatGPT指令Belle数据集：[BelleGroup/train_1M_CN](https://huggingface.co/datasets/BelleGroup/train_1M_CN)
3. 5万条英文ChatGPT指令Alpaca数据集：[50k English Stanford Alpaca dataset](https://github.com/tatsu-lab/stanford_alpaca#data-release)
4. 5万条中文GPT4指令Alpaca数据集：[shibing624/alpaca-zh](https://huggingface.co/datasets/shibing624/alpaca-zh)
5. 69万条中文指令Guanaco数据集(Belle50万条+Guanaco19万条)：[Chinese-Vicuna/guanaco_belle_merge_v1.0](https://huggingface.co/datasets/Chinese-Vicuna/guanaco_belle_merge_v1.0)


如果需要训练LLaMA模型，请参考[https://github.com/shibing624/textgen](https://github.com/shibing624/textgen)


## Citation

```latex
@software{textgen,
  author = {Xu Ming},
  title = {textgen: Implementation of language model finetune},
  year = {2023},
  url = {https://github.com/shibing624/textgen},
}
```


## Reference
- https://github.com/ymcui/Chinese-LLaMA-Alpaca
