• Stars
    star
    103
  • Rank 331,028 (Top 7 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created about 1 year ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ChatGLM2-6B微调, SFT/LoRA, instruction finetune

chatglm2-6b-sft

chatglm2-6b, chatglm-6b微调/LORA/推理

踩坑(截至20230705)

1. torch>=2.0, 否则微调会报很多错误(单纯推理可以用低版本);
2. tokenizer.encode输出为 [gMASK, sop, 真实文本token]
    64789 = {str} '[MASK]'
    64790 = {str} '[gMASK]'
    64791 = {str} '[sMASK]'
    64792 = {str} 'sop'
    64793 = {str} 'eop'
3. modeling_chatglm.py自带get_masks()的代码full_attention_mask -= padding_mask.unsqueeze(-1) - 1改为
                full_attention_mask = full_attention_mask.long() - padding_mask.unsqueeze(-1).long() - 1
4. 不支持gradient_checkpointing, 修复的话需要modeling_chatglm.py新增get_input_embeddings, set_input_embeddings;
5. modeling_chatglm.py中的ChatGLMForConditionalGeneration类forward函数中的
      if full_attention_mask is None:  前加入  batch_size, seq_length = input_ids.shape
6. get_mask(), 一直以来都对chatglm的mask/position有一些疑惑;
    def get_masks(seq, bos_token_id=sop):
        """  code from model_chatglm.py  """
        if seq.count(bos_token_id) == 2:
            context_length = seq[2:].index(bos_token_id) + 2
        else:
            context_length = seq.index(bos_token_id)
        attention_mask = torch.ones((1, len(seq), len(seq)))
        attention_mask.tril_()
        attention_mask[..., :context_length] = 1
        # attention_mask.unsqueeze_(1)
        attention_mask = (attention_mask < 0.5).bool()
        return attention_mask
7. 严格按照官方prompt构建输入输出"注意[Round 1]很重要, 不能删减"):
    输入"[Round 1]\n\n问:{}\n\n答:"
    输出"{}"
    输入id: [gMASK, sop, 输入tokens, gMASK, sop]
    输出id: [输出tokens, EOS]
8. prompttokenizer测试结论“[gMASK, sop]”很重要, 必须置于开头, 不能删减问题1+1=
   拼接:[gMASK, sop] + token_ids_0 #### 答案1: 1+1=2。
   拼接token_ids_0 + [gMASK, sop] #### 答案2.1: Hello! How can I assist you today?
   拼接token_ids_0 + [gMASK, sop] #### 答案2.2: 【问题】 【解答: 没有,tected,没有。 解答:protected,所以没有。
   拼接:[gMASK, sop] + token_ids_0 + [gMASK, sop] #### 答案3.1: the sum of 1 and 1 is 2.
   拼接:[gMASK, sop] + token_ids_0 + [gMASK, sop] #### 答案3.2: of course, 1+1=2
   拼接:[gMASK, sop] + token_ids_0 + [gMASK, sop] #### 答案3.3: 1+1=2。
   拼接:[gMASK, sop] + token_ids_0 + [BOS=1] #### 答案4.1: ""
   拼接第一轮剔除"[Round 1]",[gMASK, sop] + token_ids_0 #### 答案5: a />

环境配置

transformers==4.27.1
torch>=2.0
sentencepiece
cpm_kernels
mdtex2html
accelerate
protobuf
gradio

微调样例

地址: chatglm2_6b/ft_chatglm2

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

实验日志

微调日志(alpaca_gpt4forall)

chatglm2_6b/loss_gpt4forall_alpaca.png

推理样例(LoRA, R=8)

chatglm2_6b/predict_sample_1.png

chatglm2_6b/predict_sample_2.png

参考/感谢

免责申明

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

More Repositories

1

Keras-TextClassification

中文长文本分类、短句子分类、多标签分类、两句子相似度(Chinese Text Classification of Keras NLP, multi-label classify, or sentence classify, long or short),字词句向量嵌入层(embeddings)和网络层(graph)构建基类,FastText,TextCNN,CharCNN,TextRNN, RCNN, DCNN, DPCNN, VDCNN, CRNN, Bert, Xlnet, Albert, Attention, DeepMoji, HAN, 胶囊网络-CapsuleNet, Transformer-encode, Seq2seq, SWEM, LEAM, TextGCN
Python
1,700
star
2

nlp_xiaojiang

自然语言处理(nlp),小姜机器人(闲聊检索式chatbot),BERT句向量-相似度(Sentence Similarity),XLNET句向量-相似度(text xlnet embedding),文本分类(Text classification), 实体提取(ner,bert+bilstm+crf),数据增强(text augment, data enhance),同义句同义词生成,句子主干提取(mainpart),中文汉语短文本相似度,文本特征工程,keras-http-service调用
Python
1,508
star
3

Macropodus

自然语言处理工具Macropodus,基于Albert+BiLSTM+CRF深度学习网络架构,中文分词,词性标注,命名实体识别,新词发现,关键词,文本摘要,文本相似度,科学计算器,中文数字阿拉伯数字(罗马数字)转换,中文繁简转换,拼音转换。tookit(tool) of NLP,CWS(chinese word segnment),POS(Part-Of-Speech Tagging),NER(name entity recognition),Find(new words discovery),Keyword(keyword extraction),Summarize(text summarization),Sim(text similarity),Calculate(scientific calculator),Chi2num(chinese number to arabic number)
Python
631
star
4

nlg-yongzhuo

