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

add a100 test ground truth #8249

Merged
merged 8 commits into from
Apr 18, 2024
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
12 changes: 8 additions & 4 deletions paddlenlp/transformers/llama/modeling_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def scaled_dot_product_attention(

attn_output = paddle.matmul(attn_weights, value_states)
attn_output = attn_output.transpose([0, 2, 1, 3])
# [bsz, q_len, num_heads, head_dim] -> [bsz, q_len, num_heads * head_dim]
attn_output = attn_output.reshape([bsz, q_len, head_dim * num_heads])
return (attn_output, attn_weights) if output_attentions else attn_output

Expand Down Expand Up @@ -399,9 +400,10 @@ def forward(
alibi: Optional[paddle.Tensor] = None,
) -> Tuple[paddle.Tensor, Optional[paddle.Tensor], Optional[Tuple[paddle.Tensor]]]:
"""Input shape: Batch x Time x Channel"""
# [bs, seq_len, num_head * head_dim] -> [seq_len / n, bs, num_head * head_dim] (n is model parallelism)
# [bs, seq_len, num_head * head_dim] or [seq_len / n, bs, num_head * head_dim] (if sequence_parallel)
# enter tp region
if self.config.sequence_parallel:
# [seq_len / n, bs, num_head * head_dim] -> [seq_len, bs, num_head * head_dim] (if sequence_parallel)
hidden_states = dist.reshard(
hidden_states,
get_mesh(self.ipp),
Expand All @@ -422,6 +424,8 @@ def forward(
value_states = self.v_proj(hidden_states).reshape(shape=target_key_value_shape)

if self.config.sequence_parallel:
# [seq_len, bs, num_head * head_dim] -> [bs, seq_len, num_head * head_dim] (if sequence_parallel)
# FA and rope not support sequence first
query_states = paddle.transpose(query_states, [1, 0, 2, 3])
key_states = paddle.transpose(key_states, [1, 0, 2, 3])
value_states = paddle.transpose(value_states, [1, 0, 2, 3])
Expand Down Expand Up @@ -526,12 +530,12 @@ def forward(
else:
attn_output = outputs

# if sequence_parallel is true, out shape are [q_len / n, bs, num_head * head_dim]
# else their shape are [bs, q_len, num_head * head_dim], n is mp parallelism.
# [bs, q_len, num_head * head_dim]
attn_output = self.o_proj(attn_output)

# enter sp region
if self.config.sequence_parallel:
# [bs, q_len, num_head * head_dim] -> [q_len / n, bs, num_head * head_dim]
attn_output = paddle.transpose(attn_output, [1, 0, 2])
attn_output = dist.reshard(
attn_output,
Expand Down Expand Up @@ -595,7 +599,7 @@ def forward(
cache (`Tuple(paddle.Tensor)`, *optional*): cached past key and value projection states
"""

# [bs * seq_len, embed_dim] -> [seq_len * bs / n, embed_dim] (sequence_parallel)
# [bs, seq_len, embed_dim] or [seq_len / n, bs, embed_dim] (if sequence_parallel)
residual = hidden_states

hidden_states = self.input_layernorm(hidden_states)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ safetensors
tool_helpers
aistudio-sdk>=0.1.3
jinja2
regex
Loading
Loading