Skip to content
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

How to get gpu global rank in the dataloader model? #19331

Closed
FakeEnd opened this issue Jan 23, 2024 · 2 comments
Closed

How to get gpu global rank in the dataloader model? #19331

FakeEnd opened this issue Jan 23, 2024 · 2 comments
Labels
question Further information is requested

Comments

@FakeEnd
Copy link

FakeEnd commented Jan 23, 2024

Description & Motivation

My custom dataset using a numpy sampler to get data. If I cannot use different seed for different GPU/nodes, it will use the same seed forked from main process, which will sample the same data. So, I want to get global rank in LightningDataModule.train_dataloader to create different dataloader for different GPU/nodes. I see there is a local rank property in here, but when I try to use self.local_rank to get it, it fails.

Pitch

No response

Alternatives

No response

Additional context

No response

cc @Borda

@FakeEnd FakeEnd added feature Is an improvement or enhancement needs triage Waiting to be triaged by maintainers labels Jan 23, 2024
@awaelchli
Copy link
Contributor

Hey
In LightningDataModule, you have to do self.trainer.local_rank.

class MyDataModule(LightningDataModule):
    def train_dataloader(self):
        print(self.trainer.local_rank)
        return DataLoader(MyDataset(...))

@awaelchli awaelchli added question Further information is requested and removed feature Is an improvement or enhancement needs triage Waiting to be triaged by maintainers labels Jan 23, 2024
@FakeEnd FakeEnd closed this as completed Jan 23, 2024
@ssharpe42
Copy link

@awaelchli when is self.trainer set in the data module?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants