Skip to content

test: pin AdaLNContinuous scale/shift order and gradients (PRPUNDIT-17) - #1100

Merged
Xiaoming-AMD merged 10 commits into
mainfrom
testgap/PRPUNDIT-17
Sep 6, 2026
Merged

test: pin AdaLNContinuous scale/shift order and gradients (PRPUNDIT-17)#1100
Xiaoming-AMD merged 10 commits into
mainfrom
testgap/PRPUNDIT-17

Conversation

@jiagaoxiang

Copy link
Copy Markdown
Collaborator

Same-repo refile of #1087 so Primus-CI-TAS runs against AMD-AGI/Primus (fork PRs do not receive Docker Hub credentials, so build-docker / torch unit tests never ran).

This PR was created by dougljia via Test Gap Resolver.

Summary

  • Extends tests/unit_tests/backends/megatron/diffusion/test_flux_normalization.py with CPU TestAdaLNContinuousForwardPlainOps: independent norm(x) * (1 + scale) + shift oracle, zero-modulation LayerNorm reduction, and NeMo chunk order (first half = scale, second half = shift).
  • Adds a fused-path CUDA check against the same formula, plus a backward-flow assertion on x and cond.
  • Existing CUDA shape / invalid-norm tests are unchanged.

Closes test gap PRPUNDIT-17.

Test plan

  • GPU CI: pytest tests/unit_tests/backends/megatron/diffusion/test_flux_normalization.py (plain-ops CPU class + fused CUDA class; needs megatron.core)
  • black --check / isort --profile black on the edited file

jiagaoxiang and others added 8 commits September 3, 2026 16:44
Closes PRPUNDIT-17. Plain-ops oracle plus fused-path CUDA check for
NeMo chunk order, plus a backward-flow assertion.
Copilot review flagged that the fused-forward test only checked
forward numerics, leaving the "pin gradients" goal covered only by
the CPU plain-ops path (which doesn't exercise the
primus::fused_ln_modulate custom autograd op). Add a CUDA test that
runs backward() through the fused path and asserts finite, nonzero
gradients reach both x and cond, mirroring the existing CPU backward
test.
… tests

Copilot flagged that torch.manual_seed(0) ran after AdaLNContinuous(...)
construction in test_fused_forward_matches_plain_ops_formula and
test_forward_matches_manual_layernorm_and_modulate, so the modulation
Linear's parameter init wasn't covered by the seed. Move the seed call
before construction in both so the whole test (module init + inputs) is
reproducible.
The previous snippet-based commit (899c316) miscounted the replaced
line range and left a duplicated `cond = torch.randn(...)` line.
Drop the stray duplicate.
The previous snippet-based fix (bf5ed50) removed a duplicated `cond =
torch.randn(...)` line but missed a duplicate `output = adaln(x, cond)`
call left in test_forward_matches_manual_layernorm_and_modulate by the
same line-range mistake. Drop the redundant second call.
My prior snippet-based edit inserted a bare literal "213" line and
still left the duplicate `output = adaln(x, cond)` call in place,
which would be a SyntaxError. Remove both, leaving a single call.
…tions

