英语 | 中文
?拥抱脸•?模型范围•?明智的模型
? 在 GitHub 上提出问题或讨论想法
加入我们?不和谐或微信
查看易科技报告
在易学习中心成长
?在易科技博客学习
? Yi系列模型是01.AI从零开始训练的下一代开源大语言模型。
? Yi系列模型以双语语言模型为目标,在3T多语言语料库上进行训练,成为全球最强的LLM模型之一,在语言理解、常识推理、阅读理解等方面展现出良好的前景。例如,
Yi-34B-Chat 模型在 AlpacaEval 排行榜上排名第二(仅次于 GPT-4 Turbo) ,优于其他 LLM(例如 GPT-4、Mixtral、Claude)(基于截至 2024 年 1 月的可用数据)。
Yi-34B模型在Hugging Face Open LLM Leaderboard(预训练)和C-Eval等各种基准测试中,在所有现有开源模型(如Falcon-180B、Llama-70B、Claude)中英文和中文排名第一(基于截至 2023 年 11 月的可用数据)。
(感谢 Llama)感谢 Transformer 和 Llama 开源社区,因为它们减少了从头开始构建所需的工作量,并支持在 AI 生态系统中使用相同的工具。
长话短说
Yi系列模型采用与Llama相同的模型架构,但不是Llama的衍生品。
Yi和Llama都基于Transformer结构,该结构自2018年以来一直是大型语言模型的标准架构。
Llama 基于 Transformer 架构,凭借其卓越的稳定性、可靠的收敛性和强大的兼容性,已成为大多数最先进开源模型的新基石。这使得 Llama 成为包括 Yi 在内的模型公认的基础框架。
得益于 Transformer 和 Llama 架构,其他模型可以利用它们的强大功能,减少从头开始构建所需的工作量,并能够在其生态系统中使用相同的工具。
然而,Yi 系列模型不是 Llama 的衍生品,因为它们不使用 Llama 的权重。
由于大多数开源模型都采用 Llama 的结构,因此决定模型性能的关键因素是训练数据集、训练管道和训练基础设施。
Yi 以独特且专有的方式进行开发,完全从头开始独立创建了自己的高质量训练数据集、高效的训练管道和强大的训练基础设施。这一努力带来了优异的表现,Yi 系列模型在 2023 年 12 月的 Alpaca 排行榜上排名仅次于 GPT4,并超越 Llama。
[回到顶部⬆️]
Yi-9B-200K
开源并向公众开放。Yi-9B
开源并向公众开放。Yi-9B
在一系列类似规模的开源模型(包括 Mistral-7B、SOLAR-10.7B、Gemma-7B、DeepSeek-Coder-7B-Base-v1.5 等)中脱颖而出,成为表现最佳的模型,尤其擅长代码、数学、常识推理和阅读理解。Yi-VL-34B
和Yi-VL-6B
已开源并向公众开放。Yi-VL-34B
在最新基准测试中在所有现有开源模型中排名第一,包括MMMU和CMMMU(基于截至2024年1月的可用数据)。Yi-34B-Chat
Yi-34B-Chat-4bits
Yi-34B-Chat-8bits
Yi-6B-Chat
Yi-6B-Chat-4bits
Yi-6B-Chat-8bits
您可以在以下位置交互式地尝试其中一些:
Yi-6B-200K
和Yi-34B-200K
开源并向公众开放。Yi-6B
和Yi-34B
已开源并向公众开放。[回到顶部⬆️]
Yi 型号有多种尺寸,可满足不同的用例。您还可以微调 Yi 模型以满足您的特定要求。
如果您想部署 Yi 模型,请确保满足软件和硬件要求。
模型 | 下载 |
---|---|
Yi-34B-聊天 | •?拥抱脸•?模型范围•?明智的模型 |
Yi-34B-聊天-4bits | •?拥抱脸•?模型范围•?明智的模型 |
Yi-34B-聊天-8位 | •?拥抱脸•?模型范围•?明智的模型 |
Yi-6B-聊天 | •?拥抱脸•?模型范围•?明智的模型 |
Yi-6B-聊天-4bits | •?拥抱脸•?模型范围•?明智的模型 |
Yi-6B-聊天-8bits | •?拥抱脸•?模型范围•?明智的模型 |
- 4 位系列模型由 AWQ 量化。
- 8位系列模型通过GPTQ量化
- 所有量化模型的使用门槛都很低,因为它们可以部署在消费级 GPU(例如 3090、4090)上。
模型 | 下载 |
---|---|
翼34B | •?拥抱脸•?模型范围•?明智的模型 |
毅-34B-200K | •?拥抱脸•?模型范围•?明智的模型 |
毅9B | •?拥抱脸•?模型范围•?明智的模型 |
毅9B-200K | •?拥抱脸•?模型范围•?明智的模型 |
伊6B | •?拥抱脸•?模型范围•?明智的模型 |
毅6B-200K | •?拥抱脸•?模型范围•?明智的模型 |
- 200k大约相当于40万个汉字。
- 如果您想使用Yi-34B-200K的旧版本(2023年11月5日发布),请运行git checkout 069cd341d60f4ce4b07ec394e82b79e94f656cf
下载权重。
模型 | 简介 | 默认上下文窗口 | 预训练令牌 | 训练数据日期 |
---|---|---|---|---|
6B系列机型 | 它们适合个人和学术用途。 | 4K | 3T | 截至 2023 年 6 月 |
9B系列机型 | 它是 Yi 系列模型中最擅长编码和数学的。 | Yi-9B是在Yi-6B的基础上持续训练的,使用0.8T token。 | ||
34B系列型号 | 它们适合个人、学术和商业(特别是中小型企业)用途。这是一种经济高效的解决方案,价格实惠且具备应急能力。 | 3T |
对于聊天模型
然而,这种更高的多样性可能会加剧某些现有问题,包括:
[回到顶部⬆️]
提示:如果您想开始使用 Yi 模型并探索不同的推理方法,请查看 Yi Cookbook。
选择以下路径之一,开始您与 Yi 的旅程!
如果您更喜欢在本地部署 Yi 模型,
?♀️并且您有足够的资源(例如NVIDIA A800 80GB),您可以选择以下方法之一:
?♀️并且您的资源有限(例如MacBook Pro),您可以使用llama.cpp。
如果您不想在本地部署 Yi 模型,则可以使用以下任一选项探索 Yi 的功能。
如果你想探索 Yi 的更多特性,可以采用以下方法之一:
Yi API(Yi 官方)
Yi API(复制)
如果您想与 Yi 聊天时使用更多可自定义的选项(例如系统提示、温度、重复惩罚等),您可以尝试以下选项之一:
Yi-34B-Chat-Playground (Yi官方)
Yi-34B-聊天-游乐场(复制)
如果您想与 Yi 聊天,您可以使用以下在线服务之一,它们提供类似的用户体验:
Yi-34B-Chat(抱脸的彝族官方)
Yi-34B-Chat(Yi 官方测试版)
[回到顶部⬆️]
本教程将指导您完成在 A800 (80G) 上本地运行 Yi-34B-Chat然后执行推理的每个步骤。
确保安装了Python 3.10或更高版本。
如果您想运行其他 Yi 型号,请参阅软件和硬件要求。
要设置环境并安装所需的软件包,请执行以下命令。
git clone https://github.com/01-ai/Yi.git
cd yi
pip install -r requirements.txt
您可以从以下来源下载 Yi 模型的权重和分词器:
您可以使用 Yi chat 或基本模型进行推理,如下所示。
创建一个名为quick_start.py
的文件并将以下内容复制到其中。
from transformers import AutoModelForCausalLM , AutoTokenizer
model_path = '<your-model-path>'
tokenizer = AutoTokenizer . from_pretrained ( model_path , use_fast = False )
# Since transformers 4.35.0, the GPT-Q/AWQ model can be loaded using AutoModelForCausalLM.
model = AutoModelForCausalLM . from_pretrained (
model_path ,
device_map = "auto" ,
torch_dtype = 'auto'
). eval ()
# Prompt content: "hi"
messages = [
{ "role" : "user" , "content" : "hi" }
]
input_ids = tokenizer . apply_chat_template ( conversation = messages , tokenize = True , add_generation_prompt = True , return_tensors = 'pt' )
output_ids = model . generate ( input_ids . to ( 'cuda' ))
response = tokenizer . decode ( output_ids [ 0 ][ input_ids . shape [ 1 ]:], skip_special_tokens = True )
# Model response: "Hello! How can I assist you today?"
print ( response )
运行quick_start.py
。
python quick_start.py
然后您可以看到类似于下面的输出。 ?
Hello ! How can I assist you today ?
翼34B
步骤类似于 pip - 使用 Yi 聊天模型进行推理。
您可以使用现有文件text_generation.py
。
python demo/text_generation.py --model < your-model-path >
然后您可以看到类似于下面的输出。 ?
提示:让我给你讲一个关于猫汤姆和老鼠杰瑞的有趣故事,
世代:让我给你讲一个发生在我童年的关于猫汤姆和老鼠杰瑞的有趣故事。我父亲有一座大房子,里面住着两只猫,用来捕老鼠。有一天,我一个人在家玩,发现一只雄猫仰面躺在厨房门口附近,看上去很像要我们送东西,却爬不起来,因为周围人太多了!他又试了几分钟,最后还是放弃了……
毅9B
输入
from transformers import AutoModelForCausalLM, AutoTokenizer
MODEL_DIR = " 01-ai/Yi-9B "
model = AutoModelForCausalLM.from_pretrained(MODEL_DIR, torch_dtype= " auto " )
tokenizer = AutoTokenizer.from_pretrained(MODEL_DIR, use_fast=False)
input_text = " # write the quick sort algorithm "
inputs = tokenizer(input_text, return_tensors= " pt " ).to(model.device)
outputs = model.generate( ** inputs, max_length=256)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
输出
# write the quick sort algorithm
def quick_sort(arr):
if len(arr) < = 1:
return arr
pivot = arr[len(arr) // 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quick_sort(left) + middle + quick_sort(right)
# test the quick sort algorithm
print(quick_sort([3, 6, 8, 10, 1, 2, 1]))
[回到顶部⬆️]
确保您已安装 Docker 和 nvidia-container-toolkit。
docker run -it --gpus all
-v <your-model-path>: /models
ghcr.io/01-ai/yi:latest
或者,您可以从registry.lingyiwanwu.com/ci/01-ai/yi:latest
提取Yi Docker 镜像。
您可以使用 Yi chat 或基本模型进行推理,如下所示。
步骤类似于 pip - 使用 Yi 聊天模型进行推理。
请注意,唯一的区别是设置model_path = '<your-model-mount-path>'
而不是model_path = '<your-model-path>'
。
步骤类似于 pip - 使用 Yi 基本模型进行推理。
请注意,唯一的区别是设置--model <your-model-mount-path>'
而不是model <your-model-path>
。
conda-lock
为 conda 环境生成完全可重现的锁定文件。micromamba
来安装这些依赖项。按照此处提供的说明安装 micromamba。
执行micromamba install -y -n yi -f conda-lock.yml
创建名为yi
conda 环境并安装必要的依赖项。
以下教程将指导您完成在本地运行量化模型(Yi-chat-6B-2bits)然后执行推理的每个步骤。
本教程假设您使用配备 16GB 内存和 Apple M2 Pro 芯片的 MacBook Pro。
确保您的计算机上安装了git-lfs
。
llama.cpp
要克隆llama.cpp
存储库,请运行以下命令。
git clone [email protected]:ggerganov/llama.cpp.git
2.1 要仅使用指针克隆 XeIaso/yi-chat-6B-GGUF,请运行以下命令。
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/XeIaso/yi-chat-6B-GGUF
2.2 要下载量化的 Yi 模型(yi-chat-6b.Q2_K.gguf),请运行以下命令。
git-lfs pull --include yi-chat-6b.Q2_K.gguf
要使用 Yi 模型进行推理,您可以使用以下方法之一。
方法一:在终端进行推理
方法2:在Web中进行推理
要使用 4 线程编译llama.cpp
然后进行推理,请导航到llama.cpp
目录,然后运行以下命令。
尖端
将
/Users/yu/yi-chat-6B-GGUF/yi-chat-6b.Q2_K.gguf
替换为模型的实际路径。默认情况下,模型在完成模式下运行。
对于其他输出自定义选项(例如系统提示、温度、重复惩罚等),请运行
./main -h
查看详细说明和用法。
make -j4 && ./main -m /Users/yu/yi-chat-6B-GGUF/yi-chat-6b.Q2_K.gguf -p " How do you feed your pet fox? Please answer this question in 6 simple steps:nStep 1: " -n 384 -e
...
How do you feed your pet fox ? Please answer this question in 6 simple steps:
Step 1: Select the appropriate food for your pet fox. You should choose high-quality, balanced prey items that are suitable for their unique dietary needs. These could include live or frozen mice, rats, pigeons, or other small mammals, as well as fresh fruits and vegetables.
Step 2: Feed your pet fox once or twice a day, depending on the species and its individual preferences. Always ensure that they have access to fresh water throughout the day.
Step 3: Provide an appropriate environment for your pet fox. Ensure it has a comfortable place to rest, plenty of space to move around, and opportunities to play and exercise.
Step 4: Socialize your pet with other animals if possible. Interactions with other creatures can help them develop social skills and prevent boredom or stress.
Step 5: Regularly check for signs of illness or discomfort in your fox. Be prepared to provide veterinary care as needed, especially for common issues such as parasites, dental health problems, or infections.
Step 6: Educate yourself about the needs of your pet fox and be aware of any potential risks or concerns that could affect their well-being. Regularly consult with a veterinarian to ensure you are providing the best care.
...
现在你已经成功向Yi模型提问并得到了答案! ?
要初始化轻量级且快速的聊天机器人,请运行以下命令。
cd llama.cpp
./server --ctx-size 2048 --host 0.0.0.0 --n-gpu-layers 64 --model /Users/yu/yi-chat-6B-GGUF/yi-chat-6b.Q2_K.gguf
然后你可以得到这样的输出:
...
llama_new_context_with_model: n_ctx = 2048
llama_new_context_with_model: freq_base = 5000000.0
llama_new_context_with_model: freq_scale = 1
ggml_metal_init: allocating
ggml_metal_init: found device: Apple M2 Pro
ggml_metal_init: picking default device: Apple M2 Pro
ggml_metal_init: ggml.metallib not found, loading from source
ggml_metal_init: GGML_METAL_PATH_RESOURCES = nil
ggml_metal_init: loading ' /Users/yu/llama.cpp/ggml-metal.metal '
ggml_metal_init: GPU name: Apple M2 Pro
ggml_metal_init: GPU family: MTLGPUFamilyApple8 (1008)
ggml_metal_init: hasUnifiedMemory = true
ggml_metal_init: recommendedMaxWorkingSetSize = 11453.25 MB
ggml_metal_init: maxTransferRate = built-in GPU
ggml_backend_metal_buffer_type_alloc_buffer: allocated buffer, size = 128.00 MiB, ( 2629.44 / 10922.67)
llama_new_context_with_model: KV self size = 128.00 MiB, K (f16): 64.00 MiB, V (f16): 64.00 MiB
ggml_backend_metal_buffer_type_alloc_buffer: allocated buffer, size = 0.02 MiB, ( 2629.45 / 10922.67)
llama_build_graph: non-view tensors processed: 676/676
llama_new_context_with_model: compute buffer total size = 159.19 MiB
ggml_backend_metal_buffer_type_alloc_buffer: allocated buffer, size = 156.02 MiB, ( 2785.45 / 10922.67)
Available slots:
- > Slot 0 - max context: 2048
llama server listening at http://0.0.0.0:8080
要访问聊天机器人界面,请打开 Web 浏览器并在地址栏中输入http://0.0.0.0:8080
。
在提示窗口中输入问题,例如“您如何喂养您的宠物狐狸?请通过6个简单步骤回答这个问题”,您将收到相应的答案。
[回到顶部⬆️]
您可以为 Yi聊天模型构建 Web UI 演示(请注意,此方案不支持 Yi 基本模型)。
步骤 1:准备环境。
第2步:下载Yi模型。
步骤 3. 要在本地启动 Web 服务,请运行以下命令。
python demo/web_demo.py -c < your-model-path >
您可以通过在浏览器中输入控制台中提供的地址来访问 Web UI。
[回到顶部⬆️]
bash finetune/scripts/run_sft_Yi_6b.sh
完成后,您可以使用以下命令比较微调模型和基础模型:
bash finetune/scripts/run_eval.sh
默认情况下,我们使用 BAAI/COIG 的小型数据集来微调基本模型。您还可以使用以下jsonl
格式准备自定义数据集:
{ "prompt" : " Human: Who are you? Assistant: " , "chosen" : " I'm Yi. " }
然后将它们挂载到容器中以替换默认的:
docker run -it
-v /path/to/save/finetuned/model/:/finetuned-model
-v /path/to/train.jsonl:/yi/finetune/data/train.json
-v /path/to/eval.jsonl:/yi/finetune/data/eval.json
ghcr.io/01-ai/yi:latest
bash finetune/scripts/run_sft_Yi_6b.sh
确保你有康达。如果没有,请使用
mkdir -p ~ /miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~ /miniconda3/miniconda.sh
bash ~ /miniconda3/miniconda.sh -b -u -p ~ /miniconda3
rm -rf ~ /miniconda3/miniconda.sh
~ /miniconda3/bin/conda init bash
source ~ /.bashrc
然后,创建一个 conda 环境:
conda create -n dev_env python=3.10 -y
conda activate dev_env
pip install torch==2.0.1 deepspeed==0.10 tensorboard transformers datasets sentencepiece accelerate ray==2.7
对于Yi-6B型号,建议使用4个GPU的节点,每个GPU显存大于60GB。
对于 Yi-34B 模型,由于使用零卸载技术会消耗大量 CPU 内存,因此在 34B Finetune 训练时请注意限制 GPU 数量。请使用CUDA_VISIBLE_DEVICES来限制GPU的数量(如scripts/run_sft_Yi_34b.sh所示)。
微调 34B 模型的典型硬件设置是具有 8 个 GPU 的节点(通过 CUDA_VISIBLE_DEVICES=0,1,2,3 限制运行中的 4 个),每个 GPU 内存大于 80GB,总 CPU 内存大于 900GB。
将基于 LLM 的模型下载到 MODEL_PATH(6B 和 34B)。典型的模型文件夹如下:
| -- $MODEL_PATH
| | -- config.json
| | -- pytorch_model-00001-of-00002.bin
| | -- pytorch_model-00002-of-00002.bin
| | -- pytorch_model.bin.index.json
| | -- tokenizer_config.json
| | -- tokenizer.model
| | -- ...
从huggingface下载数据集到本地存储DATA_PATH,例如Dahoas/rm-static。
| -- $DATA_PATH
| | -- data
| | | -- train-00000-of-00001-2a1df75c6bce91ab.parquet
| | | -- test-00000-of-00001-8c7c51afc6d45980.parquet
| | -- dataset_infos.json
| | -- README.md
finetune/yi_example_dataset
有示例数据集,修改自 BAAI/COIG
| -- $DATA_PATH
| --data
| -- train.jsonl
| -- eval.jsonl
cd
进入脚本文件夹,复制并粘贴脚本,然后运行。例如:
cd finetune/scripts
bash run_sft_Yi_6b.sh
对于Yi-6B基础模型,设置training_debug_steps=20和num_train_epochs=4可以输出聊天模型,大约需要20分钟。
对于Yi-34B基础模型来说,初始化需要相对较长的时间。请耐心等待。
cd finetune/scripts
bash run_eval.sh
然后您将看到基本模型和微调模型的答案。
[回到顶部⬆️]
python quantization/gptq/quant_autogptq.py
--model /base_model
--output_dir /quantized_model
--trust_remote_code
完成后,您可以按如下方式评估生成的模型:
python quantization/gptq/eval_quantized_model.py
--model /quantized_model
--trust_remote_code
GPT-Q 是一种 PTQ(训练后量化)方法。它可以节省内存并提供潜在的加速,同时保持模型的准确性。
Yi 模型不需要太多努力就可以进行 GPT-Q 量化。我们在下面提供了分步教程。
为了运行 GPT-Q,我们将使用 AutoGPTQ 和 exllama。 Huggingface Transformer 集成了 optimization 和 auto-gptq,可以在语言模型上执行 GPTQ 量化。
提供了quant_autogptq.py
脚本供您执行 GPT-Q 量化:
python quant_autogptq.py --model /base_model
--output_dir /quantized_model --bits 4 --group_size 128 --trust_remote_code
您可以使用eval_quantized_model.py
运行量化模型:
python eval_quantized_model.py --model /quantized_model --trust_remote_code
python quantization/awq/quant_autoawq.py
--model /base_model
--output_dir /quantized_model
--trust_remote_code
完成后,您可以按如下方式评估生成的模型:
python quantization/awq/eval_quantized_model.py
--model /quantized_model
--trust_remote_code
AWQ 是一种 PTQ(训练后量化)方法。它是适用于 LLM 的高效且准确的低位权重量化 (INT3/4)。
Yi 模型无需太多努力即可进行 AWQ 量化。我们在下面提供了分步教程。
为了运行 AWQ,我们将使用 AutoAWQ。
提供了quant_autoawq.py
脚本供您执行 AWQ 量化:
python quant_autoawq.py --model /base_model
--output_dir /quantized_model --bits 4 --group_size 128 --trust_remote_code
您可以使用eval_quantized_model.py
运行量化模型:
python eval_quantized_model.py --model /quantized_model --trust_remote_code
[回到顶部⬆️]
如果您想部署 Yi 模型,请确保满足软件和硬件要求。
在使用 Yi 量化模型之前,请确保您已安装下列正确的软件。
模型 | 软件 |
---|---|
Yi 4位量化模型 | AWQ 和 CUDA |
Yi 8位量化模型 | GPTQ 和 CUDA |
在您的环境中部署 Yi 之前,请确保您的硬件满足以下要求。
模型 | 最小显存 | 推荐的 GPU 示例 |
---|---|---|
Yi-6B-聊天 | 15GB | 1 个 RTX 3090 (24 GB) 1 个 RTX 4090 (24 GB) 1 个 A10(24 GB) 1 个 A30(24 GB) |
Yi-6B-聊天-4bits | 4GB | 1 个 RTX 3060 (12 GB) 1 个 RTX 4060 (8 GB) |
Yi-6B-聊天-8bits | 8GB | 1 个 RTX 3070 (8 GB) 1 个 RTX 4060 (8 GB) |
Yi-34B-聊天 | 72GB | 4 个 RTX 4090 (24 GB) 1 个 A800(80GB) |
Yi-34B-聊天-4bits | 20GB | 1 个 RTX 3090 (24 GB) 1 个 RTX 4090 (24 GB) 1 个 A10(24 GB) 1 个 A30(24 GB) 1 个 A100(40 GB) |
Yi-34B-聊天-8位 | 38GB | 2 个 RTX 3090 (24 GB) 2 个 RTX 4090 (24 GB) 1 个 A800(40 GB) |
以下是不同批次用例下详细的最低 VRAM 要求。
模型 | 批次=1 | 批次=4 | 批次=16 | 批次=32 |
---|---|---|---|---|
Yi-6B-聊天 | 12GB | 13GB | 15GB | 18GB |
Yi-6B-聊天-4bits | 4GB | 5GB | 7GB | 10GB |
Yi-6B-聊天-8bits | 7GB | 8GB | 10GB | 14GB |
Yi-34B-聊天 | 65GB | 68GB | 76GB | > 80 GB |
Yi-34B-聊天-4bits | 19GB | 20GB | 30GB | 40GB |
Yi-34B-聊天-8位 | 35GB | 37GB | 46GB | 58GB |
模型 | 最小显存 | 推荐的 GPU 示例 |
---|---|---|
伊6B | 15GB | 1 个 RTX 3090 (24 GB) 1 个 RTX 4090 (24 GB) 1 个 A10(24 GB) 1 个 A30(24 GB) |
毅6B-200K | 50GB | 1 个 A800(80 GB) |
毅9B | 20GB | 1 个 RTX 4090 (24 GB) |
翼34B | 72GB | 4 个 RTX 4090 (24 GB) 1 个 A800(80 GB) |
毅-34B-200K | 200GB | 4 个 A800(80 GB) |
[回到顶部⬆️]
Yi-34B
和Yi-34B-Chat
上的全面微调之间的主要区别在于微调方法和结果。Yi-34B
进行微调可能是您的首选。Yi-34B-Chat
可能是您的最佳选择。