-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[Dev] MuonClip support (non-split version) on dev branch #2194
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
31 commits
Select commit
Hold shift + click to select a range
7391760
Add qk-clip on dev branch
BoxiangW 28b43f7
w/o EP working
BoxiangW 13532bc
Lint
BoxiangW 18b839a
Fix MLA usage and add logging for max_attention_score
BoxiangW 50db1cb
Removed Attention MuonClip since it is not correct. Added MLA MuonClip
BoxiangW 148fe7c
Add TE bug WAR and make sure MLA works
BoxiangW 462e1f2
Fix qkclip issue
BoxiangW af7c58b
Fix bug
BoxiangW 6a523cf
Fix TP usage
BoxiangW 8808701
Fix Lint
BoxiangW d8425ff
Fix import and error log
BoxiangW 5fdf802
lint
BoxiangW 0898ae0
Address comments
BoxiangW 1cfb40c
Lint
BoxiangW 5bd3c05
Added GQA QK Clipping
BoxiangW 87fc588
Lint
BoxiangW 5ee6ca3
Remove comment
BoxiangW 94fcd31
Rename max_score to max_logit
BoxiangW 2e19110
Change name
BoxiangW e520c81
Lint
BoxiangW 4bd9acf
Fix copyright
BoxiangW 605aae3
Move qk_clip fucntion into megatron/core
BoxiangW a2dc046
Add tests for qk_clip
BoxiangW 3e15d00
Lint and copyright
BoxiangW e13d178
Add te version checks into PR
BoxiangW 94b6589
Address comments
BoxiangW e79629d
Address comments
BoxiangW 264fddb
DP all reduce and switch to mul_ inplace op
BoxiangW 7fd7661
Merge branch 'dev' into boxiangw/muon_clip_dev
BoxiangW 841d62e
Update both main_params and non
BoxiangW b389ebf
Address comments
BoxiangW 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. | ||
|
|
||
| import torch | ||
|
|
||
| from megatron.core import mpu | ||
|
|
||
|
|
||
| def clip_qk(model, log_max_only=False) -> float: | ||
| """ | ||
| Clip the QK attention logits to the threshold, recommended for Muon optimizer. | ||
|
|
||
| Args: | ||
| model: The model to clip the QK attention logits, a list of model chunks. | ||
| log_only: Whether to only log the max attention logit, without updating the weights. | ||
|
|
||
| Returns: | ||
| The maximum attention logit, a float. | ||
| """ | ||
|
|
||
| with torch.no_grad(): | ||
| log_max_attention_logit = 0 | ||
| for model_chunk in model: | ||
| for transformer_layer in model_chunk.module.module.decoder.layers: | ||
| if hasattr(transformer_layer.self_attention, 'clip_qk'): | ||
| torch.distributed.all_reduce( | ||
| transformer_layer.self_attention.core_attention.current_max_attn_logits, | ||
| op=torch.distributed.ReduceOp.MAX, | ||
| group=mpu.get_data_parallel_group(with_context_parallel=True), | ||
| ) | ||
| log_max_attention_logit = max( | ||
| log_max_attention_logit, | ||
| torch.max( | ||
| transformer_layer.self_attention.core_attention.current_max_attn_logits | ||
| ).item(), | ||
| ) | ||
| if not log_max_only: | ||
| transformer_layer.self_attention.clip_qk() | ||
|
|
||
| return log_max_attention_logit |
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
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.
Uh oh!
There was an error while loading. Please reload this page.