Copilot review (PR #1087) flagged that `.sum().backward()` can yield an
exactly-zero gradient under LayerNorm's zero-mean-per-token property if
modulation ever becomes zero/constant (e.g. a future zero-init), making
the gradient-flow assertions fragile for the wrong reason. Switch both
backward tests to `.pow(2).sum().backward()`, which cannot cancel to
zero unless every output element is exactly zero.
Addresses Copilot review feedback (review #5105410572): the fused
forward/backward tests validated numerics but never confirmed the
module actually dispatched to primus::fused_ln_modulate, so a future
default flip to the plain-ops branch could silently stop exercising
the fused kernel while these tests kept passing.

Copilot AI 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.

🟢 Approval recommended

Only a minor test-naming inconsistency was found; the functional intent of the added coverage looks sound.

Pull request overview

Adds targeted unit tests to lock in AdaLNContinuous’s NeMo-aligned (scale, shift) chunk order and to validate both forward numerics and gradient flow for the fused CUDA path, while also covering a CPU plain-ops fallback path.

Changes:

  • Add CUDA tests asserting fused AdaLNContinuous matches the reference formula norm(x) * (1 + scale) + shift.
  • Add CUDA/CPU backward tests asserting gradients flow to both the input tensor and conditioning embedding.
  • Add CPU-only plain-ops tests (via config.adaln_plain_ops=True) to validate formula equivalence, zero-modulation reduction to LayerNorm, and chunk ordering.
File summaries
File Description
tests/unit_tests/backends/megatron/diffusion/test_flux_normalization.py Extends AdaLNContinuous test coverage for fused CUDA forward/backward behavior and adds CPU plain-ops oracle tests for formula/order invariants.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/unit_tests/backends/megatron/diffusion/test_flux_normalization.py Outdated
@jiagaoxiang

Copy link
Copy Markdown
Collaborator Author

TestIntel PR Steward: Checked the ci_failed flag on head 70e8655.

The failed build-docker (3.12) check (run 33791094932, 2026-09-03) belongs to the pre-refile context for this same commit — the build step failed in ~1s with no actual build log, consistent with the fork-PR-lacks-Docker-Hub-credentials issue this PR's description already calls out (that's the whole reason for the same-repo refile of #1087).

Since this PR was opened, a fresh Primus-CI-TAS run (33895312837) has already started against the correct same-repo context: code-lint and dependency-review are green, and build-docker (3.12) / run-unittest-jax are queued and awaiting a runner. No code defect here, so no push or manual rerun needed — I'll keep watching this new run and act if it comes back red for a real reason.

…1100)

The test only asserts gradients on x and cond, not on the
adaLN_modulation parameters, so "reaches_input_and_modulation" was
misleading. Rename to reaches_input_and_conditioning to match the
sibling fused-path test's naming.
Copilot AI review requested due to automatic review settings September 4, 2026 16:36
@jiagaoxiang

Copy link
Copy Markdown
Collaborator Author

TestIntel PR Steward: Follow-up on this poll (ci_failed, comments, reviews):

  • Copilot review (review comment on test_flux_normalization.py:256): correct — test_forward_backward_reaches_input_and_modulation only asserted gradients on x and cond, never on adaLN_modulation's parameters, so the name overclaimed what the test covers. Renamed it to test_forward_backward_reaches_input_and_conditioning (matching the sibling fused-path test's naming) in fd167a4. Not adding a separate assertion on the modulation-layer parameter grads, since that's out of scope for what this test gap (PRPUNDIT-17) is pinning down.
  • CI: the build-docker (3.12) failure this poll flagged belongs to the earlier pre-refile run already explained in my prior comment (fork PRs lack Docker Hub creds). The same-repo Primus-CI-TAS run is still queued on the new head fd167a4; I'll keep watching it.

No other open threads.

Copilot AI 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.

🟢 Approval recommended

The PR is test-only and the added checks align with the stated contract; remaining feedback is limited to minor test-oracle/convention improvements.

Review details

Suppressed comments (2)

Previously missed (2) — in code that hasn't changed since the last review.

tests/unit_tests/backends/megatron/diffusion/test_flux_normalization.py:163

  • For numeric tensor comparisons, the diffusion unit tests elsewhere commonly use torch.testing.assert_close(...) (gives better diagnostics than assert torch.allclose(...)). Consider switching this assertion (and the other new allclose assertions below) to assert_close.
    tests/unit_tests/backends/megatron/diffusion/test_flux_normalization.py:221
  • This test claims to validate a manual LayerNorm+modulation oracle, but expected is currently computed via adaln.norm(x), which couples the oracle to the module under test. Using torch.nn.functional.layer_norm here would better match the test intent and PR summary (independent plain-ops formula).
  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@jiagaoxiang

Copy link
Copy Markdown
Collaborator Author

TestIntel PR Steward: Follow-up on this poll (new reviews entry, head still fd167a4):

  • Copilot review (pullrequestreview-5115661678, 🟢 approval recommended, 0 new inline comments, 2 suppressed "previously missed" nits on unchanged code):
    • test_flux_normalization.py:163 (test_fused_forward_matches_plain_ops_formula) — suggests torch.testing.assert_close over assert torch.allclose(...). Style preference only, both give a pass/fail on the same formula check; skipping, no functional gap.
    • test_flux_normalization.py:221 (test_forward_matches_manual_layernorm_and_modulate) — notes expected reuses adaln.norm(x) rather than an independent F.layer_norm call. That test's job is to pin the *(1+scale)+shift formula and chunk order, not re-derive LayerNorm; the independent-LayerNorm check already exists as its own test (test_forward_zero_modulation_weight_is_pure_layernorm, which does use torch.nn.functional.layer_norm). Skipping as a speculative refactor that doesn't add coverage.
    • No thread exists for either (GitHub suppressed them as inline comments), so no reply target — recording the decision here instead.
  • No other new comments or reviews since my last update. CI is unchanged: still watching the same-repo Primus-CI-TAS run for build-docker (3.12) / run-unittest-jax on fd167a4.

No push needed this round.

Copilot AI review requested due to automatic review settings September 6, 2026 23:17
@Xiaoming-AMD
Xiaoming-AMD merged commit de4f536 into main Sep 6, 2026
5 of 6 checks passed

Copilot AI 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.

🟢 Approval recommended

The changes are isolated to test additions that directly exercise the intended AdaLNContinuous contracts (formula, chunk order, and gradient flow) without introducing production-code risk.

Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants