Extend collate function that can register collate functions to handle specific types#85748
Extend collate function that can register collate functions to handle specific types#85748ejguan wants to merge 6 commits intopytorch:masterfrom
Conversation
🔗 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 PendingAs of commit aa1a84d: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
NivekT
left a comment
There was a problem hiding this comment.
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:
- They can write their own
collate_fn_mapand create their own collate function with that - They can write their own collate function that imports and uses
default_collate?
pmeier
left a comment
There was a problem hiding this comment.
Thanks Erjia! I left a few inline comments.
NivekT
left a comment
There was a problem hiding this comment.
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.
Let me see how to add it to PyTorch Core doc. |
pmeier
left a comment
There was a problem hiding this comment.
LGTM when the documentation issue is sorted out and CI is green. Thanks Erjia!
6bcd6e7 to
ae805b6
Compare
|
@pytorchbot rebase |
|
@pytorchbot successfully started a rebase job. Check the current status here |
|
Successfully rebased |
2221ac2 to
c65ca5c
Compare
|
@pytorchbot merge -g |
|
@pytorchbot successfully started a merge job. Check the current status here. |
Merge failedReason: The following mandatory check(s) failed (Rule Dig deeper by viewing the failures on hud Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot rebase -m |
|
❌ 🤖 pytorchbot command failed: Try |
|
@pytorchbot rebase -b master |
|
@pytorchbot successfully started a rebase job. Check the current status here |
|
Successfully rebased |
c65ca5c to
52b159a
Compare
|
@pytorchbot merge -g |
|
@pytorchbot successfully started a merge job. Check the current status here. |
Merge failedReason: The following mandatory check(s) failed (Rule Dig deeper by viewing the failures on hud Details for Dev Infra teamRaised by workflow job |
52b159a to
e2d20ca
Compare
|
Have to manually rebase onto the safest commits on master due to the broken viable/strict branch. |
|
@ejguan has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
@pytorchbot merge -g |
|
@pytorchbot successfully started a merge job. Check the current status here. |
Merge failedReason: The following mandatory check(s) failed (Rule Dig deeper by viewing the failures on hud Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot rebase |
|
@pytorchbot successfully started a rebase job. Check the current status here |
|
Successfully rebased |
e2d20ca to
aa1a84d
Compare
|
@pytorchbot merge -g |
|
@pytorchbot successfully started a merge job. Check the current status here. |
Merge failedReason: 1 additional jobs have failed, first few of them are: Meta Internal-Only Changes Check Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge -f "The internal signal is cyclic referenced to OSS failure on a previous commit" |
|
@pytorchbot successfully started a merge job. Check the current status here. |
… 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
As per request from Vision team, adding
collatefunction with an extra argument ofcollate_fn_mapto 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_collatewill utilize thecollatefunction with a few by default collate function forint,float,strandnumpy object.Benefit:
collatefunction to handle their specific type of objectscollatefunction.