中文文本生成(NLG)之文本摘要(text summarization)工具包, 语料数据(corpus data), 抽取式摘要 Extractive text summary of Lead3、keyword、textrank、text teaser、word significance、LDA、LSI、NMF。(graph,feature,topic model,summarize tool or tookit)
Python
395
star
5

Macadam

Macadam是一个以Tensorflow(Keras)和bert4keras为基础,专注于文本分类、序列标注和关系抽取的自然语言处理工具包。支持RANDOM、WORD2VEC、FASTTEXT、BERT、ALBERT、ROBERTA、NEZHA、XLNET、ELECTRA、GPT-2等EMBEDDING嵌入; 支持FineTune、FastText、TextCNN、CharCNN、BiRNN、RCNN、DCNN、CRNN、DeepMoji、SelfAttention、HAN、Capsule等文本分类算法; 支持CRF、Bi-LSTM-CRF、CNN-LSTM、DGCNN、Bi-LSTM-LAN、Lattice-LSTM-Batch、MRC等序列标注算法。
Python
324
star
6

Pytorch-NLU

Pytorch-NLU,一个中文文本分类、序列标注工具包,支持中文长文本、短文本的多类、多标签分类任务,支持中文命名实体识别、词性标注、分词、抽取式文本摘要等序列标注任务。 Ptorch NLU, a Chinese text classification and sequence annotation toolkit, supports multi class and multi label classification tasks of Chinese long text and short text, and supports sequence annotation tasks such as Chinese named entity recognition, part of spee
Python
286
star
7

chatglm-maths

chatglm-6b微调/LORA/PPO/推理, 样本为自动生成的整数/小数加减乘除运算, 可gpu/cpu
Python
157
star
8

LLM-SFT

中文大模型微调(LLM-SFT), 数学指令数据集MWP-Instruct, 支持模型(ChatGLM-6B, LLaMA, Bloom-7B, baichuan-7B), 支持(LoRA, QLoRA, DeepSpeed, UI, TensorboardX), 支持(微调, 推理, 测评, 接口)等.
Python
103
star
9

Qwen-SFT

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

layoutlmv3-layoutxlm-chinese

chinese document classification of layoutlmv3 and layoutxlm
Python
33
star
11

Tookit-Sihui

Tookit-Sihui, a tool of some common algorithm, AI文本混合科学计算器(calculator-sihui), 句子词频-逆文本频率(TF-IDF),搜索BM25, 前缀树搜索关键词(trietree), 模板匹配-递归函数(func_recursive),中文数字转阿拉伯数字(chinese to number),阿拉伯数字转汉语数字, HMM, CRF
Python
23
star
12

Llama2-SFT

Llama2-SFT, Llama-2-7B微调(transformers)/LORA(peft)/推理
Python
16
star
13

gemma-sft

Gemma-SFT, gemma-2b/gemma-7b微调(finetune,transformers)/LORA(peft)/推理(inference)
Python
16
star
14

char_CNN_text_classification_Chinese2Pinyin

char_CNN_text_classification_Chinese2Pinyin,中文转拼音实例-基于字符的卷积神经网络-超短文本分类-主要代码为lc222的github项目,有HTTP访问等
Python
16
star
15

pytorch-loss

pytorch版损失函数,改写自科学空间文章,【通过互信息思想来缓解类别不平衡问题】、【将“softmax+交叉熵”推广到多标签分类问题】
12
star
16

ChatGLM3-SFT

chatglm3-6b, 微调/LORA/推理/单机多卡/deepspeed/支持多轮对话
Python
12
star
17

InternLM-SFT

InternLM-7B微调, SFT/LoRA, instruction finetune
Python
11
star
18

MacroGPT-Pretrain

macrogpt大模型全量预训练(1b3,32层), 多卡deepspeed/单卡adafactor
Python
10
star
19

Open-Information-Extraction-System

中文开放信息抽取系统, open-information-extraction-system, build open-knowledge-graph(SPO, subject-predicate-object) by pyltp(version==3.4.0)
Python
8
star
20

yongzhuo_spider

爬取政务Government数据、菜谱cookbook数据、百科QA问答数据等,爬虫
Python
8
star
21

Word-Dict

构建中文词频词典-搜索引擎式切词(create chinese word dict of freq by segnment of search)
Python
8
star
22

Text-Analysis

文本数据分析, Text-Analysis
Python
5
star
23

JavaLearning

A project of Java Learning、webmagic、mongo、arango、redis、mysql
Java
4
star
24

char-similar

汉字字形/拼音/语义相似度(单字, 可用于数据增强, CSC错别字检测识别任务(构建混淆集)) Chinese character font/pinyin/semantic similarity (single character, can be used for data augmentation, CSC misclassified character detection and recognition tasks (building confusion sets))
Python
4
star
25

leetcode-in-out

leetcode一些热门题型的python代码,包括输入输出。leetcode of hot, which Includes input and output.
Python
2
star
26

near-synonym

near-synonym, 中文反义词/近义词(antonym/synonym)工具包.
Python
2
star
27

pytorch-model-to-tensorflow

transformers-model of pytorch1.x to tensorflow2.x, deploy for tf-serving
Python
1
star
28

Tft-Preprocess

tensorflow-transformer(tft) of pre-processing and post-processing of text-classification
Python
1
star
29

web-demo

web-demo of http and ui
Python
1
star
30

qwen2-sft

Qwen1.5-SFT(阿里, Ali), Qwen_Qwen1.5-2B-Chat/Qwen_Qwen1.5-7B-Chat微调(transformers)/LORA(peft)/推理
Python
1
star