Skip to content
Merged
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
16 changes: 14 additions & 2 deletions tests/zero_code_change/pt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,34 @@
import torch.nn.functional as F
import torchvision
import torchvision.transforms as transforms
from packaging import version


def get_dataloaders() -> Tuple[torch.utils.data.DataLoader, torch.utils.data.DataLoader]:
transform = transforms.Compose(
[transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))]
)

# Temporary Change to allow the test to run with pytorch 1.7 RC3
# Smdebug breaks when num_workers>0 for Pytorch 1.7.0
if version.parse(torch.__version__) >= version.parse("1.7.0"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Shouldn't this check the version of torchvision instead of torch since you've already identified that the issue is caused by a dataloader coming from torchvision?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dataloader is defined in Torch torch.utils.data.DataLoader.

num_workers = 0
else:
num_workers = 2

trainset = torchvision.datasets.CIFAR10(
root="./data", train=True, download=True, transform=transform
)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=4, shuffle=True, num_workers=2)
trainloader = torch.utils.data.DataLoader(
trainset, batch_size=4, shuffle=True, num_workers=num_workers
)

testset = torchvision.datasets.CIFAR10(
root="./data", train=False, download=True, transform=transform
)
testloader = torch.utils.data.DataLoader(testset, batch_size=4, shuffle=False, num_workers=2)
testloader = torch.utils.data.DataLoader(
testset, batch_size=4, shuffle=False, num_workers=num_workers
)

classes = ("plane", "car", "bird", "cat", "deer", "dog", "frog", "horse", "ship", "truck")
return trainloader, testloader
Expand Down