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

[megatron gpt checkpoint conversion] causal mask requires pos_embed dimension #13735

Merged
merged 1 commit into from
Sep 26, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,11 @@ def convert_megatron_checkpoint(args, input_state_dict, config):

# The position embeddings.
pos_embeddings = embeddings["position_embeddings"]["weight"]
# Read the hidden dimension.
n_embed = pos_embeddings.size(1)
# DEBUG.
# Read the causal mask dimension (seqlen). [max_sequence_length, hidden_size]
n_ctx = pos_embeddings.size(0)
assert (
n_embed == heads * hidden_size_per_head
), f"detected mismatch n_embed={n_embed} != heads={heads}*hidden_size_per_head={hidden_size_per_head}"
n_ctx == config.n_ctx
), f"pos_embeddings.max_sequence_length={n_ctx} and config.n_ctx={config.n_ctx} don't match"
# Store the position embeddings.
output_state_dict["transformer.wpe.weight"] = pos_embeddings

Expand Down Expand Up @@ -175,7 +174,7 @@ def convert_megatron_checkpoint(args, input_state_dict, config):
) and weight_or_bias == "weight":

# Insert a tensor of 1x1xDxD bias.
causal_mask = torch.tril(torch.ones((n_embed, n_embed), dtype=torch.float16)).view(1, 1, n_embed, n_embed)
causal_mask = torch.tril(torch.ones((n_ctx, n_ctx), dtype=torch.float16)).view(1, 1, n_ctx, n_ctx)
output_state_dict[layer_name + ".attn.bias"] = causal_mask

# Insert a "dummy" tensor for masked_bias.
Expand Down