Expand Einsum test coverage with parameterized tests#5285
Expand Einsum test coverage with parameterized tests#5285us wants to merge 1 commit intogoogle:mainfrom
Conversation
Summary of ChangesHello, 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 significantly enhances the test coverage for 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 significantly expands the test coverage for nnx.Einsum with a comprehensive new test suite. The tests are thorough, covering output shapes, dtypes, bias handling, input validation, precision, gradients, and more. The implementation is of high quality. I have a couple of suggestions to improve the test code's readability and maintainability.
What does this PR do?
Expands
nnx.Einsumtest coverage intests/nnx/nn/linear_test.pywith a comprehensiveTestEinsumclass containing 15 test methods (35 parameterized variants). The existing Einsum tests only covered Linen/NNX equivalence and a customeinsum_op— this PR adds functional unit tests for all major Einsum behaviors.New test coverage
test_output_shape): 5 diverse einsum patterns — matrix multiply, batched matmul, multi-head attention-like, multi-dim contraction, and bias-freetest_dtypes): 12 combinations ofdtype(incl.None),param_dtype, andpreferred_element_typewith correct output dtype assertionstest_no_bias): Parameterized overdtypexparam_dtype, verifies analytic expected outputtest_bias_addition_simple,test_bias_addition_multidim,test_bias_broadcast_with_ellipsis): Verifies_infer_broadcasted_bias_shapedirectly and functionally, including ellipsis equationstest_einsum_str_missing_arrow_raises,test_einsum_str_wrong_operand_count_raises):assertRaisesRegexwith error message matchingtest_spaces_in_einsum_str): Numeric comparison between spaced and clean einsum stringstest_precision): Injection-based test verifying precision is passed toeinsum_optest_gradient_flow): Analytic gradient verification for both bias and no-bias casestest_einsum_str_call_override): Provesfirst_frompriority with different constructor vs call-time stringstest_custom_initializers): Verifies init values and forward pass analytic outputtest_ellipsis_einsum_str): Shape verification ford...ab,bc...->ad...cChecklist