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

[AutoParallel] Add sequence parallel for llama #59822

Merged
merged 24 commits into from
Dec 9, 2023

Conversation

GhostScreaming
Copy link
Contributor

@GhostScreaming GhostScreaming commented Dec 8, 2023

PR types

Others

PR changes

Others

Description

Pcard-73145

Add sequence parallel for llama.

Copy link

paddle-bot bot commented Dec 8, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@GhostScreaming GhostScreaming changed the title [WIP] Add sequence parallel for llama. [AutoParallel] Add sequence parallel for llama Dec 8, 2023
@@ -192,6 +192,26 @@ def forward(
shape=target_key_value_shape
)

if self.config.sequence_parallel:
query_states = dist.reshard(
Copy link
Contributor

Choose a reason for hiding this comment

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

reshard before projection while tranpose after projection

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thx~

@@ -238,6 +250,12 @@ def forward(
else:
attn_output = outputs

if self.config.sequence_parallel:
attn_output = paddle.transpose(attn_output, [1, 0, 2])
attn_output = dist.reshard(
Copy link
Contributor

Choose a reason for hiding this comment

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

reshard should after out_projection

@@ -731,6 +772,13 @@ def forward(

# if labels is None,means we need full output, instead of tensor_parallel_output
logits = self.lm_head(hidden_states)
if self.config.sequence_parallel:
Copy link
Contributor

Choose a reason for hiding this comment

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

    # reshard should before lm_head
    if self.config.sequence_parallel:
        hidden_states = dist.reshard(
            hidden_states, get_mesh(-1), [dist.Shard(1), dist.Replicate()]
        )
        # [S, B, H] -> [B, S, H]
        hidden_states = paddle.transpose(hidden_states, [1, 0, 2])

    logits = self.lm_head(hidden_states)

Copy link
Contributor

@JZ-LIANG JZ-LIANG left a comment

Choose a reason for hiding this comment

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

LGTM

@JZ-LIANG JZ-LIANG merged commit be090bd into PaddlePaddle:develop Dec 9, 2023
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants