[Elastic EP] Reuse CUDA graphs across reconfiguration (#54985)

This commit is contained in:
Itay Alroy
2026-09-12 10:26:39 -04:00
committed by GitHub
parent 13e221f830
commit 658c8131c7
22 changed files with 372 additions and 270 deletions
+11 -4
View File
@@ -16,10 +16,14 @@ def _make_model_state(
phy2log: torch.Tensor,
log2phy: torch.Tensor,
logcnt: torch.Tensor,
phy2log_storage: torch.Tensor | None = None,
) -> MagicMock:
"""Build a minimal EplbModelState mock with only the three map tensors."""
"""Build a minimal EplbModelState mock with its map tensors."""
state = MagicMock()
state.physical_to_logical_map = phy2log
state.physical_to_logical_map_buffer = (
phy2log if phy2log_storage is None else phy2log_storage
)
state.logical_to_physical_map = log2phy
state.logical_replica_count = logcnt
return state
@@ -27,15 +31,17 @@ def _make_model_state(
def test_commit_eplb_maps_shape_change():
"""
The normal path copies the physical_to_logical map in-place. When the number of
physical experts changes, the old map should be replaced entirely.
When the number of physical experts changes, resize the active map within its
preallocated storage.
"""
num_layers, num_logical, num_physical = 2, 4, 6
max_replicas = 3
# Build current state tensors
storage = torch.full((num_layers, num_physical + 2), -1, dtype=torch.long)
model_state = _make_model_state(
phy2log=torch.zeros(num_layers, num_physical, dtype=torch.long),
phy2log=storage[:, :num_physical],
phy2log_storage=storage,
log2phy=torch.full(
(num_layers, num_logical, max_replicas), -1, dtype=torch.long
),
@@ -54,6 +60,7 @@ def test_commit_eplb_maps_shape_change():
# Check that the number of physical experts has been updated and that the values
# match
assert model_state.physical_to_logical_map.shape[1] == num_physical + 2
assert model_state.physical_to_logical_map.data_ptr() == storage.data_ptr()
assert torch.equal(model_state.physical_to_logical_map, new_phy2log_larger)