Code Monkey home page Code Monkey logo

yayi2's Introduction

更新

[2024.03.28] 所有模型和数据上传魔搭社区。

[2023.12.22] 我们发布了技术报告🔥🔥🔥YAYI 2: Multilingual Open-Source Large Language Models

介绍

YAYI 2 是中科闻歌研发的新一代开源大语言模型,包括 Base 和 Chat 版本,参数规模为 30B。YAYI2-30B 是基于 Transformer 的大语言模型,采用了超过 2 万亿 Tokens 的高质量、多语言语料进行预训练。针对通用和特定领域的应用场景,我们采用了百万级指令进行微调,同时借助人类反馈强化学习方法,以更好地使模型与人类价值观对齐。

本次开源的模型为 YAYI2-30B Base 模型。我们希望通过雅意大模型的开源来促进中文预训练大模型开源社区的发展,并积极为此做出贡献。通过开源,我们与每一位合作伙伴共同构建雅意大模型生态。

更多技术细节,欢迎阅读我们的技术报告🔥YAYI 2: Multilingual Open-Source Large Language Models

数据集地址

数据集名称 大小 🤗 HF模型标识 下载地址 魔搭模型标识 下载地址
YAYI2 Pretrain Data 500G wenge-research/yayi2_pretrain_data 数据集下载 wenge-research/yayi2_pretrain_data 数据集下载

模型地址

模型名称 上下文长度 🤗 HF模型标识 下载地址 魔搭模型标识 下载地址
YAYI2-30B 4096 wenge-research/yayi2-30b 模型下载 wenge-research/yayi2-30b 模型下载
YAYI2-30B-Chat 4096 wenge-research/yayi2-30b-chat Comming soon...

评测结果

我们在多个基准数据集上进行了评测,包括 C-Eval、MMLU、 CMMLU、AGIEval、GAOKAO-Bench、GSM8K、MATH、BBH、HumanEval 以及 MBPP。我们考察了模型在语言理解、学科知识、数学推理、逻辑推理以及代码生成方面的表现。YAYI 2 模型在与其规模相近的开源模型中展现出了显著的性能提升。

学科知识 数学 逻辑推理 代码
模型 C-Eval(val) MMLU AGIEval CMMLU GAOKAO-Bench GSM8K MATH BBH HumanEval MBPP
5-shot 5-shot 3/0-shot 5-shot 0-shot 8/4-shot 4-shot 3-shot 0-shot 3-shot
MPT-30B - 46.9 33.8 - - 15.2 3.1 38.0 25.0 32.8
Falcon-40B - 55.4 37.0 - - 19.6 5.5 37.1 0.6 29.8
LLaMA2-34B - 62.6 43.4 - - 42.2 6.2 44.1 22.6 33.0
Baichuan2-13B 59.0 59.5 37.4 61.3 45.6 52.6 10.1 49.0 17.1 30.8
Qwen-14B 71.7 67.9 51.9 70.2 62.5 61.6 25.2 53.7 32.3 39.8
InternLM-20B 58.8 62.1 44.6 59.0 45.5 52.6 7.9 52.5 25.6 35.6
Aquila2-34B 98.5 76.0 43.8 78.5 37.8 50.0 17.8 42.5 0.0 41.0
Yi-34B 81.8 76.3 56.5 82.6 68.3 67.6 15.9 66.4 26.2 38.2
YAYI2-30B 80.9 80.5 62.0 84.0 64.4 71.2 14.8 54.5 53.1 45.8

我们使用 OpenCompass Github 仓库 提供的源代码进行了评测。对于对比模型,我们列出了他们在 OpenCompass 榜单上的评测结果,截止日期为 2023年12月15日。对于其他尚未在 OpenCompass 平台参与评测的模型,包括 MPT、Falcon 和 LLaMa 2,我们采用了 LLaMA 2 报告的结果。

推理

我们提供简单的示例来说明如何快速使用 YAYI2-30B 进行推理。该示例可在单张 A100/A800 上运行。

环境安装

  1. 克隆本仓库内容到本地环境
