FluxML / Flux.jl

Relax! Flux is the ML library that doesn't make you tensor
https://fluxml.ai/
Other
4.55k stars 609 forks source link

device movement behavior inconsistent #2513

Open chengchingwen opened 3 weeks ago

chengchingwen commented 3 weeks ago
julia> using Flux, CUDA

julia> x = randn(5); x2 = (x, x); cx2 = gpu(x2);

julia> cx2[1] === cx2[2] # Flux v0.14.24
false

julia> cx2[1] === cx2[2] # Flux v0.14.20
true

It would cause problems for weight sharing. Probably due to #2502

CarloLucibello commented 3 weeks ago

This issue is due to MLDataDevices specializing on tuples and not keeping an IdDict for those. It should be fixed.

For functor types instead it works as expected:

julia> struct A; x; y; end

julia> Functors.@functor A

julia> a = A(x, x);

julia> ca = gpu(a);

julia> ca.x === ca.y # Flux v0.14.24
true