Lightning-AI / Lightning-AI/pytorch-lightning
combined_loader: concatenating inputs
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 31.4k
- Forks
- 3.8k
- Avg merge
- 6d 7h
- Merged PRs (30d)
- 6
Description
### Description & Motivation
Application: using the combined data loader with two datasets of the same format
Suggestion: option for concatenating the data + labels in the combined loader
Motivation: currently one has to edit model code when data source is changed -> very unelegant solution and likely leads to errors!
Comment: Maybe I just did not understand the documentation right. if so please improve the documentation. :-)
currently I use:
```
iterables = {"dataset1": dataloader1, "dataset2": dataloader2}
combined_loader = CombinedLoader(iterables, mode="min_size")
```
and have to unpack the data in the models training step using:
```
def training_step(self,batch,batch_idx):
#batch1,batch2 = batch
x = torch.concat([batch['dataset1'][0],batch['dataset2'][0]])
y = torch.concat([batch['dataset1'][1],batch['dataset2'][1]])
```
### Pitch
It would be great to have something like this (example for regression tasks on images):
```
dataloader1 = DataLoader(..., batch_size = b1)
dataloader2 = DataLoader(..., batch_size = b2)
iterables = {"dataset1": dataloader1, "dataset2": dataloader2}
combined_loader = CombinedLoader(iterables, mode = 'min_size', operation = 'concat')
x,y = next(iter(combined_loader)
# x.shape = [b1+b2,h,w,c]
# y.shape = [b1+b2]
```
### Alternatives
_No response_
### Additional context
_No response_
cc @borda @justusschock @awaelchli
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the CombinedLoader API and its current min_size behavior, then compare it with the shown training_step concatenation and proposed next(iter(combined_loader)) result. Done means the requested operation is clearly defined and the combined loader can produce concatenated data and labels for the two same-format datasets without model-side unpacking.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100