Skip to content

Calling cpu on FastChain fails. #578

@adrhill

Description

@adrhill

I'm writing a script that I want to run on both GPUs and CPUs by specifying a device.
While calling gpu on a FastChain works fine, cpu fails.

I'm running the lastest releases: DiffEqFlux v1.39.0 and Flux v0.12.4.


Here is a minimal example:

using DiffEqFlux
using Flux

device = Flux.cpu

# Works
c1 = Chain(Dense(2, 10, tanh)) |> device

# Fails
c2 = FastChain(FastDense(2, 10, tanh))  |> device

and the resulting stacktrace:

ERROR: LoadError: ArgumentError: tuple length should be ≥ 0, got -3
Stacktrace:
  [1] _ntuple(f::Adapt.var"#3#5"{FastDense{typeof(tanh), DiffEqFlux.var"#initial_params#89"{Vector{Float32}}}}, n::Int64)
    @ Base ./ntuple.jl:36
  [2] ntuple
    @ ./ntuple.jl:19 [inlined]
  [3] adapt_structure
    @ ~/.julia/packages/Adapt/RGNRk/src/base.jl:16 [inlined]
  [4] adapt
    @ ~/.julia/packages/Adapt/RGNRk/src/Adapt.jl:40 [inlined]
  [5] #1
    @ ~/.julia/packages/Adapt/RGNRk/src/base.jl:3 [inlined]
  [6] map
    @ ./tuple.jl:213 [inlined]
  [7] adapt_structure
    @ ~/.julia/packages/Adapt/RGNRk/src/base.jl:3 [inlined]
  [8] adapt
    @ ~/.julia/packages/Adapt/RGNRk/src/Adapt.jl:40 [inlined]
  [9] #4
    @ ~/.julia/packages/Adapt/RGNRk/src/base.jl:17 [inlined]
 [10] ntuple(f::Adapt.var"#4#6"{UnionAll, FastChain{Tuple{FastDense{typeof(tanh), DiffEqFlux.var"#initial_params#89"{Vector{Float32}}}}}}, n::Int64)
    @ Base ./ntuple.jl:19
 [11] adapt_structure(to::Type, f::FastChain{Tuple{FastDense{typeof(tanh), DiffEqFlux.var"#initial_params#89"{Vector{Float32}}}}})
    @ Adapt ~/.julia/packages/Adapt/RGNRk/src/base.jl:17
 [12] adapt(to::Type, x::Function)
    @ Adapt ~/.julia/packages/Adapt/RGNRk/src/Adapt.jl:40
 [13] #125
    @ ~/.julia/packages/Flux/0c9kI/src/functor.jl:67 [inlined]
 [14] fmap(f::Flux.var"#125#126", x::Function; exclude::typeof(Functors.isleaf), cache::IdDict{Any, Any})
    @ Functors ~/.julia/packages/Functors/EWaud/src/functor.jl:56
 [15] fmap
    @ ~/.julia/packages/Functors/EWaud/src/functor.jl:55 [inlined]
 [16] cpu
    @ ~/.julia/packages/Flux/0c9kI/src/functor.jl:67 [inlined]
 [17] |>(x::Function, f::typeof(cpu))
    @ Base ./operators.jl:858
 [18] top-level scope
    @ ~/Developer/lvcluster/_research/cpu_test.jl:10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions