Skip to content

QK logits clipping (non-split version) - #1929

Merged
BoxiangW merged 40 commits into
NVIDIA:mainfrom
BoxiangW:boxiangw/muon-clip
Dec 10, 2025
Merged

QK logits clipping (non-split version)#1929
BoxiangW merged 40 commits into
NVIDIA:mainfrom
BoxiangW:boxiangw/muon-clip

Conversation

@BoxiangW

Copy link
Copy Markdown
Contributor

Added MLA and MHA(GQA) clipping support

Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
@BoxiangW
BoxiangW requested review from a team as code owners October 24, 2025 22:00
@copy-pr-bot

copy-pr-bot Bot commented Oct 24, 2025

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@BoxiangW BoxiangW self-assigned this Oct 24, 2025
@BoxiangW

Copy link
Copy Markdown
Contributor Author

TE's NVIDIA/TransformerEngine#2195 (2.9.0) is needed for this PR

Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
@skyw

skyw commented Oct 28, 2025

Copy link
Copy Markdown
Contributor

TE's NVIDIA/TransformerEngine#2195 (2.9.0) is needed for this PR

It has been merged.

@BoxiangW BoxiangW added Expert Review [deprecated] Apply this label to indicate that your PR is ready for expert review. Run tests labels Oct 31, 2025
@BoxiangW BoxiangW added this to the Core 0.15 milestone Oct 31, 2025
@BoxiangW

BoxiangW commented Nov 3, 2025

Copy link
Copy Markdown
Contributor Author

/ok to test 7917e68

@BoxiangW

Copy link
Copy Markdown
Contributor Author

/ok to test b63c573

Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
if config.qk_clip and is_te_min_version("2.9.0"):
# TE 2.9.0 introduces return_max_logit for qk-clip getting the max attention logits
extra_kwargs["return_max_logit"] = True
self.current_max_attn_logits = None

Copy link
Copy Markdown
Contributor

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_version but config.qk_clip? might raise an error

Copy link
Copy Markdown
Contributor Author

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

Comment thread megatron/core/optimizer/qk_clip.py Outdated
"""

log_max_attention_logit = 0
for model_chunk in model:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i dont remember, is model always a list?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
@BoxiangW

Copy link
Copy Markdown
Contributor Author

/ok to test 95fdba3

@deepakn94

Copy link
Copy Markdown
Contributor

Can we re-name this PR? It should just be "QK logits clipping" or something similar?

Comment thread megatron/core/optimizer/qk_clip.py Outdated

import torch

from megatron.core import mpu

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should use parrallel_state, mpu is a legacy name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this, changed to parrallel_state instead

Comment thread megatron/core/optimizer/qk_clip.py Outdated
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),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there any way to get this group in via args? We are trying to move away from global process groups.

Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
@BoxiangW

BoxiangW commented Dec 3, 2025

Copy link
Copy Markdown
Contributor Author

/ok to test 6562a52

@BoxiangW

BoxiangW commented Dec 8, 2025

Copy link
Copy Markdown
Contributor Author

/ok to test a2e7407

@BoxiangW

BoxiangW commented Dec 9, 2025

Copy link
Copy Markdown
Contributor Author

/ok to test d83c38e

@BoxiangW

BoxiangW commented Dec 9, 2025

Copy link
Copy Markdown
Contributor Author

/ok to test dd82679

@BoxiangW

BoxiangW commented Dec 9, 2025

Copy link
Copy Markdown
Contributor Author

/ok to test eed3c2d

@BoxiangW

BoxiangW commented Dec 9, 2025

Copy link
Copy Markdown
Contributor Author

/ok to test 99c7631

@BoxiangW

Copy link
Copy Markdown
Contributor Author

/ok to test 24e6c88

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

complexity: medium Final Review PR is in the "final review" stage Run tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants