Skip to content

unittest fix ljl#62

Merged
meichangsu1 merged 9 commits intodevfrom
kernels_unittest_fix_ljl
Feb 13, 2026
Merged

unittest fix ljl#62
meichangsu1 merged 9 commits intodevfrom
kernels_unittest_fix_ljl

Conversation

@meichangsu1
Copy link
Copy Markdown
Collaborator

No description provided.

Replace calls to `_get_sp_group_from_device_mesh` with direct access to `sequence_parallel._sp_group` in sequence parallel attention tests. This simplifies the test setup by using the already initialized group stored in the module, improving code clarity and reducing redundancy.
Add additional imports and a try-except block to verify that the 'kernels-test/flattened-build' kernel can be successfully loaded in the current environment before proceeding with the test. This prevents test failures due to environment-specific loading issues and provides a more informative skip message.
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @meichangsu1, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the unit tests for expert parallel, FSDP, and SP alignment by streamlining error reporting and correcting label handling. It removes verbose conditional logging that duplicated assertion logic, allowing test failures to be reported directly by the assertions. Additionally, it ensures that label inputs within specific test functions are consistently aligned with next-token semantics, improving the accuracy and reliability of the tests.

Highlights

  • Test Simplification: Simplified test failure reporting by removing redundant conditional checks and print statements that duplicated assertion logic for gradient, logits, and selected expert comparisons.
  • Label Consistency: Ensured consistent label semantics in specific test functions by updating sp_label_inputs to use labels_shifted instead of labels_raw, aligning with next-token semantics.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • tests/moe/test_expert_parallel_qwen3_fsdp_sp.py
    • Removed redundant if conditions and print statements that preceded assert calls for gradient, logits, and selected experts comparisons, simplifying test failure reporting.
    • Updated sp_label_inputs to use labels_shifted instead of labels_raw in _run_worker_ep_fsdp_sp_align and _run_worker_fsdp_sp_align to maintain consistent label semantics.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request appears to fix a bug in the unit tests by using the correct labels_shifted variable. However, it also removes several detailed debugging messages from assertions. While this simplifies the code, it makes it much harder to debug test failures. I've added suggestions to restore this valuable debugging information within the assertion messages.

f'max={abs_diff.max().item():.6e} rel_norm={rel.item():.6e} tol={rel_tol:.1e}',
flush=True,
)
assert rel.item() <= rel_tol
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.

medium

While removing the redundant if block is a good simplification, the detailed debugging information from the print statement is lost. When this assertion fails, it will be hard to know the actual and expected values. Please add a descriptive message to the assertion.

Suggested change
assert rel.item() <= rel_tol
assert rel.item() <= rel_tol, f'[rank{rank}] {k} grad diff mean={diff.abs().mean().item():.6e} max={diff.abs().max().item():.6e} rel_norm={rel.item():.6e} tol={rel_tol:.1e}'

diff = (sp_logits - base_logits).abs()
raise AssertionError(f'[rank{rank}] logits not close: mean_abs={diff.mean().item():.6e} '
f'max_abs={diff.max().item():.6e} (rtol=1e-3, atol=1e-4)')
assert torch.allclose(sp_logits, base_logits, rtol=1e-3, atol=1e-4)
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.

medium

Replacing the if block with a simple assert loses the detailed error message, which is very helpful for debugging. Please include the debugging information in the assertion message. The original implementation with if not torch.allclose(...) was also more efficient as it only computed the difference when the check failed.

if not torch.allclose(sp_logits, base_logits, rtol=1e-3, atol=1e-4):
    diff = (sp_logits - base_logits).abs()
    raise AssertionError(f'[rank{rank}] logits not close: mean_abs={diff.mean().item():.6e} '
                         f'max_abs={diff.max().item():.6e} (rtol=1e-3, atol=1e-4)')

if not torch.equal(base_sel, sp_sel):
mismatch = (base_sel != sp_sel).sum().item()
print(f'[rank{rank}] block[{idx}] selected_experts mismatch count={mismatch}', flush=True)
assert torch.equal(base_sel, sp_sel)
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.

medium

This change removes a helpful print statement that shows the mismatch count when the assertion fails. This information is valuable for debugging. Please include it in the assertion message.

assert torch.equal(base_sel, sp_sel), f'[rank{rank}] block[{idx}] selected_experts mismatch count={(base_sel != sp_sel).sum().item()}'

f'[rank{rank}] logits diff mean={diff.mean().item():.6e} max={diff.max().item():.6e}',
flush=True,
)
assert torch.allclose(sp_logits, base_logits, rtol=1e-3, atol=1e-4)
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.

medium

The removed print statement contained useful debugging information (mean and max difference) for when the allclose check fails. It's better to include this information in the assertion message to aid debugging.

assert torch.allclose(sp_logits, base_logits, rtol=1e-3, atol=1e-4), f'[rank{rank}] logits diff mean={(sp_logits - base_logits).abs().mean().item():.6e} max={(sp_logits - base_logits).abs().max().item():.6e}'

raise AssertionError(
f'[rank{rank}] inputs_embeds.grad(full) not close: mean_abs={abs_diff.mean().item():.6e} '
f'max_abs={abs_diff.max().item():.6e} rel_norm={rel.item():.6e} tol={grad_rel_tol:.1e}')
assert rel.item() <= grad_rel_tol
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.

medium

Replacing the if block with a simple assert loses the detailed error message, which is very helpful for debugging. Please include the debugging information in the assertion message. The diff and rel tensors are already computed, so they can be used in the message.

assert rel.item() <= grad_rel_tol, f'[rank{rank}] inputs_embeds.grad(full) not close: mean_abs={diff.abs().mean().item():.6e} max_abs={diff.abs().max().item():.6e} rel_norm={rel.item():.6e} tol={grad_rel_tol:.1e}'

@meichangsu1 meichangsu1 merged commit 454ebe8 into dev Feb 13, 2026
2 of 5 checks passed
@meichangsu1 meichangsu1 deleted the kernels_unittest_fix_ljl branch February 13, 2026 09:05
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.

1 participant