meta-pytorch / meta-pytorch/data
A more powerful Mapper than can restrict function application to only part of the datapipe items?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.3k
- Forks
- 179
- Avg merge
- 6d 1h
- Merged PRs (30d)
- 2
Description
We often have datapipes that return tuples (img, target) where we just want to call transformations on the img, but not the target. Sometimes it's the opposite: I want to apply a function to the target, and not to the img.
This usually forces us to write wrappers that "passthrough" either the img or the target. For example:
def decode_img_only(data): # boilerplate wrapper
img, target = data
img = decode(img)
return img, data
def resize_img_only(data): # boilerplate wrapper
img, target = data
img = resize(img)
return img, data
def add_label_noise(data): # boilerplate wrapper
img, target = data
target = make_noisy_label(target)
return img, data
dp = ...
dp = dp.map(decode_img_only).map(resize_img_only).map(add_label_noise)
Perhaps a more convenient way of doing this would be to implement something similar to WebDataset's map_dict and map_tuple? This would avoid all the boilerplate wrappers. For example we could imagine the code above to simply be:
dp = ...
dp = dp.map_tuple(decode, None).map(resize, None).map(None, make_noisy_label)
# or even
dp = dp.map_tuple(decode, None).map(resize, make_noisy_label)
# if the datapipes was returning a dict with "img" and "target" keys this could also be
dp = dp.map_dict("img"=decode).map_dict("img"=decode, "target"=make_noisy_label)
I even think it might be possible to implement all of map_dict() and map_tuple() functionalities withing the .map() function:
- 1 arg == current
map() - 1+ arg ==
map_tuple() - keyword arg ==
map_dict()
CC @pmeier and @msaroufim to whom this might be of interest
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
The issue names no implementation files or tests. Start by locating the existing DataPipe .map implementation and its test coverage, then resolve whether tuple/dict selection belongs in new map_tuple/map_dict methods or map; done means selected elements transform while unselected elements pass through without wrappers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-engineering
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100