Skip to content
Open
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
13 changes: 5 additions & 8 deletions tests/nn/pipe/test_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from collections import OrderedDict
from copy import deepcopy
import time
import warnings

import pytest
import torch
Expand Down Expand Up @@ -123,23 +124,19 @@ def test_batch_size_indivisible():
model = nn.Sequential(nn.Linear(1, 1))
model = Pipe(model, balance=[1], devices=["cpu"], chunks=4)

with pytest.warns(None) as record:
with warnings.catch_warnings(action="error"):
# Indivisible batch size is legal.
model(torch.rand(7, 1))

# Indivisible batch size is legal.
assert not record


def test_batch_size_small():
model = nn.Sequential(nn.Linear(1, 1))
model = Pipe(model, balance=[1], devices=["cpu"], chunks=4)

with pytest.warns(None) as record:
with warnings.catch_warnings(action="error"):
# Batch size smaller than chunks is legal.
model(torch.rand(2, 1))

# Batch size smaller than chunks is legal.
assert not record


def test_checkpoint_mode():
def count_grad_fn(grad_fn, name, visited=set()):
Expand Down
13 changes: 5 additions & 8 deletions tests/nn/pipe_process/test_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from copy import deepcopy
import os
import time
import warnings

import pytest
import torch
Expand Down Expand Up @@ -222,25 +223,21 @@ def batch_size_indivisible(pipe_class):
model = nn.Sequential(nn.Linear(1, 1))
model = pipe_class(model, balance=[1], worker_map=get_worker_map(), chunks=4)

with pytest.warns(None) as record:
with warnings.catch_warnings(action="error"):
# Indivisible batch size is legal.
model(torch.rand(7, 1))

# Indivisible batch size is legal.
assert not record


@torch_spawn([1])
@pytest.mark.parametrize("pipe_class", [AsyncPipe])
def batch_size_small(pipe_class):
model = nn.Sequential(nn.Linear(1, 1))
model = pipe_class(model, balance=[1], worker_map=get_worker_map(), chunks=4)

with pytest.warns(None) as record:
with warnings.catch_warnings(action="error"):
# Batch size smaller than chunks is legal.
model(torch.rand(2, 1))

# Batch size smaller than chunks is legal.
assert not record


@torch_spawn([1])
@pytest.mark.parametrize("pipe_class", [AsyncPipe])
Expand Down