Qwen-7B微调实例

news/2024/7/20 19:38:38 标签: 大模型, Qwen, 通义千问

QwenSFT_0">Qwen-SFT

阿里通义千问(Qwen-7B-Chat/Qwen-7B), 微调/LORA/推理

Github

https://github.com/yongzhuo/Qwen-SFT

踩坑

1. tokenizer.encode输出(不会新增特殊字符),[真实文本tokens]: 
2. chat-PROMPT: <|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\n你好<|im_end|>\n<|im_start|>assistant\n
3.1 微调输入输出:
    输入:"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n
          <|im_start|>user\n{问题}<|im_end|>\n<|im_start|>"
    输出:"assistant\n{答案}<|im_end|><|endoftext|>"
    输入id: [151644, 输入tokens(user), 151643, 198, 151644]
    输出id: [输出tokens(assistant), 151643, 151645]
3.2 推理输入输出(assistant\n放置位置不同):
    输入:"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n
          <|im_start|>user\n{问题}<|im_end|>\n<|im_start|>assistant\n"
    输出:"{答案}<|im_end|><|endoftext|>"
    输入id: [151644, 输入tokens(user), 151643, 198, 151644, 输出tokens(assistant)]
    输出id: [151643, 151645]
4. 自定义的attention_mask没有使用(所以微调不能mask掉padding, 只能用right-padding):
    LLaMA为:
        attn_weights = attn_weights + attention_mask
        attn_weights = torch.max(attn_weights, torch.tensor(torch.finfo(attn_weights.dtype).min))
    QWen-7B没有使用:
        query_length, key_length = query.size(-2), key.size(-2)
        causal_mask = self.bias[:, :, key_length - query_length: key_length, :key_length]
        mask_value = torch.finfo(attn_weights.dtype).min
        mask_value = torch.full([], mask_value, dtype=attn_weights.dtype).to(attn_weights.device)
        attn_weights = torch.where(causal_mask, attn_weights.to(attn_weights.dtype), mask_value)
5. RuntimeError: unscale_() has already been called on this optimizer since the last update().
    微调语料太少导致的

环境配置

transformers>=4.31.0
torch>=1.10.1
rouge==1.0.1
nltk==3.6.6
peft>=0.2.0
numpy
tqdm

微调

地址: qwen_sft/ft_qwen

配置: qwen_sft/ft_qwen/config.py
训练: python train.py
推理: python predict.py
验证: python evaluation.py
接口: python post_api.py

微调日志(ADVGEN)

在这里插入图片描述

推理日志(LoRA, R=8)

sample-1:
在这里插入图片描述

sample-2:
在这里插入图片描述

数据集-中文

  • https://huggingface.co/datasets/JosephusCheung/GuanacoDataset
  • https://huggingface.co/datasets/shareAI/shareGPT_cn
  • https://huggingface.co/datasets/Mutonix/RefGPT-Fact
  • https://huggingface.co/datasets/BAAI/COIG
  • https://github.com/Instruction-Tuning-with-GPT-4/GPT-4-LLM
  • https://github.com/carbonz0/alpaca-chinese-dataset
  • https://github.com/LianjiaTech/BELLE
  • https://github.com/PhoebusSi/Alpaca-CoT
  • https://github.com/Hello-SimpleAI/chatgpt-comparison-detection
  • https://github.com/yangjianxin1/Firefly
  • https://github.com/XueFuzhao/InstructionWild
  • https://github.com/OpenLMLab/MOSS
  • https://github.com/thu-coai/Safety-Prompts
  • https://github.com/LAION-AI/Open-Assistant
  • https://github.com/TigerResearch/TigerBot

参考/感谢

  • https://github.com/QwenLM/Qwen-7B
  • https://github.com/tatsu-lab/stanford_alpaca
  • https://github.com/THUDM/ChatGLM-6B
  • https://github.com/huggingface/peft
  • math23k
  • trl

免责申明

本项目相关资源仅供学术研究之用,使用涉及第三方代码的部分时,请严格遵循相应的开源协议。模型生成的内容受模型计算、随机性和量化精度损失等因素影响,本项目不对其准确性作出保证。对于模型输出的任何内容,本项目不承担任何法律责任,亦不对因使用相关资源和输出结果而可能产生的任何损失承担责任。

使用相关资源和输出结果而可能产生的任何损失承担责任。


http://www.niftyadmin.cn/n/4962095.html

相关文章

程序员如何开发一款赚钱的软件产品

在不涉及法律、政治以及中国官员的前提下,下面是一些程序员可以考虑的方法,用于开发一款赚钱的软件产品: 1. **解决实际问题**:开发解决真实问题或需求的软件,这可能涵盖从生活便利到商业流程优化的各个领域。例如,可以考虑开发一个时间管理工具、健康跟踪应用或者商务协…

sdkman 安装以及 graalvm安装

sdkman安装以及graalvm安装全过程, (可能需要梯子) tiamTiam-Lenovo:~$ curl -s "https://get.sdkman.io" | bash-syyyyyyys:/yho: -yd./yh/ m..oho. hy ..sh/ :N -/…

机器学习:开启智能时代的重要引擎

引言 随着科技的飞速发展&#xff0c;人工智能已经渗透到我们生活的各个领域。而在人工智能的众多领域中&#xff0c;机器学习以其强大的数据处理能力和智能决策能力受到了广泛关注。本文将向您介绍机器学习的概念、工作原理、应用领域以及未来的发展前景。 一、什么是机器学…

快速搭建 Linux 学习平台

最近换了一个新的笔记本电脑&#xff0c;原来的学习环境没了&#xff0c;所以就重新搭建一下&#xff0c;顺便把这个过程给记录下来&#xff0c;希望可以帮助有需要的人。一个学习环境最主要的目的是简化学习需要准备的时间&#xff0c;不需要花费太多的时间在哪些不必要的细枝…

HTML <table> 标签

实例 一个简单的 HTML 表格,包含两行两列: <table border="1"><tr><th>Month</th><th>Savings</th></tr><tr><td>January</td><td>$100</td></tr> </table>定义和用法 &l…

科兴未来 | 百万奖金!香港科大,2023人工智能国际创业大赛启动!

一、关于港科百创 Q:港科百创能为创企带来什么? A:一次性为人工智能领域创业者解决找资源、找突破、找定位的“三找难题”。 (一) 找资源:多家知名投资机构充分对接,百万奖金静待赢家 (二) 找突破:三大“导师”天团提供辅导,为参赛创业者持续赋能 (三) 找定位:行业翘楚同…

32、启用 HTTP 响应压缩和编程式配置Web应用

★ 启用HTTP压缩 就是前端页面如果改动的比较多&#xff0c;那么响应就会比较慢&#xff0c;可以通过设置HTTP响应压缩来提高响应&#xff0c;如果前端改动少&#xff0c;那么就不需要启动这个响应压缩。 目的&#xff1a;为了提高HTTP响应数据在网络上的传输效率。▲ 设置如…

【AI选股】通过pywencai访问同花顺问财接口实现智能选股

文章目录 前言一、pywencai是什么&#xff1f;1. 准备node环境2. 安装pywencai库3. git地址&#xff1a; 二、使用步骤1 . Demo2. 进阶调用 总结 前言 之前使用的iwencai&#xff0c;最近出现无法访问的问题&#xff0c;几经辗转&#xff0c;发现pywencai库可以替代其功能&…