Conversation
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.
Summary of ChangesHello @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
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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}'
No description provided.