ChatGLM-6B
ChatGLM-6B copied to clipboard
[Help] <如何正确的构建input_ids、attention_mask、position_ids和labels>
Is there an existing issue for this?
- [X] I have searched the existing issues
Current Behavior
参照GLM论文,假如token1 token2 是source, token3 token4是target 那么训练的时候:
input_ids是 [pad, pad, token1, token2, gmask, sop, token3, token4]
labels是 [0, 0, 0, 0, 0, token3, token4, eop]
position_ids是 [[0, 1, 2, 3, 4, 4, 4, 4], [0, 0, 0, 0, 0, 1, 2, 3]]
请问是这样的吗,另外attention_mask也要对应在sop前双向,sop(包含)后单向吗。 十分感谢。
Expected Behavior
No response
Steps To Reproduce
这样构造后,似乎LOSS不太对
Environment
transformers, deepspeed
Anything else?
No response
同问,请问解决了吗?照搬pretrain_glm.py不太成功
应该是以下的构造方式。
input_ids是 [token1, token2, gmask, sop, token3, token4, eop]
labels是 [-100, -100, -100, -100, token3, token4, eop]
position_ids是 [[0, 1, 2, 2, 2, 2, 2, 2], [0, 0, 0, 1, 2, 3, 4]]
应该是以下的构造方式。
input_ids是 [token1, token2, gmask, sop, token3, token4, eop]
labels是 [-100, -100, -100, -100, token3, token4, eop]
position_ids是 [[0, 1, 2, 2, 2, 2, 2, 2], [0, 0, 0, 1, 2, 3, 4]]
position_ids是不是 [[0, 1, 2, 3, 2, 2, 2, 2], [0, 0, 0, 1, 2, 3, 4]]
@Porraio @yxzero 感觉porria大佬的是对的,论文里面也确实mask token 的position1 id 和 bos token 的position 1 id 是一样的。最近在学习 chatglm tuning, 感觉对label, position id 和 attention mask的构造有点晕
而且gmask设置True False那里看着也很迷惑
https://huggingface.co/THUDM/chatglm-6b/blob/9c7416d83483e5917034c4db70ec7d5512ac56ca/modeling_chatglm.py#L1084
以及
https://huggingface.co/THUDM/chatglm-6b/blob/9c7416d83483e5917034c4db70ec7d5512ac56ca/modeling_chatglm.py#L1056
应该是if gmask
才设置mask_positions吧
应该是以下的构造方式。
input_ids是 [token1, token2, gmask, sop, token3, token4, eop]
labels是 [-100, -100, -100, -100, token3, token4, eop]
position_ids是 [[0, 1, 2, 2, 2, 2, 2, 2], [0, 0, 0, 1, 2, 3, 4]]
这个地方有点问题吧,按照官方代码应该如下: input_ids是 [token1, token2, gmask, sop, token3, token4, eop]
labels是 [-100, -100, -100, sop, token3, token4, eop]
position_ids是 [[0, 1, 2, 2, 2, 2, 2, 2], [0, 0, 0, 1, 2, 3, 4]]
按照论文的话,应该是这样 input_ids是 [token1, token2, gmask, sop, token3, token4]
labels是 [-100, -100, -100, token3, token4, eop]
position_ids是 [[0, 1, 2, 2, 2, 2], [0, 0, 0, 1, 2, 3]]
batch 训练时, position_ids要怎么进行padding