git clone https://github.com/wenge-research/YAYI2.git
cd YAYI2
  1. 创建 conda 虚拟环境
conda create --name yayi_inference_env python=3.8
conda activate yayi_inference_env

请注意,本项目需要 Python 3.8 或更高版本。

  1. 安装依赖
pip install transformers==4.33.1
pip install torch==2.0.1
pip install sentencepiece==0.1.99
pip install accelerate==0.25.0

Base 模型推理代码

>>> from transformers import AutoModelForCausalLM, AutoTokenizer
>>> tokenizer = AutoTokenizer.from_pretrained("wenge-research/yayi2-30b", trust_remote_code=True)
>>> model = AutoModelForCausalLM.from_pretrained("wenge-research/yayi2-30b", device_map="auto", trust_remote_code=True)
>>> inputs = tokenizer('The winter in Beijing is', return_tensors='pt')
>>> inputs = inputs.to('cuda')
>>> pred = model.generate(
        **inputs, 
        max_new_tokens=256, 
        eos_token_id=tokenizer.eos_token_id, 
        do_sample=True,
        repetition_penalty=1.2,
        temperature=0.4, 
        top_k=100, 
        top_p=0.8
        )
>>> print(tokenizer.decode(pred.cpu()[0], skip_special_tokens=True))

当您首次访问时,需要下载并加载模型,可能会花费一些时间。

模型微调

本项目支持基于分布式训练框架 deepspeed 进行指令微调,配置好环境并执行相应脚本即可启动全参数微调或 LoRA 微调。

环境安装

  1. 创建 conda 虚拟环境:
conda create --name yayi_train_env python=3.10
conda activate yayi_train_env
  1. 安装依赖:
pip install -r requirements.txt
  1. 安装 accelerate:
pip install --upgrade accelerate
  1. 安装 flashattention:
pip install flash-attn==2.0.3 --no-build-isolation
pip install triton==2.0.0.dev20221202  --no-deps 

全参训练

  • 数据格式:参考 data/yayi_train_example.json,是一个标准 JSON 文件,每条数据由 "system" "conversations" 组成,其中 "system" 为全局角色设定信息,可为空字符串,"conversations" 是由 human 和 yayi 两种角色交替进行的多轮对话内容。

  • 运行说明:运行以下命令即可开始全参数微调雅意模型,该命令支持多机多卡训练,建议使用 16*A100(80G) 或以上硬件配置。

deepspeed --hostfile config/hostfile \
    --module training.trainer_yayi2 \
    --report_to "tensorboard" \
    --data_path "./data/yayi_train_example.json" \
    --model_name_or_path "your_model_path" \
    --output_dir "./output" \
    --model_max_length 2048 \
    --num_train_epochs 1 \
    --per_device_train_batch_size 1 \
    --gradient_accumulation_steps 1 \
    --evaluation_strategy "no" \
    --save_strategy "steps" \
    --save_steps 500 \
    --save_total_limit 10 \
    --learning_rate 5e-6 \
    --warmup_steps 2000 \
    --lr_scheduler_type cosine \
    --logging_steps 1 \
    --gradient_checkpointing True \
    --deepspeed "./config/deepspeed.json" \
    --bf16 True 

或者通过命令行启动:

bash scripts/start.sh

请注意,如需使用 ChatML 模版进行指令微调,可将命令中的 --module training.trainer_yayi2 修改为 --module training.trainer_chatml;如需或自定义 Chat 模版,可修改 trainer_chatml.py 的 Chat 模版中 system、user、assistant 三种角色的 special token 定义。以下是 ChatML 模版示例,如果训练时使用该模版或自定义模版,推理时也需要保持一致。

<|im_start|>system
You are a helpful and harmless assistant named YAYI.<|im_end|>
<|im_start|>user
Hello!<|im_end|>
<|im_start|>assistant
Hello! How can I assist you today?<|im_end|>
<|im_start|>user
1+1=<|im_end|>
<|im_start|>assistant
1+1 equals 2.<|im_end|>

