meta-pytorch / meta-pytorch/data

Additional basic functions beyond .map to allow for more functional programming

Open
#1,145 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.3k
Forks
179
Avg merge
6d 1h
Merged PRs (30d)
2

Description

🚀 The feature

For IterDataPipe, the .map maps a function over the items of an iterable. where the function has the form

f: Any -> Any

Other basic building blocks could be .pipe, .iter_map and .comsume. where

  • .pipe would take f: Iterable -> Iterable
  • .iter_map takes f: Any -> Iterable
  • .comsume takes f: Iterable -> Any
Motivation, pitch

Such an approach would allow for more flexible functional programming and would reduce most currently provided IterDataPipe classes to a simple functional call. For example

The Enumerator class would become

dp.pipe(enumerate)

This would immediately enable to use all itertools functions in this context.

The TarArchiveLoader could become

def iter_from_tar_archive(fd):
    .<code to yield files from tar archive >
dp.iter_map(iter_from_tar_archive)

I believe using this approach, almost all provided classes could be written using less boilerplate using generator functions (essentially just writing the code inside __iter__ as a standalone generator function, possibly curried for convenience if other parameters are being used).

Would be great to hear if this was considered? Thanks!

Alternatives

The .pipe can already be written as

dp2 = IterableWrapper(enumerate(dp)) 

but I believe this would be a lot less nice than the above

dp.pipe(enumerate)
Additional context

No response

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 reviewing the existing IterDataPipe API and the IterableWrapper, Enumerator, and TarArchiveLoader examples named in the issue. Clarify the semantics and scope of pipe, iter_map, and consume, then establish the expected API and coverage before implementation; the issue currently presents a design proposal rather than a defined change.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.