Repository navigation
QK logits clipping (non-split version) #1929
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
Changes from 28 commits
0ef342c
a5d2ea8
978b99b
b77a6d6
a83b68c
eae6a5a
c370cdd
6f8f77d
527075f
3cebc1f
e3c468f
ef995ea
7f5f1e2
65fc829
75ee38c
a1c0ff6
762bdb5
ba5c073
7917e68
495f58d
55cc00d
f54fbdd
9095615
4b490cc
0453ded
1bb0407
b63c573
bdda5e9
bd0436b
646aea5
4d16029
2b890d0
95fdba3
6562a52
a2e7407
d83c38e
dd82679
eed3c2d
99c7631
24e6c88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. | ||
|
|
||
| import torch | ||
|
|
||
|
|
||
| def clip_qk(model) -> 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. | ||
|
|
||
| Returns: | ||
| The maximum attention logit, a float. | ||
| """ | ||
|
|
||
| log_max_attention_logit = 0 | ||
| for model_chunk in model: | ||
|
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. i dont remember, is model always a list?
Contributor
Author
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. According to https://github.com/NVIDIA/Megatron-LM/pull/1929/files#diff-7fc2a91343e49be3c1705b8237bbe437029132d8826e5c963e1b0b84d457bc38L1250. I think it is true for MLM, is it true for MBridge as well? |
||
| for transformer_layer in model_chunk.module.module.decoder.layers: | ||
| if hasattr(transformer_layer.self_attention, 'clip_qk'): | ||
| log_max_attention_logit = max( | ||
| log_max_attention_logit, | ||
| torch.max( | ||
| transformer_layer.self_attention.core_attention.current_max_attn_logits | ||
| ).item(), | ||
| ) | ||
| transformer_layer.self_attention.clip_qk() | ||
|
|
||
| return log_max_attention_logit | ||
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.
what if
not is_te_min_versionbut config.qk_clip? might raise an errorThere 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.
Right now it will raise an error if te version is wrong