Macropodus commited on
Commit
8fbc569
·
1 Parent(s): 67ca627

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +135 -0
README.md CHANGED
@@ -1,3 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: cc-by-nc-4.0
3
  ---
 
1
+ # chatglm-maths
2
+ chatglm-6b微调/LORA/PPO/推理, 样本为自动生成的整数/小数加减乘除运算, 可gpu/cpu
3
+
4
+ ## 踩坑
5
+ ```python
6
+ 1. eps=1e-5(不要改小), 半精度float16, 以及LN采用的是Post-LN(泛化性更好) + DeepNorm, 【害, Attention前也有LN】目的是大模型为了防止梯度溢出等;
7
+ 2. 模型输入输出, 默认的tokenization_chatglm.py/modeling_chatglm.py不能用, 因为那是完全为生成generate设置的, 需要自己写好所有缩入参数, 或者机子改成适配的;
8
+ 2.1 ChatGLMModel中, get_masks()正常, get_position_ids()函数中‘context_length = seq.index(150004) + 1’ 改为 ‘context_length = len(seq)’;
9
+ 2.2 训练输入input_ids格式暂定为(训练后post-padding, 推理前pre-padding[tokenization_chatglm.py默认pre-padding])
10
+ x: prompt_1 + "_" + text_1 + "\n" + prompt_2 + [gMASK] + [BOS] + "_" + text_2 + [PAD]*N
11
+ 2.3 训练输入label_ids格式暂定为(CrossEntropyLoss默认忽略-100不参与计算loss)
12
+ y = [-100]*len(text_1) + [BOS] + text_2 + [EOS] + [-100]*N
13
+ 2.4 注意position/mask(自带的只是推理用的batch_size=1, 所以训练输入还得自己写), 可参考GLM-130的README.md, huozhe 查看GLM-1源码https://github.com/THUDM/GLM/blob/main/tasks/seq2seq/dataset.py
14
+ 3. 注意chatglm-6b权重是float16的, 不过计算loss时候会转成float32计算, 最后loss再转回float16更新梯度;
15
+ 4. ChatGLMTokenizer有时候会报奇奇怪怪的错误, 建议生成时候设置max_new_tokens, 最大{"max_new_tokens": 2048}; decode有时候会出现不存在id;
16
+ 5. 低秩自适应LORA, RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
17
+ 尝试 transformers升级到最新, get_peft_model后再.cuda(), device_map={'':torch.cuda.current_device()},
18
+ ```
19
+
20
+ ## 微调数据
21
+ 1. 原始数据来自[https://github.com/LYH-YF/MWPToolkit](https://github.com/LYH-YF/MWPToolkit)
22
+
23
+ 处理后的微调数据(算式/解方程)-MWP: [https://huggingface.co/datasets/Macropodus/MWP-Instruct](https://huggingface.co/datasets/Macropodus/MWP-Instruct)
24
+
25
+ 3. 大数加减乘除来自: [https://github.com/liutiedong/goat.git ](https://github.com/liutiedong/goat.git )
26
+
27
+
28
+ ## LoRA权重
29
+ ```shell
30
+ Baichuan-7B-GPT4ForALL: https://huggingface.co/Macropodus/MWP-Instruct
31
+ Bloomz-7B-GPT4ForALL: https://huggingface.co/Macropodus/MWP-Instruct
32
+ ChatGLM-6B-GPT4ForALL: https://huggingface.co/Macropodus/MWP-Instruct
33
+ LlaMA-7B-GPT4ForALL: https://huggingface.co/Macropodus/MWP-Instruct
34
+ ChatGLM-6B-MWP: https://huggingface.co/Macropodus/MWP-Instruct
35
+ ```
36
+
37
+ ## 数据集-中文
38
+ - [https://github.com/tatsu-lab/stanford_alpaca](https://github.com/tatsu-lab/stanford_alpaca)
39
+ - [https://github.com/LianjiaTech/BELLE](https://github.com/LianjiaTech/BELLE)
40
+ - [https://github.com/carbonz0/alpaca-chinese-dataset](https://github.com/carbonz0/alpaca-chinese-dataset)
41
+
42
+
43
+ ## 环境配置
44
+ ```shell
45
+ transformers>=4.26.1
46
+ cpm_kernels==1.0.11
47
+ icetk==0.0.4
48
+ torch>=1.10.1
49
+ rouge==1.0.1
50
+ nltk==3.6.6
51
+ peft>=0.2.0
52
+ numpy
53
+ tqdm
54
+
55
+ lion_pytorch
56
+ macropodus
57
+ trl>=0.4.1
58
+ ```
59
+
60
+ ## 微调-计算题
61
+ ```shell
62
+ lora
63
+ 微调: python c00_toy_lora_train_6b.py
64
+ 推理: python p00_toy_lora_predict_6b.py
65
+
66
+ ppo
67
+ 训练: python t10_toy_trl_train_ppo.py
68
+ 测试: python t10_toy_trl_predict_ppo.py
69
+
70
+ 6b
71
+ 微调: python c00_toy_cpu_train_6b.py
72
+ 推理: python p00_toy_cpu_predit_6b.py
73
+
74
+ small-layer
75
+ 微调: python c01_toy_cpu_train_small.py
76
+ 推理: python p01_toy_cpu_predict_small.py
77
+ ```
78
+
79
+
80
+ ## 参考/感谢
81
+ - [https://github.com/THUDM/ChatGLM-6B](https://github.com/THUDM/ChatGLM-6B)
82
+ - [https://github.com/THUDM/GLM](https://github.com/THUDM/GLM)
83
+ - [https://github.com/tatsu-lab/stanford_alpaca](https://github.com/tatsu-lab/stanford_alpaca)
84
+ - [https://github.com/LianjiaTech/BELLE](https://github.com/LianjiaTech/BELLE)
85
+ - [https://github.com/huggingface/peft](https://github.com/huggingface/peft)
86
+ - [https://github.com/mymusise/ChatGLM-Tuning](https://github.com/mymusise/ChatGLM-Tuning)
87
+ - [https://github.com/bojone/bert4keras](https://github.com/bojone/bert4keras)
88
+ - [trl](https://github.com/lvwerra/trl)
89
+ - [math23k](https://aclanthology.org/D17-1088)
90
+
91
+ ## 推理日志toy
92
+ ```cpu
93
+ generator_calculate_line: ('13+75=', '13+75=88')
94
+ tokenizer.vocab_size: 150344
95
+ eval: 0%| | 0/1 [00:00<?, ?it/s]batch_query: ['简便运算: 98+83= 剖析: 98+83=181']
96
+ batch_qtext_0: 简便运算: 98+83= 剖析:
97
+ batch_qans_0: 98+83=181
98
+ response_0: 98+83=171
99
+ {'rouge-1': 0.0, 'rouge-2': 0.0, 'rouge-l': 0.0, 'bleu': 0.0}
100
+ 请输入:
101
+ 25.31+86.35=
102
+ 请稍等...
103
+ 25.31+86.35=101.66
104
+ ```
105
+
106
+
107
+ ## 微调日志toy
108
+ ```cpu
109
+ generator_calculate_line: ('13+75=', '13+75=88')
110
+ tokenizer.vocab_size: 150344
111
+ Loading checkpoint shards: 100%|██████████████████████████████████████████���███████████████████████████████████████████████████████████████████████████████████████████████████| 8/8 [00:10<00:00, 1.31s/it]
112
+ transformer.word_embeddings.weight False
113
+ ......
114
+ transformer.layers.26.mlp.dense_4h_to_h.bias False
115
+ transformer.layers.27.input_layernorm.weight True
116
+ transformer.layers.27.input_layernorm.bias True
117
+ transformer.layers.27.attention.query_key_value.weight True
118
+ transformer.layers.27.attention.query_key_value.bias True
119
+ transformer.layers.27.attention.dense.weight True
120
+ transformer.layers.27.attention.dense.bias True
121
+ transformer.layers.27.post_attention_layernorm.weight True
122
+ transformer.layers.27.post_attention_layernorm.bias True
123
+ transformer.layers.27.mlp.dense_h_to_4h.weight True
124
+ transformer.layers.27.mlp.dense_h_to_4h.bias True
125
+ transformer.layers.27.mlp.dense_4h_to_h.weight True
126
+ transformer.layers.27.mlp.dense_4h_to_h.bias True
127
+ transformer.final_layernorm.weight True
128
+ transformer.final_layernorm.bias True
129
+ model.chat start
130
+ 13+75=88, but that's not the correct answer. The correct answer is 13+75=88, which is 90.
131
+ /anaconda3/envs/py371/lib/python3.7/site-packages/transformers/optimization.py:395: FutureWarning: This implementation of AdamW is deprecated and will be removed in a future version. Use the PyTorch implementation torch.optim.AdamW instead, or set `no_deprecation_warning=True` to disable this warning
132
+ FutureWarning,
133
+ epoch: 0%|
134
+
135
+
136
  ---
137
  license: cc-by-nc-4.0
138
  ---