Skip to content

Conversation

Clorist33
Copy link
Contributor

@Clorist33 Clorist33 commented Sep 19, 2025

UT for EPLB

Co-authored-by Skywalker-EP 173723846@qq.com
Co-authored-by offline 0806@qq.com
Co-authored-by dsxsteven@sina.com

UT Description

1. Module Description

  • Module: EPLB

2. Covered Source Files

  • vllm_ascend/eplb/adaptor/abstract_adaptor.py
  • vllm_ascend/eplb/core/eplb_device_transfer_loader.py
  • vllm_ascend/eplb/core/eplb_utils.py
  • vllm_ascend/eplb/core/policy/policy_abstract.py
  • vllm_ascend/eplb/core/policy/policy_dynamic_ep.py
  • vllm_ascend/eplb/core/policy/policy_dynamic_ep_v2.py
  • vllm_ascend/eplb/core/policy/policy_factory.py

3. Testing Method

  • Framework: pytest
  • Test Data: mock data
  • Test Type: unit test

4. Coverage

Copy link

👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:‌‌

  • A PR should do only one thing, smaller PRs enable faster reviews.
  • Every PR should include unit tests and end-to-end tests ‌to ensure it works and is not broken by other future PRs.
  • Write the commit message by fulfilling the PR description to help reviewer and future developers understand.

If CI fails, you can run linting and testing checks locally according Contributing and Testing.

Copy link
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 introduces a suite of unit tests for the Expert Placement Load Balancing (EPLB) functionality. The tests cover various components, including adaptors, policies, and utility functions. While the coverage is a good step forward, my review identified several critical issues in the new tests. These include incorrect assertions that do not match the code's behavior, and flawed test setups that would cause tests to fail for reasons different from what they intend to verify. Addressing these issues is crucial to ensure the reliability and correctness of the test suite.



def test_generate_task_and_state_flow(mock_adaptor):
loader_obj = loader.D2DExpertWeightLoader(mock_adaptor)
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The D2DExpertWeightLoader class is instantiated with mock_adaptor as an argument, but its __init__ method does not accept any arguments. This will cause a TypeError. The adaptor should be set using the set_adator method after instantiation. This needs to be fixed in all test functions in this file (lines 60, 96, 102, 118).

Suggested change
loader_obj = loader.D2DExpertWeightLoader(mock_adaptor)
loader_obj = loader.D2DExpertWeightLoader()
loader_obj.set_adator(mock_adaptor)

Comment on lines 24 to 34
with pytest.raises(ZeroDivisionError):
policy.safe_divide(1, 0)

# safe_exact_divide
assert policy.safe_exact_divide(10, 3) == 3
with pytest.raises(ZeroDivisionError):
policy.safe_exact_divide(1, 0)

# safe_mod
assert policy.safe_mod(10, 3) == 1
with pytest.raises(ZeroDivisionError):
policy.safe_mod(1, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The tests for safe_divide, safe_exact_divide, and safe_mod incorrectly expect a ZeroDivisionError to be raised on division by zero. The implementation of these safe operations is designed to handle this case by returning 0 and printing a message, not by raising an exception. The tests should be updated to assert that the return value is 0 in these scenarios.

Suggested change
with pytest.raises(ZeroDivisionError):
policy.safe_divide(1, 0)
# safe_exact_divide
assert policy.safe_exact_divide(10, 3) == 3
with pytest.raises(ZeroDivisionError):
policy.safe_exact_divide(1, 0)
# safe_mod
assert policy.safe_mod(10, 3) == 1
with pytest.raises(ZeroDivisionError):
policy.safe_mod(1, 0)
assert policy.safe_divide(1, 0) == 0
# safe_exact_divide
assert policy.safe_exact_divide(10, 3) == 3
assert policy.safe_exact_divide(1, 0) == 0
# safe_mod
assert policy.safe_mod(10, 3) == 1
assert policy.safe_mod(1, 0) == 0

Comment on lines +77 to +91
expert_table_zero = np.array([[]]) # 1 layer, 0 NPU, 0 experts
workload_zero = np.array([[]])
with pytest.raises(ValueError):
policy.rebalance_experts(expert_table_zero, workload_zero)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The test case for num_npus <= 0 is not correctly set up. The input arrays expert_table_zero and workload_zero are initialized as np.array([[]]), which creates 2D arrays with shape (1, 0). However, the rebalance_experts method expects 3D arrays. This will cause a ValueError: not enough values to unpack (expected 3, got 2) when trying to unpack the shape, which is not the error this test case is intended to catch. To correctly test the num_npus <= 0 check, you should provide 3D arrays with the second dimension being 0, for example, np.zeros((1, 0, 0)).

Suggested change
expert_table_zero = np.array([[]]) # 1 layer, 0 NPU, 0 experts
workload_zero = np.array([[]])
with pytest.raises(ValueError):
policy.rebalance_experts(expert_table_zero, workload_zero)
expert_table_zero = np.zeros((1, 0, 0))
workload_zero = np.zeros((1, 0, 0))
with pytest.raises(ValueError):
policy.rebalance_experts(expert_table_zero, workload_zero)

Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

tanqingshan (A) and others added 3 commits September 24, 2025 10:36
Signed-off-by: tanqingshan (A) <t50050625@china.huawei.com>

Signed-off-by:  <>

Signed-off-by: tanqingshan (A)  <50050625@china.huawei.com>
Signed-off-by:  <>

Signed-off-by: tanqingshan <50050625@china.huawei.com>
Signed-off-by:  <>

Signed-off-by: tanqingshan <50050625@china.huawei.com>
dsxsteven and others added 2 commits September 24, 2025 11:14
Signed-off-by: daishixun <dsxsteven@sina.com>
@wangxiyuan wangxiyuan merged commit 302494c into vllm-project:main Sep 24, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants