ChatGLM-6B icon indicating copy to clipboard operation
ChatGLM-6B copied to clipboard

[Help] <如何正确的构建input_ids、attention_mask、position_ids和labels>

Open Porraio opened this issue 1 year ago • 9 comments

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

Porraio avatar Mar 17 '23 09:03 Porraio

同问,请问解决了吗?照搬pretrain_glm.py不太成功

acadaiaca avatar Mar 17 '23 10:03 acadaiaca

应该是以下的构造方式。

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]]

Porraio avatar Mar 21 '23 08:03 Porraio

应该是以下的构造方式。

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]]

yxzero avatar Mar 22 '23 02:03 yxzero

@Porraio @yxzero 感觉porria大佬的是对的,论文里面也确实mask token 的position1 id 和 bos token 的position 1 id 是一样的。最近在学习 chatglm tuning, 感觉对label, position id 和 attention mask的构造有点晕

rookiebird avatar Mar 30 '23 09:03 rookiebird

而且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吧

JaheimLee avatar Mar 31 '23 09:03 JaheimLee

应该是以下的构造方式。

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]]

BiaoLiu2017 avatar Apr 12 '23 08:04 BiaoLiu2017

按照论文的话,应该是这样 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]]

king21guns avatar May 29 '23 09:05 king21guns

batch 训练时, position_ids要怎么进行padding

zhuzzjlu avatar Jun 12 '23 07:06 zhuzzjlu