-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Queue length modification with the use of DDP #1127
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num_subjects() iterations_per_epoch() modified
for more information, see https://pre-commit.ci
This makes total sense. I've added some minor readability changes and tested the new implementation as follows: import os
import torch
import torch.distributed as dist
import torchio as tio
from loguru import logger
num_subjects = 6
samples_per_volume = 2
max_length = 1000
subjects = []
tensor = torch.ones(1, 16, 16, 16)
for i in range(num_subjects):
subject = tio.Subject(
image=tio.ScalarImage(tensor=i * tensor),
id=i,
)
subjects.append(subject)
dataset = tio.SubjectsDataset(subjects)
is_distributed = bool(os.environ.get('WORLD_SIZE'))
if is_distributed:
dist.init_process_group()
subject_sampler = torch.utils.data.distributed.DistributedSampler(
dataset,
shuffle=False,
)
rank = dist.get_rank()
else:
subject_sampler = None
rank = 0
patch_sampler = tio.sampler.UniformSampler(patch_size=2)
queue = tio.Queue(
dataset,
max_length,
sampler=patch_sampler,
samples_per_volume=samples_per_volume,
num_workers=0,
shuffle_subjects=False,
shuffle_patches=False,
subject_sampler=subject_sampler,
)
loader = torch.utils.data.DataLoader(
queue,
batch_size=1,
num_workers=0,
shuffle=False,
collate_fn=lambda x: x[0],
)
for i, patch in enumerate(loader):
logger.info(f'Rank {rank} | Batch {i} | Subject {patch["id"]}') Run with torchrun --nproc_per_node=3 /tmp/ddp.py Output:
|
Thanks for your contribution, @haughty-yeon! @allcontributors please add @haughty-yeon for bug |
I couldn't determine any contributions to add, did you specify any contributions? I've put up a pull request to add @haughty-yeon! 🎉 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
num_subjects()
iterations_per_epoch()
modified
Fixes #1125.
Description
Checklist
CONTRIBUTING
docs and have a developer setup (especially important arepre-commit
andpytest
)pytest
make html
inside thedocs/
folder