meta-pytorch / meta-pytorch/data

Register Functional API to different DataPipe class

Open
#200 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
@functional_datapipe("func")
class IterToMapMapDataPipe(MapDataPipe):
    def __init__(self, datapipe: IterDataPipe):
        self.datapipe = datapipe

Using the functional_datapipe above would register this functional API to MapDataPipe. As we want to register this functional_datapiep to the IterDataPipe, I have to do the following trick.

class IterToMapMapDataPipe(MapDataPipe):
    def __init__(self, datapipe: IterDataPipe):
        self.datapipe = datapipe

IterDataPipe.register_datapipe_as_function("func", IterToMapMapDataPipe)
Motivation, pitch

Option 1:
Use the type annotation of the first input datapipe from __init__ or __new__ function to determine which DataPipe class we should register.

class IterToMapMapDataPipe(MapDataPipe):
    def __init__(self, datapipe: IterDataPipe):  # <---------- IterDataPipe here is used to register
        self.datapipe = datapipe

Option 2:
Add an optional argument for functional_datapipe API to explicitly set the right DataPipe class.

@functional_datapipe("func", register_cls=IterDataPipe)
class IterToMapMapDataPipe(MapDataPipe):
    def __init__(self, datapipe: IterDataPipe):
        self.datapipe = datapipe
Alternatives

No response

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 reading the functional_datapipe API and the register_datapipe_as_function entry point mentioned in the issue. Compare the proposed annotation-based and explicit register_cls approaches, then determine which registration behavior the project should support. Done means a functional API can be registered against a different DataPipe class without the manual workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
backend-api-design, data-engineering
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.