LoRA 微调

  • 数据格式:同上,参考 data/yayi_train_example_multi_rounds.json。
  • 运行以下命令即可开始 LoRA 微调雅意模型。
bash scripts/start_lora.sh

预训练数据

  • 在预训练阶段,我们不仅使用了互联网数据来训练模型的语言能力,还添加了通用精选数据和领域数据,以增强模型的专业技能。数据分布情况如下: data distribution

  • 我们构建了一套全方位提升数据质量的数据处理流水线,包括标准化、启发式清洗、多级去重、毒性过滤四个模块。我们共收集了 240TB 原始数据,预处理后仅剩 10.6TB 高质量数据。整体流程如下: data process

分词器

  • YAYI 2 采用 Byte-Pair Encoding(BPE)作为分词算法,使用 500GB 高质量多语种语料进行训练,包括汉语、英语、法语、俄语等十余种常用语言,词表大小为 81920。
  • 我们对数字进行逐位拆分,以便进行数学相关推理;同时,在词表中手动添加了大量HTML标识符和常见标点符号,以提高分词的准确性。另外,我们预设了200个保留位,以便未来可能的应用,例如在指令微调阶段添加标识符。由于是字节级别的分词算法,YAYI 2 Tokenizer 可以覆盖未知字符。
  • 我们采样了单条长度为 1万 Tokens 的数据形成评价数据集,涵盖中文、英文和一些常见小语种,并计算了模型的压缩比。

Alt text

  • 压缩比越低通常表示分词器具有更高效率的性能。

Loss 曲线

YAYI 2 模型的 loss 曲线见下图: loss

相关协议

开源协议

本项目中的代码依照 Apache-2.0 协议开源,社区使用 YAYI 2 模型和数据需要遵循《雅意 YAYI 2 模型社区许可协议》。若您需要将雅意 YAYI 2系列模型或其衍生品用作商业用途,请完整填写《雅意 YAYI 2 模型商用登记信息》,并发送至 [email protected],收到邮件后我们将在3个工作日进行审核,通过审核后您将收到商用许可证,请您在使用过程中严格遵守《雅意 YAYI 2 模型商用许可协议》的相关内容,感谢您的配合!

引用

如果您在工作中使用了我们的模型,请引用我们的论文:

