Skip to content

[TTS] Add comprehensive MoE dispatch unit tests with golden-value regression checks - #15698

Merged
blisc merged 1 commit into
NVIDIA-NeMo:mainfrom
XuesongYang:xueyang/pr-unit-test-moe
Jun 3, 2026
Merged

blisc merged 1 commit into
NVIDIA-NeMo:mainfrom
XuesongYang:xueyang/pr-unit-test-moe

Conversation

@XuesongYang

Copy link
Copy Markdown
Collaborator

Add behavioral and golden-value tests for PositionwiseConvFFMoE.forward():

  • Determinism (same seed → identical output across re-init)
  • Gradient flow (backward produces non-zero grads for router + experts)
  • Edge cases: all-padding, single token, top_k == num_experts
  • Bias / no-bias configurations
  • Per-sample padding isolation
  • Golden-value regression: expected output_sum, logits_sum, first expert indices, and output[0,0,:4] captured from the current sequential implementation under seed=42, verified with atol=1e-5

These tests lock in the numerical behaviour of the forward pass so that any future refactoring (e.g. batched dispatch) can be validated against the same golden values.

…n checks

Add behavioral and golden-value tests for PositionwiseConvFFMoE.forward():
- Determinism (same seed → identical output across re-init)
- Gradient flow (backward produces non-zero grads for router + experts)
- Edge cases: all-padding, single token, top_k == num_experts
- Bias / no-bias configurations
- Per-sample padding isolation
- Golden-value regression: expected output_sum, logits_sum, first expert
  indices, and output[0,0,:4] captured from the current sequential
  implementation under seed=42, verified with atol=1e-5

These tests lock in the numerical behaviour of the forward pass so that
any future refactoring (e.g. batched dispatch) can be validated against
the same golden values.

Signed-off-by: Xuesong Yang <1646669+XuesongYang@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 13, 2026 20:56
@copy-pr-bot

copy-pr-bot Bot commented May 13, 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.

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.

Pull request overview

Adds MoE forward-pass regression and behavioral tests for TTS transformer modules, focused on PositionwiseConvFFMoE routing, padding, gradients, and golden numerical outputs.

Changes:

  • Adds golden-value fixtures for several MoE expert/top-k/bias/padding configurations.
  • Adds gradient-flow and all-padding behavior tests.
  • Adds parametrized golden-value regression checks for output sums, router logits, expert indices, and sample output elements.
Comments suppressed due to low confidence (1)

tests/collections/tts/modules/test_transformer_2501.py:1314

  • router_probs is unpacked but never used. Since flake8 selects F841 for unused local variables in changed files, this test will fail linting unless this value is either asserted or ignored with _.
            output, router_logits, router_probs, expert_indices = moe_ffn(x, x_mask)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

x_mask = torch.zeros(self.batch_size, self.seq_len)

with torch.no_grad():
output, router_logits, router_probs, expert_indices = moe_ffn(x, x_mask)
Comment on lines +1269 to +1276
[
(4, 1, False, False),
(4, 2, False, False),
(8, 1, False, True),
(8, 2, False, True),
(4, 2, True, True),
(16, 1, True, True),
],
Comment on lines +1295 to +1305
set_seed(42)
moe_ffn = PositionwiseConvFFMoE(
d_model=self.d_model,
d_ffn=self.d_ffn,
p_dropout=0.0,
num_experts=num_experts,
top_k_experts=top_k,
kernel_size=1,
bias=use_bias,
)
moe_ffn.eval()
)
moe_ffn.eval()

x = torch.randn(self.batch_size, self.seq_len, self.d_model)
Comment on lines +1309 to +1311
if use_padding:
x_mask[0, 7:] = 0
x_mask[1, 5:] = 0
Comment on lines +1235 to +1242
has_expert_grad = False
for expert in moe_ffn.experts:
for name in ('proj', 'o_net'):
g = expert[name].conv.weight.grad
if g is not None and g.abs().sum() > 0:
has_expert_grad = True
break
assert has_expert_grad, "At least one expert weight must receive a gradient"
@XuesongYang

Copy link
Copy Markdown
Collaborator Author

/ok to test b912b96

@github-actions

Copy link
Copy Markdown
Contributor

[🤖]: Hi @XuesongYang 👋,

We wanted to let you know that a CICD pipeline for this PR just finished successfully.

So it might be time to merge this PR or get some approvals.

@blisc
blisc merged commit be23ce1 into NVIDIA-NeMo:main Jun 3, 2026
178 checks passed
@XuesongYang
XuesongYang deleted the xueyang/pr-unit-test-moe branch July 21, 2026 18:32

This branch was previously deployed

2 inactive deployments
public — b912b965 Deployed May 13, 2026 by copy-pr-bot[bot] via release / finalize / publish-docs #381
test — b912b965 Deployed May 13, 2026 by copy-pr-bot[bot] via cicd-wait-in-queue #19850
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants