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
Show file tree
Hide file tree
Changes from all 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 = np.ones(seq_length, dtype="int64")
labels = np.array(labels, dtype="int64")
return [tokens, loss_mask, attention_mask, position_ids, labels]

Expand Down
7 changes: 3 additions & 4 deletions model_zoo/gpt/run_pretrain_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ def create_data_holder(args):
loss_mask = paddle.static.data(name="loss_mask",
shape=[-1, args.max_seq_len],
dtype="float32")
attention_mask = paddle.static.data(
name="attention_mask",
shape=[-1, 1, args.max_seq_len, args.max_seq_len],
dtype="float32")
attention_mask = paddle.static.data(name="attention_mask",
shape=[-1, args.max_seq_len],
dtype="int64")
position_ids = paddle.static.data(name="position_ids",
shape=[-1, args.max_seq_len],
dtype="int64")
Expand Down