Skip to content

Extend collate function that can register collate functions to handle specific types#85748

Closed
ejguan wants to merge 6 commits intopytorch:masterfrom
ejguan:extend_collate
Closed

Extend collate function that can register collate functions to handle specific types#85748
ejguan wants to merge 6 commits intopytorch:masterfrom
ejguan:extend_collate

Conversation

@ejguan
Copy link
Copy Markdown
Contributor

@ejguan ejguan commented Sep 27, 2022

As per request from Vision team, adding collate function with an extra argument of collate_fn_map to dispatch custom collate functions for non-collection objects and specific objects.
If the type of batch element is not present incollate_fn_map, it will go through all keys in the insertion order to check if the type is a subclass of the key. If so, it will invoke the corresponding collate functions.

And, default_collate will utilize the collate function with a few by default collate function for int, float, str and numpy object.

Benefit:

  • Domain teams can register their own collate function to handle their specific type of objects
  • Easier for users to extend from the collate function.

@ejguan ejguan requested a review from pmeier September 27, 2022 20:00
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot bot commented Sep 27, 2022

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/85748

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures, 20 Pending

As of commit aa1a84d:
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot bot added the release notes: dataloader release notes category label Sep 27, 2022
@ejguan ejguan added the topic: improvements topic category label Sep 27, 2022
Copy link
Copy Markdown
Contributor

@NivekT NivekT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this. Overall, this makes sense to me. I think we should make it clear to users about how they can extend collate and default_collate (provide examples) and what the best practices may be.

For example:

  1. They can write their own collate_fn_map and create their own collate function with that
  2. They can write their own collate function that imports and uses default_collate?

Copy link
Copy Markdown
Collaborator

@pmeier pmeier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Erjia! I left a few inline comments.

@ejguan ejguan requested review from NivekT and pmeier September 28, 2022 16:27
Copy link
Copy Markdown
Contributor

@NivekT NivekT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for making the changes. A small comment but feel free to ignore.

We should import and render the documentation for these functions in TorchData (or in core documentation) for the upcoming release.

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 28, 2022
@ejguan
Copy link
Copy Markdown
Contributor Author

ejguan commented Sep 28, 2022

We should import and render the documentation for these functions in TorchData (or in core documentation) for the upcoming release.

Let me see how to add it to PyTorch Core doc.

Copy link
Copy Markdown
Collaborator

@pmeier pmeier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM when the documentation issue is sorted out and CI is green. Thanks Erjia!

@ejguan
Copy link
Copy Markdown
Contributor Author

ejguan commented Sep 29, 2022

@pytorchbot rebase

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a rebase job. Check the current status here

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Successfully rebased extend_collate onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout extend_collate && git pull --rebase)

@ejguan
Copy link
Copy Markdown
Contributor Author

ejguan commented Sep 29, 2022

@pytorchbot merge -g

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a merge job. Check the current status here.
The merge job was triggered with the green (-g) flag. This means that your change will be merged once all checks on your PR have passed (ETA: 0-4 Hours). If this is not the intended behavior, feel free to use some of the other merge options in the wiki.
Please reach out to the PyTorch DevX Team with feedback or questions!

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Merge failed

Reason: The following mandatory check(s) failed (Rule superuser):

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

@ejguan
Copy link
Copy Markdown
Contributor Author

ejguan commented Sep 29, 2022

@pytorchbot rebase -m

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot bot commented Sep 29, 2022

❌ 🤖 pytorchbot command failed:

@pytorchbot: error: unrecognized arguments: -m

usage: @pytorchbot [-h] {merge,revert,rebase,label} ...

Try @pytorchbot --help for more info.

@ejguan
Copy link
Copy Markdown
Contributor Author

ejguan commented Sep 29, 2022

@pytorchbot rebase -b master

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a rebase job. Check the current status here

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Successfully rebased extend_collate onto refs/remotes/origin/master, please pull locally before adding more changes (for example, via git checkout extend_collate && git pull --rebase)

@ejguan
Copy link
Copy Markdown
Contributor Author

ejguan commented Sep 29, 2022

@pytorchbot merge -g

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a merge job. Check the current status here.
The merge job was triggered with the green (-g) flag. This means that your change will be merged once all checks on your PR have passed (ETA: 0-4 Hours). If this is not the intended behavior, feel free to use some of the other merge options in the wiki.
Please reach out to the PyTorch DevX Team with feedback or questions!

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Merge failed

Reason: The following mandatory check(s) failed (Rule superuser):

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

@ejguan
Copy link
Copy Markdown
Contributor Author

ejguan commented Sep 29, 2022

Have to manually rebase onto the safest commits on master due to the broken viable/strict branch.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@ejguan has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@ejguan
Copy link
Copy Markdown
Contributor Author

ejguan commented Sep 29, 2022

@pytorchbot merge -g

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a merge job. Check the current status here.
The merge job was triggered with the green (-g) flag. This means that your change will be merged once all checks on your PR have passed (ETA: 0-4 Hours). If this is not the intended behavior, feel free to use some of the other merge options in the wiki.
Please reach out to the PyTorch DevX Team with feedback or questions!

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Merge failed

Reason: The following mandatory check(s) failed (Rule superuser):

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

@ejguan
Copy link
Copy Markdown
Contributor Author

ejguan commented Sep 30, 2022

@pytorchbot rebase

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a rebase job. Check the current status here

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Successfully rebased extend_collate onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout extend_collate && git pull --rebase)

@ejguan
Copy link
Copy Markdown
Contributor Author

ejguan commented Sep 30, 2022

@pytorchbot merge -g

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a merge job. Check the current status here.
The merge job was triggered with the green (-g) flag. This means that your change will be merged once all checks on your PR have passed (ETA: 0-4 Hours). If this is not the intended behavior, feel free to use some of the other merge options in the wiki.
Please reach out to the PyTorch DevX Team with feedback or questions!

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 additional jobs have failed, first few of them are: Meta Internal-Only Changes Check

Details for Dev Infra team Raised by workflow job

@ejguan
Copy link
Copy Markdown
Contributor Author

ejguan commented Sep 30, 2022

@pytorchbot merge -f "The internal signal is cyclic referenced to OSS failure on a previous commit"

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a merge job. Check the current status here.
The merge job was triggered with the force (-f) flag. This means your change will be merged immediately, bypassing any CI checks (ETA: 1-5 minutes). If this is not the intended behavior, feel free to use some of the other merge options in the wiki.
Please reach out to the PyTorch DevX Team with feedback or questions!

mehtanirav pushed a commit that referenced this pull request Oct 4, 2022
… specific types (#85748)

As per request from Vision team, adding `collate` function with an extra argument of `collate_fn_map` to dispatch custom collate functions for non-collection objects and specific objects.
If the type of batch element is not present in`collate_fn_map`, it will go through all keys in the insertion order to check if the type is a subclass of the key. If so, it will invoke the corresponding collate functions.

And, `default_collate` will utilize the `collate` function with a few by default collate function for `int`, `float`, `str` and `numpy object`.

Benefit:
- Domain teams can register their own `collate` function to handle their specific type of objects
- Easier for users to extend from the `collate` function.
Pull Request resolved: #85748
Approved by: https://github.com/NivekT, https://github.com/pmeier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request cla signed Merged release notes: dataloader release notes category topic: improvements topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants