1221: DataLoader with NamedTuple r=CarloLucibello a=cossio
Just a couple of small changes, so that `DataLoader` can be created with a `NamedTuple` of tensors instead of `Tuple`. This way the tensors can be referred to by name. For example
```
train_loader = DataLoader((images = Xtrain, labels = Ytrain), batchsize=16)
batch = first(train_loader)
y = model(batch.images)
logitcrossentropy(y, batch.labels)
```
If we only use tuples, then in datasets with multiple tensors one has to be careful about the order in which the tensors are fed into the `DataLoader` constructor and be consistent with this elsewhere. With `NamedTuples` one just have to be consistent about the names used, which I think is a minor improvement.
CC @CarloLucibello
### PR Checklist
- [x] Tests are added
- [x] Entry in NEWS.md
- [x] Documentation, if applicable
I don't think this qualifies as an API change. It's just a minor feature addition. So final review probably not required.
- [ ] Final review from `@MikeInnes` or `@dhairyagandhi96` (for API changes).
Co-authored-by: cossio <j.cossio.diaz@gmail.com>
Co-authored-by: cossio <cossio@users.noreply.github.com>
1213: Fixing indentation in train! docstring r=CarloLucibello a=natema
One code block is not correctly displayed in the doc of [Flux.Optimise.train!
](https://fluxml.ai/Flux.jl/stable/training/training/#Flux.Optimise.train!).
Based on the previous code block, I guess it's an indentation problem.
Co-authored-by: natema <natema@users.noreply.github.com>
1152: extend dataloader r=CarloLucibello a=CarloLucibello
cfr discussion in #1149. Currently DataLoader interface supports
1. `for x in DataLoader(X)`
2. `for (x, y) in DataLoader(X, Y)`
This PR adds
3. `for (x,) in DataLoader((X,))`
4. `for (x, y) in DataLoader((X, Y))`
Edit:
the constructor in 2. is removed in this PR
Co-authored-by: CarloLucibello <carlo.lucibello@gmail.com>
1129: Added dropgrad in huber_loss r=CarloLucibello a=HenriDeh
Workaround to prevent `iterate(::nothing)` when working with CuArrays. See issue #1128
Co-authored-by: HenriDeh <47037088+HenriDeh@users.noreply.github.com>
1141: Speedup matmul of CuMatrix and OneHotMatrix r=CarloLucibello a=AStupidBear
This solves #189.
```julia
julia> using Flux
julia> using Flux: CuArrays
julia> A = zeros(300, 10000) |> gpu;
julia> B = Flux.onehotbatch(rand(1:10000, 256), 1:10000) |> gpu;
julia> A * B; CuArrays.@time A * B;
┌ Warning: Performing scalar operations on GPU arrays: This is very slow, consider disallowing these operations with `allowscalar(false)`
└ @ GPUArrays ~/shared/.julia/packages/GPUArrays/OXvxB/src/host/indexing.jl:43
0.002824 seconds (951 CPU allocations: 38.156 KiB) (2 GPU allocations: 301.000 KiB, 2.32% gc time of which 46.42% spent allocating)
julia> import Base: *
julia> A::AbstractMatrix * B::Flux.OneHotMatrix = @inbounds A[:, map(x->x.ix, B.data)]
* (generic function with 522 methods)
julia> A * B; CuArrays.@time A * B;
0.000343 seconds (169 CPU allocations: 5.000 KiB) (2 GPU allocations: 301.000 KiB, 15.53% gc time of which 65.97% spent allocating)
```
Co-authored-by: Yao Lu <luyaocns@gmail.com>
1165: Fix docstring of logitcrossentropy r=dhairyagandhi96 a=cossio
Since `y` is a logit, there is no log (see the diff).
Co-authored-by: cossio <cossio@users.noreply.github.com>
1174: Functors r=MikeInnes a=MikeInnes
Just splits out the implementation to the [Functors](https://github.com/FluxML/Functors.jl) package, so the same traits can be used elsewhere (e.g. Optimisers.jl) without depending on all of Flux.
Co-authored-by: Mike J Innes <mike.j.innes@gmail.com>