Skip to content

TigerResearch/TigerBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TigerBot

Tiger

最近更新

目录

环境安装

conda create --name tigerbot python=3.8
conda activate tigerbot
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia

git clone https://github.com/TigerResearch/TigerBot
cd TigerBot
pip install -r requirements.txt

模型下载

Tigerbot-7B
Tigerbot-7B Bits memory(GB)
Tigerbot-7B-base 16 17.2
Tigerbot-7B-sft 16 17.2
Tigerbot-7B-sft-int4 4 8.5
Tigerbot-176B)
Tigerbot-176B Bits memory(GB)
Tigerbot-176B-sft 16 347.6
Tigerbot-176B-sft-int4 4 108.5

训练和推理

预训练

启动训练前安装 DeepSpeed

git clone https://github.com/microsoft/DeepSpeed/
cd DeepSpeed
rm -rf build
TORCH_CUDA_ARCH_LIST="8.0" DS_BUILD_CPU_ADAM=1 DS_BUILD_UTILS=1 pip install . \
--global-option="build_ext" --global-option="-j8" --no-cache -v \
--disable-pip-version-check 2>&1 | tee build.log

TORCH_CUDA_ARCH_LIST 根据你运行的 GPU 架构做调整,获取 TORCH_CUDA_ARCH_LIST

CUDA_VISIBLE_DEVICES=0 python -c "import torch; print(torch.cuda.get_device_capability())"

如果返回的结果是(8, 0),那么 TORCH_CUDA_ARCH_LIST="8.0"

启动训练

deepspeed \
--include="localhost:0,1,2,3" \
./train_clm.py \
--deepspeed ./ds_config/ds_config_zero3.json \
--model_name_or_path ./tigerbot_560m \
--dataset_name TigerResearch/dev_pretrain \
--do_train \
--output_dir ./ckpt-clm \
--overwrite_output_dir \
--preprocess_num_workers 8 \
--num_train_epochs 5 \
--learning_rate 1e-5 \
--evaluation_strategy steps \
--eval_steps 10 \
--bf16 True \
--save_strategy steps \
--save_steps 10 \
--save_total_limit 2 \
--logging_steps 10 \
--tf32 True \
--per_device_train_batch_size 2 \
--per_device_eval_batch_size 2

微调

启动训练

deepspeed \
--include="localhost:0,1,2,3" \
./train_sft.py \
--deepspeed ./ds_config/ds_config_zero3.json \
--model_name_or_path ./tigerbot_560m \
--dataset_name TigerResearch/dev_sft \
--do_train \
--output_dir ./ckpt-sft \
--overwrite_output_dir \
--preprocess_num_workers 8 \
--num_train_epochs 5 \
--learning_rate 1e-5 \
--evaluation_strategy steps \
--eval_steps 10 \
--bf16 True \
--save_strategy steps \
--save_steps 10 \
--save_total_limit 2 \
--logging_steps 10 \
--tf32 True \
--per_device_train_batch_size 2 \
--per_device_eval_batch_size 2

推理

单卡推理

CUDA_VISIBLE_DEVICES=0 python infer.py --model_path ${MODEL_DIR}

多卡推理

CUDA_VISIBLE_DEVICES=0,1,2,3 python infer.py --model_path ${MODEL_DIR}

量化

我们使用GPTQ算法和GPTQ-for-LLaMa实现量化:

切换到 gptq 目录

cd gptq

模型量化

CUDA_VISIBLE_DEVICES=0 python tigerbot.py ${MODEL_DIR} c4 --wbits 4 --act-order --groupsize 128 --save tigerbot-4bit-128g.pt

量化模型单卡推理

CUDA_VISIBLE_DEVICES=0 python tigerbot_infer.py ${MODEL_DIR} --wbits 4 --groupsize 128 --load tigerbot-4bit-128g.pt

量化模型多卡推理

CUDA_VISIBLE_DEVICES=0,1 python tigerbot_infer.py ${MODEL_DIR} --wbits 4 --groupsize 128 --load tigerbot-4bit-128g.pt

开源数据集

预训练数据

Tiger

  • 中文书籍及代码细分:

中文书籍分类代码语言

微调数据

数据搜集

  • 模型中使用的微调数据的搜集思想如下:

    a. 参考 Alpaca,扩充中英文 seed_tasks,增加一些中文习惯种子问题,基于此生成 2m 中文(本次开源 0.5m)及 0.1m(本次开源 50k)

    b. 基于人工写题及答案、网络搜集方式,整理加工问答集数据,在开源列表中标识为[自研]部分,本次开放部分数据

    c. 基于各类公开数据集转换清洗,其中[自研*]部分,表示基于原始数据进行二次开发后得到,[开源]部分数据集一般原始数据即为较规整的问答数据,进行简单清洗得到

数据开源

领域数据

测评

在 7 项 NLP 任务上进行模型测评,以 OpenAI-InstructGPT-6B-SFT 为基准,归一化并平均各模型的得分,结果如下:

image

API

TigerBot 提供了三种 API,包括 Chat-API,Plug-ins,Fine-Tunes。

调用示例

import requests

url = "https://api.tigerbot.com/bot-service/ft/call"

headers = {
  'Authorization': 'Bearer ' + API_KEY
}
payload = {
  'ftId': 'Your ftId',
  'text': '将以下中文翻译为英文:对此美国的政策制定者目前陷入了困境:一方面要促进增长,另一方面又得降低总债务水平'
}

response = requests.post(url, headers=headers, json=payload)

print(response.text)
{
  "code": 200,
  "msg": "操作成功",
  "data": {
    "result": [
      "The dilemma facing US policymakers is how to stimulate growth while lowering the level of total debt."
    ]
  }
}

使用 API,需先在 TigerBot 平台上进行申请,申请通过后获取 API_KEY,即可快速训练体验

Chat-API 为 TigerBot 对外提供的可直接使用的 api,支持 Tigerbot-7B 和 Tigerbot-180B 两种模型的选择

  • Rethink

    TigerBot 提供的自研插件,可直接通过 api 进行调用

  • Custom Rethink

    用户管理自己的数据,训练自己的插件

无需代码,仅需按照数据要求管理上传自己的数据,即可快速训练出基于 TigerBot 大模型能力基础的自己的模型

Chat 案例 【完整案例

image


image


image


image


image


image

平台

产品链接

https://www.tigerbot.com

联系电话

021-63888086

联系邮箱

cong.fu@tigerobo.com

wei.cai@tigerobo.com

企业微信

Tiger

Releases

No releases published

Packages

No packages published

Languages