一、导读
Yi-1.5是Yi的升级版本。 它使用 500B tokens的高质量语料库在 Yi 上持续进行预训练,并在 3M 个多样化的微调样本上进行微调。
与 Yi 相比,Yi-1.5 在编码、数学、推理和指令跟踪能力方面表现更强,同时在语言理解、常识推理和阅读理解方面仍然保持出色的能力。
Model |
Context Length |
Pre-trained Tokens |
Yi-1.5 |
4K |
3.6T |
模型
-
对话模型
Name |
Download |
Yi-1.5-34B-Chat |
https://modelscope.cn/models/01ai/Yi-1.5-34B-Chat |
Yi-1.5-9B-Chat |
https://modelscope.cn/models/01ai/Yi-1.5-9B-Chat |
Yi-1.5-6B-Chat |
https://modelscope.cn/models/01ai/Yi-1.5-6B-Chat |
-
基础模型
Name |
Download |
Yi-1.5-34B |
https://modelscope.cn/models/01ai/Yi-1.5-34B |
Yi-1.5-9B |
https://modelscope.cn/models/01ai/Yi-1.5-9B |
Yi-1.5-6B |
https://modelscope.cn/models/01ai/Yi-1.5-6B |
模型评测
-
对话模型
Yi-1.5-34B-Chat 在多数基准测试中表现与更大规模的模型相当甚至超越它们。
Yi-1.5-9B-Chat 是同规模的开源模型中表现顶尖。
-
基础模型
Yi-1.5-34B 在多数基准测试中表现与更大规模的模型相当甚至超越它们。
Yi-1.5-9B 是同规模的开源模型中表现顶尖。
以下为大家带来魔搭社区推理、微调最佳实践教程。
二、模型体验
模型体验链接:https://modelscope.cn/studios/01ai/Yi-1.5-34B-Chat-Demo/summary
自我认知:
数学:
逻辑:
三、环境配置与安装
本文使用的模型为Yi-1.5-6B-Chat模型,可在ModelScope的Notebook的环境(这里以PAI-DSW为例)的配置下运行(显存24G) 。
环境配置与安装
本文主要演示的模型推理代码可在魔搭社区免费实例PAI-DSW的配置下运行(显存24G) :
点击模型右侧Notebook快速开发按钮,选择GPU环境
打开Notebook环境:
四、 模型链接和下载
Yi-9B现已在ModelScope社区开源,模型链接:
https://www.modelscope.cn/models/01ai/Yi-9B/summary
社区支持直接下载模型的repo:
from modelscope import snapshot_download
model_dir = snapshot_download("01ai/Yi-1.5-6B-Chat")
五、Yi-1.5系列模型推理
模型推理
from modelscope import AutoModelForCausalLM, AutoTokenizer,snapshot_download
import torch
model_dir = snapshot_download('01ai/Yi-1.5-6B-Chat')
tokenizer = AutoTokenizer.from_pretrained(model_dir, use_fast=False)
# Since transformers 4.35.0, the GPT-Q/AWQ model can be loaded using AutoModelForCausalLM.
model = AutoModelForCausalLM.from_pretrained(
model_dir,
device_map="auto",
torch_dtype=torch.bfloat16
).eval()
# Prompt content: "hi"
messages = [
{"role": "user", "content": "浙江的省会是哪里?"}
]
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)
显存占用:
六、Yi-1.5系列模型微调和微调后推理
我们使用swift来对模型进行微调, swift是魔搭社区官方提供的LLM微调推理框架.
微调代码开源地址: https://github.com/modelscope/swift
以yi-1.5-9b-chat模型为例,我们使用swift提供的自我认知数据集进行训练, 改变模型对自己和作者的认知。目前魔搭社区已经支持了yi1.5-6B/9B/34B全系列模型(包含量化模型)的训练和推理。请点击链接来查看具体支持的模型类型:https://github.com/modelscope/swift/blob/main/docs/source/LLM/%E6%94%AF%E6%8C%81%E7%9A%84%E6%A8%A1%E5%9E%8B%E5%92%8C%E6%95%B0%E6%8D%AE%E9%9B%86.md
环境准备:
git clone https://github.com/modelscope/swift.git
cd swift
pip install .[llm]
微调脚本: LoRA
# Experimental environment: A100
# 19GB GPU memory
swift sft \
--model_type yi-1_5-9b-chat \
--sft_type lora \
--dataset self-cognition#1000 \
--dtype AUTO \
--num_train_epochs 1 \
--max_length 1024 \
--check_dataset_strategy warning \
--lora_rank 8 \
--lora_alpha 32 \
--lora_dropout_p 0.05 \
--lora_target_modules ALL \
--gradient_checkpointing true \
--batch_size 1 \
--weight_decay 0.1 \
--learning_rate 1e-4 \
--gradient_accumulation_steps 16 \
--max_grad_norm 0.5 \
--warmup_ratio 0.03 \
--save_total_limit 2 \
--logging_steps 10 \
--use_flash_attn true \
--model_name 小白 'Xiao Bai' \
--model_author 魔搭 ModelScope \
微调后推理脚本: (这里的ckpt_dir需要修改为训练生成的checkpoint文件夹)
# Experimental environment: A100
CUDA_VISIBLE_DEVICES=0 \
swift infer \
--ckpt_dir "output/yi-1_5-9b-chat/vx-xxx/checkpoint-xxx" \
--use_flash_attn true \
--temperature 0.3 \
--top_p 0.7 \
--repetition_penalty 1. \
--do_sample true \
--merge_lora false
微调的可视化结果:
训练前生成样例:
训练后生成样例:
(微调后通用能力测试)
资源占用
微调
七、Yi-1.5系列模型量化方法
社区开发者基于AWQ和GPTQ的方法,对Yi-1.5系列模型量化,量化后的模型已开源在魔搭社区,欢迎开发者体验和反馈。
-
量化后模型
模型名称 |
下载地址 |
Yi-1.5-6B-Chat-AWQ |
https://modelscope.cn/models/AI-ModelScope/Yi-1.5-6B-Chat-AWQ |
Yi-1.5-6B-Chat-GPTQ |
https://modelscope.cn/models/AI-ModelScope/Yi-1.5-6B-Chat-GPTQ |
Yi-1.5-9B-Chat-AWQ |
https://modelscope.cn/models/AI-ModelScope/Yi-1.5-9B-Chat-AWQ |
Yi-1.5-9B-Chat-GPTQ |
https://modelscope.cn/models/AI-ModelScope/Yi-1.5-9B-Chat-GPTQ |
Yi-1.5-34B-Chat-AWQ |
https://www.modelscope.cn/models/AI-ModelScope/Yi-1.5-34B-Chat-AWQ/summary |
Yi-1.5-34B-Chat-GPTQ |
https://www.modelscope.cn/models/AI-ModelScope/Yi-1.5-34B-Chat-GPTQ |
点击链接了解更多
所有评论(0)