[Test] Optimize test_trtllm_gen_fused_moe.py#2072
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughThis change threads a new Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Test Suite
participant CUDAGraph as CUDAGraphMoE
participant AutoTuner
participant Kernel as MoE Kernel
Test->>CUDAGraph: init(..., enable_autotune)
CUDAGraph->>CUDAGraph: store flag
alt enable_autotune == true
Test->>CUDAGraph: call_moe(..., enable_autotune=True)
CUDAGraph->>AutoTuner: autotune(enable=True, tune_max_num_tokens=4096)
AutoTuner->>Kernel: probe variants
Kernel-->>AutoTuner: metrics
AutoTuner->>Kernel: launch chosen variant
else enable_autotune == false
Test->>CUDAGraph: call_moe(..., enable_autotune=False)
CUDAGraph->>AutoTuner: autotune(enable=False)
AutoTuner->>Kernel: launch default variant
end
Kernel-->>CUDAGraph: results
CUDAGraph-->>Test: outputs
Test->>Test: check_accuracy (isfinite + isclose)
Test->>AutoTuner: clear_cache()
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📥 CommitsReviewing files that changed from the base of the PR and between 56e959c1c34aa201d135f3711e1840750df21d50 and cca7e66. 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)tests/moe/test_trtllm_gen_fused_moe.py (1)
🪛 Ruff (0.14.4)tests/moe/test_trtllm_gen_fused_moe.py1426-1426: Create your own exception (TRY002) 1426-1426: Avoid specifying long messages outside the exception class (TRY003) 1428-1428: Create your own exception (TRY002) 1428-1428: Avoid specifying long messages outside the exception class (TRY003) 🔇 Additional comments (15)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @jiahanc, 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 focuses on optimizing the Highlights
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 introduces several valuable optimizations to the test_trtllm_gen_fused_moe.py test file. The changes include adding a configuration option to enable or disable the autotuner, which enhances test flexibility. The test parameterization has been refined by adjusting token counts for better coverage and speed. Furthermore, the check_accuracy function has been significantly optimized by leveraging torch.isclose, leading to faster test execution. Clearing the autotuner cache between test runs is also a great addition for ensuring test isolation. Overall, these are solid improvements. I have one minor suggestion to improve code maintainability by replacing a repeated magic number with a named constant.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
tests/moe/test_trtllm_gen_fused_moe.py (2)
211-211: Consider extracting magic number to a constant.The value
tune_max_num_tokens=4096is hardcoded in 4 different locations. While acceptable for test code, defining it as a module-level constant would improve maintainability.Example:
# Near the top of the file TUNE_MAX_NUM_TOKENS = 4096Then use
tune_max_num_tokens=TUNE_MAX_NUM_TOKENSat each call site.Also applies to: 803-803, 980-980, 1132-1132
1419-1437: Improved accuracy check with early exit, but consider using AssertionError.The refactored
check_accuracyfunction is more efficient with:
torch.isfinitefor cleaner finite value validationtorch.isclosefor better element-wise comparison- Early return when
match_ratio >= percentHowever, the exceptions raised at lines 1422 and 1424 use generic
Exception. For test code,AssertionErrorwould be more idiomatic.Apply this diff:
- if not torch.isfinite(a).all(): - raise Exception("Non-finite values in reference output") - if not torch.isfinite(b).all(): - raise Exception("Non-finite values in actual output") + if not torch.isfinite(a).all(): + raise AssertionError("Non-finite values in reference output") + if not torch.isfinite(b).all(): + raise AssertionError("Non-finite values in actual output")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between d42fb90 and 7be4a657929b4d0d0ff4cf6a2d09915ff5a537bc.
📒 Files selected for processing (1)
tests/moe/test_trtllm_gen_fused_moe.py(30 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/moe/test_trtllm_gen_fused_moe.py (1)
flashinfer/autotuner.py (4)
AutoTuner(335-784)autotune(251-262)get(362-365)clear_cache(778-780)
🪛 Ruff (0.14.4)
tests/moe/test_trtllm_gen_fused_moe.py
1422-1422: Create your own exception
(TRY002)
1422-1422: Avoid specifying long messages outside the exception class
(TRY003)
1424-1424: Create your own exception
(TRY002)
1424-1424: Avoid specifying long messages outside the exception class
(TRY003)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Deploy Docs
🔇 Additional comments (11)
tests/moe/test_trtllm_gen_fused_moe.py (11)
35-35: LGTM: Import additions support the autotuner control feature.The new imports for
AutoTunerandautotuneare properly used throughout the file to enable/disable autotuning during tests and clear the cache between runs.
79-79: LGTM: Enable autotune flag properly integrated.The
enable_autotuneflag is correctly extracted from config with a sensible default ofTrue, maintaining backward compatibility.
110-110: LGTM: Autotune context manager correctly applied during warmup.The
autotune(self.enable_autotune)context manager properly controls autotuning behavior during the warmup phase.
556-556: LGTM: Consistent enable_autotune propagation across MoE implementations.The
enable_autotuneflag is consistently extracted from kwargs with a default ofTrueacross all MoE implementation types (FP4, FP8BlockScale, FP8PerTensor, BF16), maintaining backward compatibility.Also applies to: 768-768, 946-946, 1112-1112
569-569: LGTM: Autotune context managers correctly applied.The
autotunecontext manager is properly used with theenable_autotuneflag to control autotuning behavior during kernel execution across all MoE implementations.Also applies to: 780-780, 954-954, 1115-1115
2112-2113: LGTM: AutoTuner cache clearing ensures test isolation.Clearing the AutoTuner cache between test runs prevents cross-configuration tactic reuse, ensuring each test configuration gets fresh autotuning. This is a good practice for test isolation.
2253-2254: LGTM: Enable autotune properly integrated into test harness.The
enable_autotuneflag is correctly extracted fromrouting_configand passed through tocompute_production, enabling per-test-case control of autotuning behavior.Also applies to: 2270-2270
2010-2010: LGTM: Consistent enable_autotune default in unified computation.The
enable_autotuneflag extraction with defaultTruemaintains consistency with other parts of the codebase.
2313-2313: LGTM: Good test coverage for enable_autotune flag.The routing configurations include both
enable_autotune: TrueandFalsevalues, ensuring test coverage for both autotuner-enabled and disabled code paths. This aligns well with the PR objectives.Also applies to: 2329-2329, 2345-2345, 2438-2438, 2454-2454, 2470-2470, 2561-2561, 2635-2635
2285-2285: LGTM: Token count adjustments improve test coverage.The
num_tokensparameter values have been adjusted to[8, 768, 3072]for most tests, improving coverage as stated in the PR objectives. The TopK test appropriately maintains[8, 128]due to GeGlu constraints.Also applies to: 2411-2411, 2536-2536, 2611-2611
2560-2560: Verify intentional removal of intermediate_size=384 from TopK routing.The
compatible_intermediate_sizelist was changed from[384, 512, 768, 1024]to[512, 768, 1024], removing 384. While this may be intentional to improve test execution speed, please confirm:
- Is the removal of 384 intentional for TopK routing?
- Note that the test parametrization at line 2538 still includes 384, which will now be skipped by
skip_checkslogic.
|
/bot run |
|
[FAILED] Pipeline #38230531: 13/17 passed |
Signed-off-by: jiahanc <173873397+jiahanc@users.noreply.github.com>
Signed-off-by: jiahanc <173873397+jiahanc@users.noreply.github.com>
|
/bot run |
|
[SUCCESS] Pipeline #38313925: 15/17 passed |
📌 Description
Currently
test_llm_gen_fused_moetook long time, make some optimization to speed upcheck_accuracyto speed up🔍 Related Issues
🚀 Pull Request Checklist
Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete.
✅ Pre-commit Checks
pre-commitby runningpip install pre-commit(or used your preferred method).pre-commit install.pre-commit run --all-filesand fixed any reported issues.🧪 Tests
unittest, etc.).Reviewer Notes
Summary by CodeRabbit