eplb redundant expert bugfix (#4291)
### What this PR does / why we need it?
Redundant experts bugfix
### Does this PR introduce _any_ user-facing change?
After configuring the path for experts_map, users do not need to
configure iinit_redundancy_expert.
### How was this patch tested?
The accuracy of EPLB was tested with and without the use of redundant
experts.
- vLLM version: v0.11.0
- vLLM main:
2918c1b49c
---------
Signed-off-by: shenchuxiaofugui <1311027364@qq.com>
This commit is contained in:
@@ -9,39 +9,6 @@ from vllm_ascend.eplb.core import eplb_utils
|
||||
from vllm_ascend.eplb.core.eplb_utils import EPLBParamUtils
|
||||
|
||||
|
||||
def test_determine_default_expert_map_single_world():
|
||||
count, expert_map = eplb_utils.determine_default_expert_map(
|
||||
global_expert_num=4,
|
||||
world_size=1,
|
||||
rank_id=0,
|
||||
global_redundant_expert_num=0)
|
||||
assert count == 4
|
||||
assert torch.equal(expert_map, torch.arange(4, dtype=torch.int32))
|
||||
|
||||
|
||||
def test_determine_default_expert_map_multiple_worlds_no_redundant():
|
||||
count, expert_map = eplb_utils.determine_default_expert_map(
|
||||
global_expert_num=8,
|
||||
world_size=2,
|
||||
rank_id=0,
|
||||
global_redundant_expert_num=0)
|
||||
|
||||
assert count == 4
|
||||
assert torch.all(expert_map[:4] >= 0)
|
||||
assert torch.all(expert_map[4:] == -1)
|
||||
|
||||
|
||||
def test_determine_default_expert_map_multiple_worlds_with_redundant():
|
||||
count, expert_map = eplb_utils.determine_default_expert_map(
|
||||
global_expert_num=5,
|
||||
world_size=2,
|
||||
rank_id=0,
|
||||
global_redundant_expert_num=1)
|
||||
|
||||
assert count == 2
|
||||
assert torch.all(expert_map[0:2] >= 0)
|
||||
|
||||
|
||||
def test_generate_log2phy_map_single_rank_holding():
|
||||
|
||||
expert_map = torch.tensor([[0, -1], [-1, 0]], dtype=torch.int32)
|
||||
@@ -64,21 +31,17 @@ def test_generate_log2phy_map_multiple_rank_holding(monkeypatch):
|
||||
|
||||
|
||||
def test_determine_default_log2phy_map_world_size_1():
|
||||
log2phy = eplb_utils.determine_default_log2phy_map(
|
||||
global_expert_num=3,
|
||||
world_size=1,
|
||||
rank_id=0,
|
||||
global_redundant_expert_num=0)
|
||||
log2phy = eplb_utils.determine_default_log2phy_map(global_expert_num=3,
|
||||
world_size=1,
|
||||
rank_id=0)
|
||||
assert log2phy.shape == (3, )
|
||||
assert (log2phy >= 0).all()
|
||||
|
||||
|
||||
def test_determine_default_log2phy_map_world_size_multiple():
|
||||
log2phy = eplb_utils.determine_default_log2phy_map(
|
||||
global_expert_num=6,
|
||||
world_size=2,
|
||||
rank_id=1,
|
||||
global_redundant_expert_num=1)
|
||||
log2phy = eplb_utils.determine_default_log2phy_map(global_expert_num=6,
|
||||
world_size=2,
|
||||
rank_id=1)
|
||||
assert log2phy.shape == (6, )
|
||||
assert (log2phy >= 0).all()
|
||||
|
||||
|
||||
@@ -48,8 +48,7 @@ class TestExpertLoadBalancer(TestBase):
|
||||
with open(json_file, 'r') as f:
|
||||
self.expert_map: MockData = json.load(f)
|
||||
|
||||
self.expert_load_balancer = ExpertLoadBalancer(json_file,
|
||||
global_expert_num=8)
|
||||
self.expert_load_balancer = ExpertLoadBalancer(json_file, 8)
|
||||
|
||||
def test_init(self):
|
||||
|
||||
@@ -83,7 +82,7 @@ class TestExpertLoadBalancer(TestBase):
|
||||
)
|
||||
self.assertEqual(expert_placement_map.shape,
|
||||
(self.expert_load_balancer.layers_num,
|
||||
self.expert_load_balancer.ranks_num, 8))
|
||||
self.expert_load_balancer.ranks_num, 10))
|
||||
self.assertTrue(torch.all(expert_placement_map >= -1))
|
||||
|
||||
def test_generate_log2phy_expert_map(self):
|
||||
@@ -91,7 +90,7 @@ class TestExpertLoadBalancer(TestBase):
|
||||
log2phy_map = self.expert_load_balancer.generate_log2phy_expert_map(
|
||||
layer_id)
|
||||
self.assertEqual(log2phy_map.shape,
|
||||
(self.expert_load_balancer.ranks_num, 8))
|
||||
(self.expert_load_balancer.ranks_num, 10))
|
||||
self.assertTrue(torch.all(log2phy_map >= -1))
|
||||
|
||||
@mock.patch("torch_npu.npu._lazy_init")
|
||||
@@ -102,7 +101,7 @@ class TestExpertLoadBalancer(TestBase):
|
||||
rank_local_expert_num, rank_expert_map = self.expert_load_balancer.get_rank_placement_map(
|
||||
layer_id, rank_id)
|
||||
self.assertEqual(rank_local_expert_num, 5)
|
||||
expected_tensor = torch.tensor([2, -1, 1, 3, -1, 4, -1, 0],
|
||||
expected_tensor = torch.tensor([2, -1, 1, 3, -1, 4, -1, 0, -1, -1],
|
||||
dtype=torch.int32).to(
|
||||
rank_expert_map.device)
|
||||
self.assertTrue(rank_expert_map.equal(expected_tensor))
|
||||
@@ -110,7 +109,7 @@ class TestExpertLoadBalancer(TestBase):
|
||||
rank_id = 1
|
||||
rank_local_expert_num, rank_expert_map = self.expert_load_balancer.get_rank_placement_map(
|
||||
layer_id, rank_id)
|
||||
expected_tensor = torch.tensor([-1, 1, 4, -1, 2, -1, 0, 3],
|
||||
expected_tensor = torch.tensor([-1, 1, 4, -1, 2, -1, 0, 3, -1, -1],
|
||||
dtype=torch.int32).to(
|
||||
rank_expert_map.device)
|
||||
self.assertTrue(rank_expert_map.equal(expected_tensor))
|
||||
@@ -120,7 +119,7 @@ class TestExpertLoadBalancer(TestBase):
|
||||
rank_id = 0
|
||||
log2phy_map = self.expert_load_balancer.get_rank_log2phy_map(
|
||||
layer_id, rank_id)
|
||||
expected_tensor = torch.tensor([2, 6, 1, 3, 7, 4, 5, 0],
|
||||
expected_tensor = torch.tensor([2, 6, 1, 3, 7, 4, 5, 0, -1, -1],
|
||||
dtype=torch.int32).to(
|
||||
log2phy_map.device)
|
||||
self.assertTrue(log2phy_map.equal(expected_tensor))
|
||||
@@ -128,7 +127,7 @@ class TestExpertLoadBalancer(TestBase):
|
||||
rank_id = 1
|
||||
log2phy_map = self.expert_load_balancer.get_rank_log2phy_map(
|
||||
layer_id, rank_id)
|
||||
expected_tensor = torch.tensor([2, 6, 9, 3, 7, 4, 5, 8],
|
||||
expected_tensor = torch.tensor([2, 6, 9, 3, 7, 4, 5, 8, -1, -1],
|
||||
dtype=torch.int32).to(
|
||||
log2phy_map.device)
|
||||
self.assertTrue(log2phy_map.equal(expected_tensor))
|
||||
|
||||
Reference in New Issue
Block a user