2022-04-12 06:57:54 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
import colossalai
|
2023-09-18 08:31:06 +00:00
|
|
|
from colossalai.legacy.utils.memory import colo_device_memory_capacity, colo_set_process_memory_fraction
|
2023-04-06 06:51:35 +00:00
|
|
|
from colossalai.testing import spawn
|
2022-04-12 06:57:54 +00:00
|
|
|
from colossalai.utils.cuda import get_current_device
|
|
|
|
|
|
|
|
|
|
|
|
def _run_colo_set_process_memory_fraction_and_colo_device_memory_capacity():
|
|
|
|
frac1 = colo_device_memory_capacity(get_current_device())
|
|
|
|
colo_set_process_memory_fraction(0.5)
|
|
|
|
frac2 = colo_device_memory_capacity(get_current_device())
|
|
|
|
assert frac2 * 2 == frac1
|
|
|
|
|
|
|
|
|
|
|
|
def run_dist(rank, world_size, port):
|
2023-09-19 06:20:26 +00:00
|
|
|
colossalai.legacy.launch(config={}, rank=rank, world_size=world_size, host="localhost", port=port, backend="nccl")
|
2022-04-12 06:57:54 +00:00
|
|
|
_run_colo_set_process_memory_fraction_and_colo_device_memory_capacity()
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.dist
|
2022-06-08 15:14:18 +00:00
|
|
|
@pytest.mark.parametrize("world_size", [3, 4])
|
2022-04-12 06:57:54 +00:00
|
|
|
def test_memory_utils(world_size):
|
2023-04-06 06:51:35 +00:00
|
|
|
spawn(run_dist, world_size)
|
2022-04-12 06:57:54 +00:00
|
|
|
|
|
|
|
|
2023-09-19 06:20:26 +00:00
|
|
|
if __name__ == "__main__":
|
2022-04-12 06:57:54 +00:00
|
|
|
test_memory_utils(world_size=2)
|