Skip to content

Bump FLA to 0.5.1 and integrate GDN2 kernels - #5765

Merged
xuantengh merged 12 commits into
NVIDIA:mainfrom
xuantengh:xuantengh/gdn2
Aug 11, 2026
Merged

xuantengh merged 12 commits into
NVIDIA:mainfrom
xuantengh:xuantengh/gdn2

Conversation

@xuantengh

@xuantengh xuantengh commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor
  • I, the PR author, have personally reviewed every line of this PR.

What does this PR do?

Convergence: see the wandb run.

Fixes #4955

@xuantengh
xuantengh requested a review from a team as a code owner July 12, 2026 13:16
@xuantengh
xuantengh requested a review from a team July 12, 2026 13:17
@xuantengh
xuantengh requested review from a team as code owners July 12, 2026 13:17
@copy-pr-bot

copy-pr-bot Bot commented Jul 12, 2026

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.

@svcnvidia-nemo-ci
svcnvidia-nemo-ci marked this pull request as draft July 12, 2026 13:17
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been automatically converted to draft because all PRs must start as drafts.

When you are ready for review, click Ready for Review to begin the review process. This will:

  1. Add the oncall reviewer (optional reviewer)
  2. Add required review teams based on your changes

See the contribution guide for more details.

@xuantengh

Copy link
Copy Markdown
Contributor Author

/claude review

@claude claude Bot left a comment

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.

Light review — one inline nit and two items to double-check.

1. uv.lock not updated. pyproject.toml bumps flash-linear-attention from ~=0.4.0 to flash-linear-attention[cuda]>=0.5.1, but uv.lock is not part of this PR. Per the contribution workflow, uv.lock must be regenerated (uv lock inside the container) when pyproject.toml dependencies change, otherwise uv sync --locked fails in CI. Please confirm the lock file is committed (it may just be missing from the diff view).

2. chunk_gdn2 not reset to None on import failure — see inline comment on the except ImportError block.

Otherwise the change looks clean and well-tested: test_module_construction, test_gpu_forward_backward, the parametrized _prepare_input_for_gated_delta_rule coverage, and the dedicated test_parallel_gated_delta_net2_correctness give good coverage of the new GDN2 path across TP/SP/CP.

@xuantengh

Copy link
Copy Markdown
Contributor Author

/claude review

@claude

claude Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

test_jit_compiled_helpers is broken — mismatch with the actual return contract of _prepare_input_for_gated_delta_rule.

The refactored method returns a single dict that includes the output gate under the key "gate", and forward() relies on exactly that (gate = kernel_inputs.pop("gate") at gated_delta_net.py:519). But the test unpacks the result as a 2-tuple:

# tests/unit_tests/ssm/test_gated_delta_net.py:352
kernel_inputs, gate_out = gdn._prepare_input_for_gated_delta_rule(
    qkv, gate, gate_feats, A_log_mock, dt_bias_mock, batch, seq_len
)

Unpacking a dict into two names raises ValueError: too many values to unpack, so this test errors out. Even after fixing the unpack, assert set(kernel_inputs.keys()) == expected_keys (line 356) would still fail because expected_keys omits "gate", which the real dict contains.

Suggested reconciliation to match the implementation (which forward() depends on):

kernel_inputs = gdn._prepare_input_for_gated_delta_rule(
    qkv, gate, gate_feats, A_log_mock, dt_bias_mock, batch, seq_len
)
gate_out = kernel_inputs["gate"]

assert set(kernel_inputs.keys()) == expected_keys | {"gate"}

Relatedly, the docstring is inaccurate: the signature is -> dict[str, torch.Tensor] and it returns one dict, but the Returns: block still describes tuple[dict[str, Tensor], Tensor] with the gate as a separate tuple element. Please update it to describe the single dict (with gate as a key).

@xuantengh
xuantengh marked this pull request as ready for review July 14, 2026 09:44
@xuantengh

Copy link
Copy Markdown
Contributor Author

/claude review

@xuantengh

Copy link
Copy Markdown
Contributor Author

/ok to test b22c5cf

Comment thread megatron/core/ssm/gated_delta_net.py Outdated
from fla.modules.convolution import causal_conv1d
from fla.modules.l2norm import l2norm
from fla.ops.gated_delta_rule import chunk_gated_delta_rule
from fla.ops.gdn2.chunk import chunk_gdn2

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.

The matching except ImportError block (lines 51-56) sets causal_conv1d, l2norm, and chunk_gated_delta_rule to None, but does not set chunk_gdn2 = None. If FLA is installed but too old to have fla.ops.gdn2.chunk (or FLA is absent entirely), this import fails and chunk_gdn2 is never bound. The GDN2 guard in __init__ (assert chunk_gdn2 is not None) then raises NameError: name 'chunk_gdn2' is not defined instead of the intended friendly AssertionError message about requiring flash-linear-attention >= 0.5.1.

Please add chunk_gdn2 = None to the except ImportError block:

except ImportError:
    causal_conv1d = None
    l2norm = None
    chunk_gated_delta_rule = None
    chunk_gdn2 = None

    HAVE_FLA = False

@claude claude Bot left a comment

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.

Light review — the changes add a GDN2 variant to the gated delta net layer, with good test coverage (parametrized construction, forward/backward, correctness, and jit-helper tests for both variants).

One correctness issue flagged inline: the new chunk_gdn2 import isn't defaulted to None in the except ImportError block, so the GDN2 availability guard would raise NameError instead of the intended AssertionError when FLA is missing or too old.

Everything else looks consistent — config plumbing, FLOPs accounting, and sharded_state_dict all handle the new variant symmetrically.

@xuantengh xuantengh changed the title Bump FLA to 0.5.1 and integrate GDN2 kernels Bump FLA to 0.5.2 and integrate GDN2 kernels Jul 29, 2026

@santhnm2 santhnm2 left a comment

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.

Approved for transformer changes

Comment on lines +1351 to +1358
if self.experimental_attention_variant in ("gated_delta_net", "gdn2"):
# gdn2 may also be enabled for GDN layers built via the hybrid layer pattern
# symbol 'G', where linear_attention_freq is unused; the GPT experimental
# attention route raises a clear error downstream if it is missing.
if self.experimental_attention_variant == "gated_delta_net":
assert (
self.linear_attention_freq is not None
), f"linear_attention_freq must be set for linear gated_delta_net."

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 think it's ok to keep because the GPT experimental attention path is still active even if no new features are being added; we can remove if and when the GPT path is deleted entirely

Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
@xuantengh

Copy link
Copy Markdown
Contributor Author

/ok to test 63aebd9

Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
@xuantengh

Copy link
Copy Markdown
Contributor Author

/ok to test a5051b2

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/31445864937

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/31447097726

This branch was previously deployed

2 inactive deployments
public — a5051b29 Deployed Aug 10, 2026 by copy-pr-bot[bot] via finalize / publish-docs #5601
test — a5051b29 Deployed Aug 10, 2026 by copy-pr-bot[bot] via cicd-wait-in-queue #18544
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved All necessary approvals have been made complexity: medium Run functional tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature-request] Add Megatron Core support for GatedDeltaNet2

10 participants