Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gpt example attention mask #3240

Merged
merged 8 commits into from
Sep 26, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions model_zoo/gpt/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,17 +442,13 @@ def _construct_sample(self, tokens):
labels = tokens[1:]
tokens = tokens[:-1]
seq_length = len(tokens)
# Attention mask for the attention calulate
attention_mask = np.tri(seq_length, seq_length).reshape(
(1, seq_length, seq_length))

# The pad and eos tokens do not contribute the loss
loss_mask = np.ones(seq_length, dtype="float32")
loss_mask[np.where(np.array(tokens) == self.eos_id)] = 0.0
position_ids = np.arange(0, seq_length, dtype="int64")

attention_mask = (attention_mask - 1.0) * 1e9
attention_mask = attention_mask.astype("float32")
attention_mask = loss_mask
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还是有点不妥,attention_mask = loss_mask 屏蔽掉了 eos的token,但是很多下游,是用eos表示一些token的生成和结束。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

经沟通,该example没有做pad,所以attention mask全1即可。

labels = np.array(labels, dtype="int64")
return [tokens, loss_mask, attention_mask, position_ids, labels]

Expand Down