Lightning-AI / Lightning-AI/pytorch-lightning

Ensure `torch.nn.Modules` in `DataModule` get moved to proper device

Open
#19,662 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
31.4k
Forks
3.8k
Avg merge
6d 7h
Merged PRs (30d)
6

Description

### Description & Motivation

I have on gpu augmentations I perform via some custom `torch.nn.Modules` I define in my `LightningDataModule`. How can I ensure these get moved to the correct device during distributed training so I can use them in the `on_after_batch_transfer` hook?

### Pitch

_No response_

### Alternatives

_No response_

### Additional context

_No response_

cc @borda

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how LightningDataModule handles device placement and how the on_after_batch_transfer hook is invoked during distributed training. The work is done when custom torch.nn.Modules owned by a DataModule are moved to the correct device and can be used safely from that hook.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
distributed-systems, machine-learning
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.