-
Notifications
You must be signed in to change notification settings - Fork 660
[CI] 【Hackathon 9th Sprint No.18】NO.18 功能模块单测补充 #5064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CI] 【Hackathon 9th Sprint No.18】NO.18 功能模块单测补充 #5064
Conversation
This file contains unit tests for the DeepEP buffer helpers and runners, including various test cases for buffer allocation, cleanup, and dispatching processes.
|
Thanks for your contribution! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive unit tests for the DeepEP buffer management and MoE (Mixture of Experts) execution functionality in fastdeploy/model_executor/layers/moe/ep.py, achieving 85% test coverage as part of Hackathon 9th Sprint No.18.
Key Changes:
- Added extensive mock infrastructure for testing DeepEP buffers and runners without requiring actual dependencies
- Implemented 9 test cases covering buffer allocation, low-latency operations, dispatch/combine flows, and MoE selection strategies
- Created recording stubs to verify correct API interactions with the DeepEP communication layer
| num_max_dispatch_tokens_per_rank=2, | ||
| ) | ||
| layer = types.SimpleNamespace( | ||
| redundant_table_manger=None, |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in variable name: redundant_table_manger should be redundant_table_manager (missing 'a' in 'manager').
| TWO_STAGE_RDMA_HINT = 4096 | ||
| TWO_STAGE_NVL_HINT = 2048 | ||
|
|
||
| init_history: list[dict] = [] |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class-level mutable default list can lead to unexpected behavior. The init_history list is shared across all instances and persists between test runs. While there's a reset() method to clear it, consider using instance-level tracking or document this as an intentional design choice for test recording.
tests/model_executor/test_moe.py
Outdated
| _STUBS_INSTALLED = False | ||
|
|
||
|
|
||
| def _install_dependency_stubs(): | ||
| global _STUBS_INSTALLED | ||
| if _STUBS_INSTALLED: | ||
| return |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Global mutable state _STUBS_INSTALLED can cause test isolation issues. If a test modifies the stubbed modules, subsequent tests may see unexpected state. Consider using pytest fixtures with proper teardown or a context manager to ensure proper isolation between test runs.
| fd_model_executor_pkg.ops = fd_ops_pkg | ||
|
|
||
| gpu_module = types.ModuleType("fastdeploy.model_executor.ops.gpu") | ||
| gpu_module.calls = {"redundant": [], "topk": []} |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The gpu_module.calls dictionary is initialized with mutable lists that are shared across test runs. While the reset_recorders fixture clears these, consider using a more explicit pattern to avoid potential state leakage if the fixture is accidentally skipped or fails.
| fd_ops_pkg.gpu = gpu_module | ||
|
|
||
| moe_module = types.ModuleType("fastdeploy.model_executor.layers.moe.moe") | ||
| moe_module.calls = [] |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to gpu_module, the moe_module.calls list is a module-level mutable that persists across tests. This pattern is repeated multiple times. Consider creating a shared test utility class to manage these recording structures consistently.
| return ([0], [0], [1], [2]) | ||
|
|
||
| layer = types.SimpleNamespace( | ||
| redundant_table_manger=_RedundantTable(), |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in variable name: redundant_table_manger should be redundant_table_manager (missing 'a' in 'manager').
| num_max_dispatch_tokens_per_rank=2, | ||
| ) | ||
| layer = types.SimpleNamespace( | ||
| redundant_table_manger=None, |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in variable name: redundant_table_manger should be redundant_table_manager (missing 'a' in 'manager').
tests/model_executor/test_moe.py
Outdated
| _STUBS_INSTALLED = False | ||
|
|
||
|
|
||
| def _install_dependency_stubs(): |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _install_dependency_stubs() function is complex and performs significant setup (creating multiple module stubs). Add a docstring explaining its purpose, what dependencies it's stubbing, and why this approach is necessary for testing.
| def _install_dependency_stubs(): | |
| def _install_dependency_stubs(): | |
| """ | |
| Sets up stub modules for external dependencies required by the code under test. | |
| This function creates and registers mock versions of the following modules: | |
| - paddle | |
| - paddle.nn | |
| - paddle.distributed | |
| These stubs provide minimal implementations and attributes needed for the tests to run, | |
| without requiring the actual external libraries to be installed. This approach ensures | |
| that unit tests can execute in isolation, avoiding side effects and dependency issues | |
| that may arise from importing or using real external modules. | |
| """ |
tests/model_executor/test_moe.py
Outdated
| _STUBS_INSTALLED = True | ||
|
|
||
|
|
||
| _install_dependency_stubs() |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _install_dependency_stubs() is called at module import time (line 383), which means stubs are installed as soon as the test module is imported. This violates the principle of explicit test setup and can cause side effects. Consider moving this to a pytest fixture with session scope or using pytest's autouse=True fixture for better control and visibility.
| _install_dependency_stubs() | |
| @pytest.fixture(scope="session", autouse=True) | |
| def _install_stubs_fixture(): | |
| global _STUBS_INSTALLED | |
| if not _STUBS_INSTALLED: | |
| _install_dependency_stubs() |
…elpers Refactor DeepEP tests to use scoped stubs
YuanRisheng
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
把减少的miss代码行数也在pr描述里进行说明
tests/model_executor/test_ep.py
Outdated
| @@ -0,0 +1,631 @@ | |||
| """Unit tests for the DeepEP buffer helpers and runners.""" | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
缺copyright
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已经添加,同时已经说明
Added licensing information to the test file.
|
0.2⭐️ |
|
hi, @xunyoyo
|
|
@xunyoyo @YuanRisheng 该 PR 当前落后 develop 分支约一周的提交。建议后续补充单测类的 PR 在合入前定期执行一次 |

This file contains unit tests for the DeepEP buffer helpers and runners, including various test cases for buffer allocation, cleanup, and dispatching processes.
Motivation
NO.18 功能模块 fastdeploy/model_executor/layers/moe/ep.py 单测补充
Modifications
add tests/model_executor/test_ep.py
Usage or Command
tests/model_executor/test_ep.py:Accuracy Tests
旧覆盖
tests/model_executor/test_ep.py:覆盖 ++176 行
Checklist
[FDConfig],[APIServer],[Engine],[Scheduler],[PD Disaggregation],[Executor],[Graph Optimization],[Speculative Decoding],[RL],[Models],[Quantization],[Loader],[OP],[KVCache],[DataProcessor],[BugFix],[Docs],[CI],[Optimization],[Feature],[Benchmark],[Others],[XPU],[HPU],[GCU],[DCU],[Iluvatar],[Metax]]pre-commitbefore commit.releasebranch, make sure the PR has been submitted to thedevelopbranch, then cherry-pick it to thereleasebranch with the[Cherry-Pick]PR tag.