Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions fairscale/utils/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import multiprocessing
import os
import random
import sys
import tempfile
from typing import Any, Callable, Dict, List, Optional, Tuple

Expand All @@ -53,6 +54,10 @@
not torch.cuda.is_available() or torch.cuda.device_count() < 2, reason="multiple GPUs required"
)

skip_if_py38 = pytest.mark.skipif(
sys.version_info.major == 3 and sys.version_info.minor == 8, reason="Python3.8 is skipped"
)

_, filename_mpi = tempfile.mkstemp()


Expand Down
13 changes: 7 additions & 6 deletions tests/nn/data_parallel/test_sharded_ddp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from fairscale.nn.data_parallel import ShardedDataParallel
from fairscale.optim import OSS
from fairscale.utils.testing import GPT2, skip_if_no_cuda, skip_if_single_gpu
from fairscale.utils.testing import GPT2, skip_if_no_cuda, skip_if_py38, skip_if_single_gpu


def run_one_step(rank, world_size, backend, device, temp_file_name):
Expand Down Expand Up @@ -112,16 +112,17 @@ def run_test(backend, device, world_size=2):
mp.spawn(run_one_step, args=(world_size, backend, device, temp_file_name), nprocs=world_size, join=True)


def test_step_on_cpu():
run_test(backend=dist.Backend.GLOO, device=torch.device("cpu"), world_size=4)


@skip_if_no_cuda
@skip_if_single_gpu
def test_step_on_gpu():
def test_step_gpu():
run_test(backend=dist.Backend.NCCL, device=torch.device("cuda"))


@skip_if_py38
def test_step_cpu():
run_test(backend=dist.Backend.GLOO, device=torch.device("cpu"))


def run_ddp_parity(rank, world_size, backend, temp_file_name):
url = "file://" + temp_file_name
dist.init_process_group(init_method=url, backend=backend, rank=rank, world_size=world_size)
Expand Down