-
Notifications
You must be signed in to change notification settings - Fork 617
adding variable length attention to llama3 8b #2000
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bd0c0fc
support varlen_attn for llama3
liangel-02 ea085c1
testing
liangel-02 b3f723d
fixing is_causal and .item()
liangel-02 d8a6254
correct loss/perf
liangel-02 9381ada
cleaning up
liangel-02 0012170
collapse batch outside of dataloader
liangel-02 4fef6eb
remove explicit mask def
liangel-02 0d32d5a
attention_type
liangel-02 4d80f4e
remove use_flex_attn
liangel-02 ab033dd
remove use_flex for all other models
liangel-02 2b1a40f
integration test
liangel-02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,9 +61,10 @@ def parallelize_deepseekv3( | |
| ({parallel_dims.tp}) and 2 * CP degree ({parallel_dims.cp}). | ||
| """ | ||
|
|
||
| use_flex_attn = getattr(model.model_args, "use_flex_attn", False) | ||
| if job_config.parallelism.context_parallel_degree > 1 and use_flex_attn: | ||
| raise NotImplementedError("CP support for FlexAttention is still in progress.") | ||
| attn_type = getattr(model.model_args, "attn_type", "sdpa") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: in python 3.11+ strenum seems like a good fit for this
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TorchTitan still sticks to 3.10 afaik. |
||
| use_flex_attn = attn_type == "flex" | ||
| if job_config.parallelism.context_parallel_degree > 1 and attn_type != "sdpa": | ||
| raise NotImplementedError("CP support is only supported for SDPA.") | ||
|
|
||
| if parallel_dims.tp_enabled: | ||
| enable_float8_linear = "float8" in job_config.model.converters | ||
|
|
@@ -84,7 +85,6 @@ def parallelize_deepseekv3( | |
| world_mesh["tp"], | ||
| loss_parallel=not job_config.parallelism.disable_loss_parallel, | ||
| enable_float8_tensorwise_tp=False, | ||
| use_flex_attn=use_flex_attn, | ||
| ) | ||
| maybe_enable_async_tp(job_config, world_mesh["tp"]) | ||
|
|
||
|
|
@@ -181,7 +181,6 @@ def apply_non_moe_tp( | |
| tp_mesh: DeviceMesh, | ||
| loss_parallel: bool, | ||
| enable_float8_tensorwise_tp: bool, | ||
| use_flex_attn: bool, | ||
| ): | ||
| """Apply tensor parallelism.""" | ||
| # 1. Parallelize the embedding and shard its outputs (which are the first | ||
|
|
@@ -211,18 +210,11 @@ def apply_non_moe_tp( | |
| PrepareModuleInput, | ||
| ) | ||
|
|
||
| if use_flex_attn: | ||
| attention_kernel_plan = prepare_module_input( | ||
| input_layouts=(Shard(1), Shard(1), Shard(1)), | ||
| desired_input_layouts=(Shard(1), Shard(1), Shard(1)), | ||
| use_local_output=True, | ||
| ) | ||
| else: | ||
| attention_kernel_plan = prepare_module_input( | ||
| input_layouts=(Shard(1), Shard(1), Shard(1)), | ||
| desired_input_layouts=(Shard(1), Shard(1), Shard(1)), | ||
| use_local_output=True, | ||
| ) | ||
liangel-02 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| attention_kernel_plan = prepare_module_input( | ||
| input_layouts=(Shard(1), Shard(1), Shard(1)), | ||
| desired_input_layouts=(Shard(1), Shard(1), Shard(1)), | ||
| use_local_output=True, | ||
| ) | ||
| # Apply tensor + sequence parallelism to every transformer block | ||
| # NOTE: At the cost of model code change, we can accelerate Sequence Parallel | ||
| # by folding (and unfolding) the batch dimension and the sequence dimension. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use per_op_sac like the test above.