@article{YAYI 2,
  author    = {Yin Luo, Qingchao Kong, Nan Xu, et.al.},
  title     = {YAYI 2: Multilingual Open Source Large Language Models},
  journal   = {arXiv preprint arXiv:2312.14862},
  url       = {https://arxiv.org/abs/2312.14862},
  year      = {2023}
}

Star History

Star History Chart

yayi2's People

Contributors

wenge-research avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

yayi2's Issues

Alignment data

你好。Thank you for your work.

Is the SFT dataset available?

It would be great to adopt to different languages.

500GB预训练数据

repo中提供的数据集地址不可访问,请问数据集开源在什么地方呢?

关于能否在4090等消费级显卡运行

求教主要是关于运行设备的几个问题
1个人设备4090显卡,能否运行?
2后续是否会有量化版本的模型或方案?
3个人量化是否支持llama.cpp,或什么方式

'YayiTokenizer' object has no attribute 'sp_model'

运行样例程序时碰到:

Traceback (most recent call last):
  File "/data/model/yayi2-30b/try.py", line 2, in <module>
    tokenizer = AutoTokenizer.from_pretrained("/data/model/yayi2-30b", trust_remote_code=True)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/user23202791/.conda/envs/fastchat/lib/python3.11/site-packages/transformers/models/auto/tokenization_auto.py", line 847, in from_pretrained
    return tokenizer_class.from_pretrained(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/user23202791/.conda/envs/fastchat/lib/python3.11/site-packages/transformers/tokenization_utils_base.py", line 2089, in from_pretrained
    return cls._from_pretrained(
           ^^^^^^^^^^^^^^^^^^^^^
  File "/data/user23202791/.conda/envs/fastchat/lib/python3.11/site-packages/transformers/tokenization_utils_base.py", line 2311, in _from_pretrained
    tokenizer = cls(*init_inputs, **init_kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/user23202791/.cache/huggingface/modules/transformers_modules/yayi2-30b/tokenization_yayi.py", line 74, in __init__
    super().__init__(
  File "/data/user23202791/.conda/envs/fastchat/lib/python3.11/site-packages/transformers/tokenization_utils.py", line 367, in __init__
    self._add_tokens(
  File "/data/user23202791/.conda/envs/fastchat/lib/python3.11/site-packages/transformers/tokenization_utils.py", line 467, in _add_tokens
    current_vocab = self.get_vocab().copy()
                    ^^^^^^^^^^^^^^^^
  File "/data/user23202791/.cache/huggingface/modules/transformers_modules/yayi2-30b/tokenization_yayi.py", line 111, in get_vocab
    vocab = {self.convert_ids_to_tokens(i): i for i in range(self.vocab_size)}
                                                             ^^^^^^^^^^^^^^^
  File "/data/user23202791/.cache/huggingface/modules/transformers_modules/yayi2-30b/tokenization_yayi.py", line 107, in vocab_size
    return self.sp_model.get_piece_size()
           ^^^^^^^^^^^^^
AttributeError: 'YayiTokenizer' object has no attribute 'sp_model'

系统版本:Ubuntu 22.04
包版本如下:

Package                           Version
--------------------------------- ------------
accelerate                        0.30.1
addict                            2.4.0
aiofiles                          23.2.1
aiohttp                           3.9.5
aiosignal                         1.3.1
aliyun-python-sdk-core            2.15.1
aliyun-python-sdk-kms             2.16.3
altair                            5.3.0
annotated-types                   0.6.0
anyio                             4.3.0
asttokens                         2.4.1
attrs                             23.2.0
certifi                           2024.2.2
cffi                              1.16.0
charset-normalizer                3.3.2
click                             8.1.7
cloudpickle                       3.0.0
cmake                             3.29.3
comm                              0.2.2
contourpy                         1.2.1
crcmod                            1.7
cryptography                      42.0.8
cycler                            0.12.1
datasets                          2.18.0
debugpy                           1.6.7
decorator                         5.1.1
dill                              0.3.8
diskcache                         5.6.3
distro                            1.9.0
dnspython                         2.6.1
einops                            0.8.0
email_validator                   2.1.1
exceptiongroup                    1.2.0
executing                         2.0.1
fastapi                           0.111.0
fastapi-cli                       0.0.3
ffmpy                             0.3.2
filelock                          3.14.0
flash-attn                        2.5.8
fonttools                         4.51.0
frozenlist                        1.4.1
fschat                            0.2.36
fsspec                            2024.2.0
gast                              0.5.4
gradio                            4.31.3
gradio_client                     0.16.3
h11                               0.14.0
httpcore                          1.0.5
httptools                         0.6.1
httpx                             0.27.0
huggingface-hub                   0.23.0
idna                              3.7
importlib_metadata                7.1.0
importlib_resources               6.4.0
interegular                       0.3.3
ipykernel                         6.29.4
ipython                           8.25.0
jedi                              0.19.1
Jinja2                            3.1.4
jmespath                          0.10.0
joblib                            1.4.2
jsonschema                        4.22.0
jsonschema-specifications         2023.12.1
jupyter_client                    8.6.2
jupyter_core                      5.7.2
kiwisolver                        1.4.5
lark                              1.1.9
llvmlite                          0.42.0
lm-format-enforcer                0.9.8
markdown-it-py                    3.0.0
markdown2                         2.4.13
MarkupSafe                        2.1.5
matplotlib                        3.9.0
matplotlib-inline                 0.1.7
mdurl                             0.1.2
modelscope                        1.15.0
mpmath                            1.3.0
msgpack                           1.0.8
multidict                         6.0.5
multiprocess                      0.70.16
nest_asyncio                      1.6.0
networkx                          3.3
nh3                               0.2.17
ninja                             1.11.1.1
numba                             0.59.1
numpy                             1.26.4
nvidia-cublas-cu12                12.1.3.1
nvidia-cuda-cupti-cu12            12.1.105
nvidia-cuda-nvrtc-cu12            12.1.105
nvidia-cuda-runtime-cu12          12.1.105
nvidia-cudnn-cu12                 8.9.2.26
nvidia-cufft-cu12                 11.0.2.54
nvidia-curand-cu12                10.3.2.106
nvidia-cusolver-cu12              11.4.5.107
nvidia-cusparse-cu12              12.1.0.106
nvidia-ml-py                      12.550.52
nvidia-nccl-cu12                  2.20.5
nvidia-nvjitlink-cu12             12.4.127
nvidia-nvtx-cu12                  12.1.105
openai                            1.30.1
OpenCC                            1.1.6
orjson                            3.10.3
oss2                              2.18.5
outlines                          0.0.34
packaging                         24.1
pandas                            2.2.2
parso                             0.8.4
peft                              0.10.0
pexpect                           4.9.0
pickleshare                       0.7.5
pillow                            10.3.0
pip                               24.0
platformdirs                      4.2.2
plotly                            5.22.0
prometheus_client                 0.20.0
prometheus-fastapi-instrumentator 7.0.0
prompt-toolkit                    3.0.43
protobuf                          5.26.1
psutil                            5.9.8
ptyprocess                        0.7.0
pure-eval                         0.2.2
py-cpuinfo                        9.0.0
pyarrow                           16.1.0
pyarrow-hotfix                    0.6
pycparser                         2.22
pycryptodome                      3.20.0
pydantic                          2.7.1
pydantic_core                     2.18.2
pydub                             0.25.1
Pygments                          2.18.0
pyparsing                         3.1.2
python-dateutil                   2.9.0.post0
python-dotenv                     1.0.1
python-multipart                  0.0.9
pytz                              2024.1
PyYAML                            6.0.1
pyzmq                             25.1.2
ray                               2.22.0
referencing                       0.35.1
regex                             2024.5.15
requests                          2.31.0
rich                              13.7.1
rpds-py                           0.18.1
ruff                              0.4.4
safetensors                       0.4.3
scipy                             1.13.0
semantic-version                  2.10.0
sentencepiece                     0.2.0
setuptools                        69.5.1
shellingham                       1.5.4
shortuuid                         1.0.13
simplejson                        3.19.2
six                               1.16.0
sniffio                           1.3.1
sortedcontainers                  2.4.0
stack-data                        0.6.2
starlette                         0.37.2
svgwrite                          1.4.3
sympy                             1.12
tenacity                          8.3.0
tiktoken                          0.6.0
tokenizers                        0.19.1
tomli                             2.0.1
tomlkit                           0.12.0
toolz                             0.12.1
torch                             2.3.0
tornado                           6.3.3
tqdm                              4.66.4
traitlets                         5.14.3
transformers                      4.40.2
triton                            2.3.0
typer                             0.12.3
typing_extensions                 4.11.0
tzdata                            2024.1
ujson                             5.10.0
urllib3                           2.2.1
uvicorn                           0.29.0
uvloop                            0.19.0
vllm                              0.4.2
vllm_nccl_cu12                    2.18.1.0.4.0
watchfiles                        0.21.0
wavedrom                          2.0.3.post3
wcwidth                           0.2.13
websockets                        11.0.3
wheel                             0.43.0
xformers                          0.0.26.post1
xxhash                            3.4.1
yapf                              0.40.2
yarl                              1.9.4
zipp                              3.19.2

顺带一提,模型在 https://modelscope.cn/models/wenge-research/yayi2-30b 上下载时其实碰到了下面的问题:

Encountered 6 file(s) that may not have been copied correctly on Windows:
        pytorch_model-00001-of-00007.bin
        pytorch_model-00006-of-00007.bin
        pytorch_model-00004-of-00007.bin
        pytorch_model-00005-of-00007.bin
        pytorch_model-00002-of-00007.bin
        pytorch_model-00003-of-00007.bin

See: `git lfs help smudge` for more details.

不知道是否有影响

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.