test_pipeline_partition.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. import os
  2. import pytest
  3. from aphrodite.distributed.utils import get_pp_indices
  4. def test_custom_layer_partition():
  5. def _verify(partition_str, num_layers, pp_size, goldens):
  6. bak = os.environ.get("APHRODITE_PP_LAYER_PARTITION", None)
  7. os.environ["APHRODITE_PP_LAYER_PARTITION"] = partition_str
  8. for pp_rank, golden in enumerate(goldens):
  9. assert get_pp_indices(num_layers, pp_rank, pp_size) == golden
  10. if bak is not None:
  11. os.environ["APHRODITE_PP_LAYER_PARTITION"] = bak
  12. # Even partition
  13. _verify("5,5,5,5", 20, 4, [(0, 5), (5, 10), (10, 15), (15, 20)])
  14. # Balanced partition
  15. _verify("4,6,6,4", 20, 4, [(0, 4), (4, 10), (10, 16), (16, 20)])
  16. # Put reminder somewhere
  17. _verify("5,6,5,6", 22, 4, [(0, 5), (5, 11), (11, 16), (16, 22)])
  18. # Invalid partition strings
  19. with pytest.raises(ValueError):
  20. _verify("5,5,5,5,", 20, 4, [(0, 5), (5, 10), (10, 15), (15, 20)])
  21. with pytest.raises(ValueError):
  22. _verify("5,5,5,a", 20, 4, [(0, 5), (5, 10), (10, 15), (15, 20)])
  23. # Wrong number of partitions
  24. with pytest.raises(ValueError):
  25. _verify("5,5,5", 20, 4, [(0, 5), (5, 10), (10, 15), (15, 20)])
  26. # Wrong number of layers
  27. with pytest.raises(ValueError):
  28. _verify("5,5,5,5", 21, 4, [(0, 5), (5, 10), (10, 15), (15, 20)])