[Notebook](https://github.com/unit-mesh/unit-minions/blob/master/chatglm-tuning.ipynb)
ChatGLM-finetune-LoRA
此存储库包含使用低秩适配 (LoRA) 的 fintune ChatGLM-6b 代码。
示例行:
`
{'prompt': 'Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nClassify the movie genres from the given context.\n\n### Input:\nThis movie tells the story of two brothers who were both born with magical powers.\n\n### Response:', 'completion': 'Fantasy'}
`
LoRA:
config = LoraConfig(
peft_type="LORA",
task_type="SEQ_2_SEQ_LM",
r=8,
lora_alpha=8,
target_modules=["q", "v"],
lora_dropout=0.1,
)
使用上面的 LoRA 配置, trainable_params:3670016 (0.06%), non_trainable_params:6255206400
保存和加载代码:
``` python
torch.save(lora.lora_state_dict(model), 'path to file you saved')
model.load_state_dict(torch.load('path to file you saved'), strict=False)
```
链接: https://pan.baidu.com/s/1KnadoP0BVqbL4_hcxy2Fog?pwd=jb7r 提取码: jb7r
[1] @halomaster • 21 Mar 2023, 05:59 GMT
另一个项目:
https://github.com/ssbuild/chatglm_finetuning
也支持LoRA
[2] @halomaster • 21 Mar 2023, 06:02 GMT
deep_training项目
基于pytorch-lightning 和 transformers实现的上下游训练框架
https://github.com/ssbuild/deep_training
[3] @halomaster • 27 Mar 2023, 03:02 GMT
目前可用的Demo:
https://huggingface.co/spaces/multimodalart/ChatGLM-6B
[4] @halomaster • 08 Apr 2023, 15:27 GMT
chatglm_finetuning:https://github.com/ssbuild/chatglm_finetuning
[5] @halomaster • 08 Apr 2023, 15:28 GMT
<ul>
<li>WechatExporter:<a href="https://github.com/BlueMatthew/WechatExporter">BlueMatthew/WechatExporter: Wechat Chat History Exporter 微信聊天记录导出备份程序 (github.com)</a></li>
<li>chatglm-6b:<a href="https://github.com/THUDM/ChatGLM-6B">THUDM/ChatGLM-6B: ChatGLM-6B:开源双语对话语言模型 | An Open Bilingual Dialogue Language Model (github.com)</a></li>
<li>zero_nlp:<a href="https://github.com/yuanzhoulvpi2017/zero_nlp">yuanzhoulvpi2017/zero_nlp: 中文nlp应用(大模型、数据、模型、训练、推理) (github.com)</a></li>
<li>chatglm_finetuning:https://github.com/ssbuild/chatglm_finetuning</li>
<li>MoeChat:<a href="https://github.com/Fzoss/MoeChat">Fzoss/MoeChat: 一个比较好看的WEB聊天界面UI (github.com)</a></li>
<li>Alpaca: A Strong, Replicable Instruction-Following Model:<a href="https://crfm.stanford.edu/2023/03/13/alpaca.html">Stanford CRFM</a></li>
<li>LLAMA:<a href="https://github.com/facebookresearch/llama">facebookresearch/llama: Inference code for LLaMA models (github.com)</a></li>
</ul>
[6] @halomaster • 09 Apr 2023, 06:09 GMT
https://raw.githubusercontent.com/ssbuild/chatglm_finetuning/main/models.py
这段代码定义了一个PyTorch ChatGLM模型类ChatGLMModel。我们可以从中获得以下理解:
1. ChatGLMModel继承nn.Module,实现了模型的基础结构。
2. __init__函数初始化模型,包括:
- 调用nn.Module的__init__函数
- 指定模型名称为chatglm
- 加载HuggingFace的transformer-base-cased预训练模型
- 从预训练模型中提取文本编码器transformer和解码器lm_head
- 初始化参数max_length(文本最大长度)和pad_token_id(填充标记的ID)
3. forward函数定义模型的前向计算流程,它接收文本输入ids和掩码masks,并返回模型输出。计算过程主要是:
- 检查输入长度是否超过max_length,如果超过则截断
- 将填充标记的ID pad_token_id添加至文本末尾直至长度达到max_length
- 将文本输入ids和掩码masks喂入transformer得到context代码
- 将context代码输入lm_head得到最终的logits输出
4. 额外定义了get_input_ids和get_attention_mask函数,用于将字符串文本输入转换为模型输入所需的格式。
5. 最后,定义了load_model函数用于加载预训练的ChatGLM模型。
所以,总的来说,这个模型类实现了如下功能:
1. 加载HuggingFace的transformer-base-cased预训练模型。
2. 从预训练模型中提取文本编码器和解码器用于构建ChatGLM模型。
3. 定义ChatGLM模型的前向计算过程,主要是文本输入->文本编码器->解码器->输出logits。
4. 实现将字符串输入转换为模型所需输入格式的函数。
5. 实现从保存文件加载预训练ChatGLM模型的函数。
6. 继承nn.Module实现ChatGLM模型的基础结构。
这个模型类提供了一个简单易用的接口用于构建和加载ChatGLM模型。
[7] @halomaster • 10 Apr 2023, 16:41 GMT
一种平价的chatgpt实现方案, 基于ChatGLM-6B + LoRA
https://github.com/mymusise/ChatGLM-Tuning
[8] @halomaster • 12 Apr 2023, 01:29 GMT
- 斯坦福大学发布了 Alpaca,这是一种基于 LLama 7B 模型的指令跟随模型
- 来自加州大学伯克利分校、卡内基梅隆大学、斯坦福大学和加州大学圣地亚哥分校的研究人员开源了 Vicuna,这是一个与 GPT-4 性能相匹配的 LLama 微调版本
- Berkeley AI Research Institute (BAIR) 发布了 Koala,这是一种使用互联网对话进行微调的 LLama 版本
- Nebuly 开源了 ChatLLama,这是一个使用您自己的数据创建对话助手的框架
- FreedomGPT 是一个基于羊驼的开源会话代理,采用 LLama
- 加州大学伯克利分校的 Colossal-AI 项目发布了 ColossalChat,这是一种 ChatGPT 类型的模型,具有基于 LLama 的完整 RLHF 管道
[9] @halomaster • 29 Apr 2023, 15:55 GMT
https://github.com/thomas-yanxin/LangChain-ChatGLM-Webui/blob/master/docs/deploy.md
基于LangChain和ChatGLM-6B等系列LLM的针对本地知识库的自动问答
[10] @halomaster • 30 Apr 2023, 08:37 GMT
logger.warning_once(f"The dtype of attention mask ({attention_mask.dtype}) is not bool")
AttributeError: 'Logger' object has no attribute 'warning_once'
在GitHub找到的解决办法是升级transformers升级到4.27.1
https://github.com/THUDM/ChatGLM-6B/issues/344 作者:催化脑洞 https://www.bilibili.com/read/cv23021868/ 出处:bilibili
1 of 1 pages 10 replies