[EPLB] Mask padding in EPLB load recording (#38128)
Signed-off-by: ilmarkov <markovilya197@gmail.com> Signed-off-by: Markov Ilya <markovilya19@gmail.com> Co-authored-by: Markov Ilya <markovilya19@gmail.com>
This commit is contained in:
co-authored by
Markov Ilya
parent
311ad689ad
commit
a2abce646f
@@ -1332,6 +1332,9 @@ def _test_body_eplb(
|
||||
eplb_moe_layer.router.eplb_state.should_record_tensor = torch.ones(
|
||||
(), dtype=torch.bool, device=device
|
||||
)
|
||||
eplb_moe_layer.router.eplb_state.num_unpadded_tokens_tensors = [
|
||||
torch.tensor(0, dtype=torch.int32, device=device)
|
||||
]
|
||||
|
||||
# Get "after" output with rearranged weights and EPLB routing
|
||||
with set_forward_context(
|
||||
|
||||
@@ -61,12 +61,14 @@ def setup_eplb_state(
|
||||
global_num_experts, dtype=torch.int64, device="cuda"
|
||||
)
|
||||
should_record_tensor = torch.ones((), dtype=torch.bool, device="cuda")
|
||||
num_unpadded_tokens_tensors = [torch.tensor(0, dtype=torch.int32, device="cuda")]
|
||||
|
||||
return EplbLayerState(
|
||||
expert_load_view=expert_load_view,
|
||||
logical_to_physical_map=logical_to_physical_map,
|
||||
logical_replica_count=logical_replica_count,
|
||||
should_record_tensor=should_record_tensor,
|
||||
num_unpadded_tokens_tensors=num_unpadded_tokens_tensors,
|
||||
)
|
||||
|
||||
|
||||
@@ -782,3 +784,67 @@ def test_eplb_map_with_redundancy(
|
||||
torch.testing.assert_close(load, exp_load)
|
||||
else:
|
||||
assert load.sum().item() == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"l2p_map, replica_count, num_physical, topk_ids, "
|
||||
"num_unpadded, expected_out, expected_load",
|
||||
[
|
||||
pytest.param(
|
||||
[[0], [1], [2], [3]],
|
||||
[1, 1, 1, 1],
|
||||
4,
|
||||
[[0, 1], [2, 3], [0, 2], [1, 3]],
|
||||
2,
|
||||
[[0, 1], [2, 3], [0, 2], [1, 3]],
|
||||
# only rows 0,1 counted: expert 0→1, 1→1, 2→1, 3→1
|
||||
[1, 1, 1, 1],
|
||||
id="half_padded",
|
||||
),
|
||||
pytest.param(
|
||||
# record everything (None = no padding info)
|
||||
[[0], [1], [2], [3]],
|
||||
[1, 1, 1, 1],
|
||||
4,
|
||||
[[0, 1], [2, 3], [0, 2], [1, 3]],
|
||||
None,
|
||||
[[0, 1], [2, 3], [0, 2], [1, 3]],
|
||||
[2, 2, 2, 2],
|
||||
id="no_padding_info",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_eplb_map_num_unpadded_tokens(
|
||||
l2p_map,
|
||||
replica_count,
|
||||
num_physical,
|
||||
topk_ids,
|
||||
num_unpadded,
|
||||
expected_out,
|
||||
expected_load,
|
||||
):
|
||||
l2p = torch.tensor(l2p_map, dtype=torch.int64, device="cuda")
|
||||
rc = torch.tensor(replica_count, dtype=torch.int64, device="cuda")
|
||||
load = torch.zeros(num_physical, dtype=torch.int32, device="cuda")
|
||||
rec = torch.tensor(True, dtype=torch.bool, device="cuda")
|
||||
ids = torch.tensor(topk_ids, dtype=torch.int32, device="cuda")
|
||||
num_unpadded_t = (
|
||||
torch.tensor(num_unpadded, dtype=torch.int32, device="cuda")
|
||||
if num_unpadded is not None
|
||||
else None
|
||||
)
|
||||
|
||||
out = eplb_map_to_physical_and_record(
|
||||
topk_ids=ids,
|
||||
expert_load_view=load,
|
||||
logical_to_physical_map=l2p,
|
||||
logical_replica_count=rc,
|
||||
record_enabled=rec,
|
||||
num_unpadded_tokens=num_unpadded_t,
|
||||
)
|
||||
|
||||
exp_out = torch.tensor(expected_out, dtype=out.dtype, device="cuda")
|
||||
torch.testing.assert_close(out, exp_out)
|
||||
|
||||
exp_load = torch.tensor(expected_load, dtype=torch.int32, device="cuda")
|
||||
torch.testing.assert_close(load, exp_load)
|
||||
|
||||
Reference in New Issue
Block a user