---
title: Chinese-llama2-CLAM-7b
canonical_url: "https://www.modelscope.cn/models/szdex/Chinese-llama2-CLAM-7b"
md_url: "https://www.modelscope.cn/models/szdex/Chinese-llama2-CLAM-7b.md"
repository: szdex/Chinese-llama2-CLAM-7b
last_updated: 2023-08-14
license: "Apache License 2.0"
pipeline_tag: text-generation
tasks:
  - text-generation
model_type:
  - llama
architectures:
  - LlamaForCausalLM
library_name:
  - pytorch
  - transformer
frameworks:
  - pytorch
language:
  - zh
inference_backends:
  - "deploy_task text/emb"
  - "lmdeploy 0.9.1"
  - "lmdeploy_turbomind 0.9.1"
  - "sglang 0.5.2"
  - "vllm 0.9.2"
downloads: 161
stars: 3
tags:
  - text-generation-inference
---

# Chinese-llama2-CLAM-7b

> Chinese-llama2-CLAM-7b - szdex 在 ModelScope 开源的模型。近日，为促进国产AI领域的发展，开放群岛开源社区宣布成立大模型SIG发起单位之一，北京晴数智慧科技有限公司Magic Data的发布了基于其自研数据集微调的语言模型Chinese-llama2-CLAM-7b项目。项目包含：1. 自研的中文 SFT 数据集 MagicData-CLAM 2. 使用该自研数据集微调的语言模型 Chinese-llama2-CLAM-7b 3. 使用开源的中文指令数据集微调的对比模型…

szdex/Chinese-llama2-CLAM-7b 是 ModelScope 魔搭社区上的text-generation模型，采用 Apache License 2.0 许可，可用 deploy_task text/emb、lmdeploy 0.9.1、lmdeploy_turbomind 0.9.1 部署。

- **Repository**: szdex/Chinese-llama2-CLAM-7b
- **License**: Apache License 2.0
- **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**: text-generation-inference
- **Downloads**: 161
- **Stars**: 3
- **Last updated**: 2023-08-14

Source: https://www.modelscope.cn/models/szdex/Chinese-llama2-CLAM-7b

---

# 关于开放群岛开源社区大模型SIG
* 开放群岛开源社区联合发起成立了大模型SIG，首批发起单位包括智谱AI、百度、阿里魔搭社区、华为昇思社区、腾讯云、启智社区等26家单位，旨在以大模型为中间键件，实现数据要素和算力资源的高效配置。大模型SIG首批发起单位汇集了算力提供方、训练数据提供方、大模型厂商、行业应用方以及第三方法律服务机构，以“高性能模型底座+高质量垂直行业数据”双轮驱动的方式，最大程度发挥数据要素的行业应用价值。未来，大模型SIG会持续推动高质量科研数据、行业公共数据合规有序流通，以大模型为核心技术底座，赋能千行百业AI+应用。
* 本项目旨在介绍开放群岛开源社区首批发起单位之一北京晴数智慧科技有限公司基于其自研的中文 SFT 数据集 MagicData-CLAM微调的llama2模型。

### 模型推理

* 单卡加载一个模型需要15G显存。
* 本地测试环境：py310-torch1.13.1-cuda11.6-cudnn8

#### Web Demo

我们使用 [text-generation-webui](https://github.com/oobabooga/text-generation-webui/tree/main) 开源项目搭建的 demo 进行推理，得到文档中的对比样例。该demo支持在网页端切换模型、调整多种常见参数等。

实验环境：py310-torch1.13.1-cuda11.6-cudnn8

```
git clone https://github.com/oobabooga/text-generation-webui.git
cd text-generation-webui
pip install -r requirements.txt

# 建议使用软链接将模型绝对路径链至 `./models`。也可以直接拷贝进去。
ln -s ${model_dir_absolute_path} models/${model_name}

# 启动服务
python server.py --model ${model_name} --listen --listen-host 0.0.0.0 --listen-port ${port}
```
如果服务正常启动，就可以通过该端口访问服务了 `${server_ip}:${port}`

#### Inference script

See https://github.com/magichub-opensource/CLAM-Conversational-Language-AI-from-MagicData/blob/master/inference.py

```
import os,sys,argparse
# os.environ['CUDA_VISIBLE_DEVICES'] = '1'
import torch
import re
import transformers
from transformers import AutoModelForCausalLM, AutoTokenizer

# modelpath = 'models/Chinese-llama2-CLAM-7b' # local path
modelpath = 'MagicHub/Chinese-llama2-CLAM-7b' # huggingface repo

print(f'model path: {modelpath}')
model = AutoModelForCausalLM.from_pretrained(modelpath, device_map="cuda:0", torch_dtype=torch.float16)
tokenizer = AutoTokenizer.from_pretrained(modelpath, use_fast=False)

prompt = "歌剧和京剧的区别是什么？\n"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda:0")
generate_ids = model.generate(
        inputs.input_ids, do_sample=True, max_new_tokens=1024, top_k=10, top_p=0.1, temperature=0.5, repetition_penalty=1.18,
        eos_token_id=2, bos_token_id=1, pad_token_id=0, typical_p=1.0,encoder_repetition_penalty=1,
        )
response = tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
cleaned_response = re.sub('^'+prompt,'', response)
print(f'输入：\n{prompt}\n')
print(f"输出：\n{cleaned_response}\n")
```
### 版权信息

* 数据集来源于开放群岛开源社区发起单位之一北京晴数智慧科技有限公司自研的中文 SFT 数据集 MagicData-CLAM。
* 模型来源于Meta开源的llama2。
* 使用模型需要遵循llama2的开源协议。
* 如有违反相关条款，随时联系m我们删除。
