Skip to content

Zygote cannot repeat? #59

@nmheim

Description

@nmheim
using Flux

struct Model
    W
end

Flux.@functor Model

m = Model(rand(3))
ps = params(m)

loss() = sum(repeat(m.W, 1, 4))
# loss() = sum(m.W)
gs = Flux.gradient(loss, ps)

the example above works with the loss that is commented out.
with the one that contains a repeat I get:

ERROR: LoadError: Mutating arrays is not supported
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] (::Zygote.var"#982#983")(::Nothing) at /home/niklas/.julia/packages/Zygote/8dVxG/src/lib/array.jl:38
 [3] (::Zygote.var"#2597#back#984"{Zygote.var"#982#983"})(::Nothing) at /home/niklas/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:49
 [4] repeat at ./abstractarraymath.jl:283 [inlined]
 [5] (::typeof((repeat)))(::FillArrays.Fill{Float64,2,Tuple{Base.OneTo{Int64},Base.OneTo{Int64}}}) at /home/niklas/.julia/packages/Zygote/8dVxG/src/compiler/interface2.jl:0
 [6] loss at /home/niklas/repos/GenerativeModels.jl/minimal.jl:12 [inlined]
 [7] (::typeof((loss)))(::Float64) at /home/niklas/.julia/packages/Zygote/8dVxG/src/compiler/interface2.jl:0
 [8] (::Zygote.var"#38#39"{Zygote.Params,Zygote.Context,typeof((loss))})(::Float64) at /home/niklas/.julia/packages/Zygote/8dVxG/src/compiler/interface.jl:101
 [9] gradient(::Function, ::Zygote.Params) at /home/niklas/.julia/packages/Zygote/8dVxG/src/compiler/interface.jl:47
 [10] top-level scope at /home/niklas/repos/GenerativeModels.jl/minimal.jl:13
 [11] include at ./boot.jl:328 [inlined]
 [12] include_relative(::Module, ::String) at ./loading.jl:1105
 [13] include(::Module, ::String) at ./Base.jl:31
 [14] include(::String) at ./client.jl:424
 [15] top-level scope at REPL[5]:1

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