Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Padded batching #78

Closed
casper2002casper opened this issue Apr 19, 2022 · 1 comment · Fixed by #197
Closed

Padded batching #78

casper2002casper opened this issue Apr 19, 2022 · 1 comment · Fixed by #197

Comments

@casper2002casper
Copy link

casper2002casper commented Apr 19, 2022

When working with ANN that output different sized vectors depending on the input (for example when using GraphNeuralNetworks.jl), it would be useful to convert the output of a batch to a CuArray in order to perform loss computations.
Current:

julia> MLUtils.batch([[1,2],[3,4]])
2×2 Matrix{Int64}:
 1  3
 2  4

julia> MLUtils.batch([[1,2],[3]])
ERROR: DimensionMismatch("mismatch in dimension 1 (expected 2 got 1)")

Feature:

julia> MLUtils.batch([[1,2],[3]], pad =  0)
2×2 Matrix{Int64}:
 1  3
 2  0
@darsnack
Copy link
Member

As a temporary workaround, you can do

batches = [[1, 2], [3]]
MLUtils.batch(rpad.(batches, 2, 0))

Probably a variation of this where we pad as we iterate batches would be a possible PR for this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants