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

Fix for onecold broadcast bug #764

Merged
merged 5 commits into from
Jul 4, 2020
Merged

Conversation

DhairyaLGandhi
Copy link
Member

@DhairyaLGandhi DhairyaLGandhi commented May 4, 2019

Using mapreduce was returning an Array when used with OneHotMatrix{CuArray}. This causes issues down the chain. map avoids that, and also avoids the reduction giving slightly better speed (~40x).

@DhairyaLGandhi
Copy link
Member Author

bors try

bors bot added a commit that referenced this pull request May 4, 2019
@bors
Copy link
Contributor

bors bot commented May 4, 2019

try

Build succeeded

@KristofferC
Copy link
Contributor

KristofferC commented May 4, 2019

What was the bug? Could the existing test be tweaked or added to in order to catch it?

@DhairyaLGandhi
Copy link
Member Author

DhairyaLGandhi commented May 4, 2019

mapreduce is returning an Array with a OneHotMatrix{CuArray}.

I think we already have the test that is supposed to check for this

@test Flux.onecold(y) isa CuArray

Maybe we should add an extra one that checks for the broadcasting just like in the accuracy function?

Edit: I should've written the description properly, and I shall change that to reflect what changes are made and why.

@MikeInnes
Copy link
Member

The diff looks odd to me -- if this can be done with a simple map, why was it written with mapreduce before? Is there a behaviour change or was the original code just redundant?

If there's no behaviour change then this is certainly good to go.

@DhairyaLGandhi
Copy link
Member Author

We needed to hit an optimised kernel with the GPU at the time (iirc, because it's been a while since this has been up), but things have moved on massively since then and the regular way works fine now.

No change in behaviour

@darsnack
Copy link
Member

darsnack commented Mar 24, 2020

I think this will address #864 issues as well. This addresses the comment I made on #864. String labels will still fail to work on the GPU. Any other delays on this other than possibly wanting to be consistent with #1006?

@DhairyaLGandhi
Copy link
Member Author

Bump

@MikeInnes
Copy link
Member

I'm not totally clear on the testing situation; if there's a test for this already, why isn't it failing currently? Can we add the test that would fail without this patch?

@lassepe
Copy link
Contributor

lassepe commented Jun 18, 2020

A test that would fail right now is the following identity:

using Flux: onehotbatch, onecold
using Test

data = [:b, :a, :c]
labels = [:a, :b, :c]
hot = onehotbatch(data, labels)
cold = onecold(hot, labels)

@test cold == data

This is something that works with the new map version of onecold.

However, I don't know why the the reduce with | was necessary (I guess there is/was a good reason to do it like this). From #1214 one can at least infer that at some point onehotbatch used to produce matrices with eltype Bool.

@lassepe
Copy link
Contributor

lassepe commented Jun 18, 2020

Perhaps another relevant data point:

When the mapreduce version of onecold was first introduced, it seems like there was no test for this. The only thing tested is the 1-argument-version. In that case the reduce is simply a 0 | x::Int which should just give x. The 2-argument version where (potentially non-Integer) labels are passed is only tested with Base.Matrix not with Flux.OneHotMatrix.

@darsnack
Copy link
Member

I think the original reason was for some CUDA optimization. But this PR really should get some attention.

@CarloLucibello
Copy link
Member

@DhairyaLGandhi could you add the test from #764 (comment) and get this merged?

@DhairyaLGandhi
Copy link
Member Author

bors r+

bors bot added a commit that referenced this pull request Jul 3, 2020
764: Fix for onecold broadcast bug r=DhairyaLGandhi a=DhairyaLGandhi

Using `mapreduce` was returning an `Array` when used with `OneHotMatrix{CuArray}`. This causes issues down the chain. `map` avoids that, and also avoids the reduction giving slightly better speed (~40x).

Co-authored-by: Dhairya Gandhi <dhairya@juliacopmuting.com>
@bors
Copy link
Contributor

bors bot commented Jul 3, 2020

Build failed:

@CarloLucibello
Copy link
Member

bors r+

@bors
Copy link
Contributor

bors bot commented Jul 4, 2020

Build succeeded:

@bors bors bot merged commit 630d6c5 into FluxML:master Jul 4, 2020
@DhairyaLGandhi DhairyaLGandhi mentioned this pull request Dec 31, 2020
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 this pull request may close these issues.

6 participants