Skip to content

vae_mnist: Mutating arrays is not supported #301

Open
@jstrube

Description

@jstrube

When running vae_mnist with Flux v0.12.3 causes:

 ERROR: LoadError: Mutating arrays is not supported
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:33
  [2] (::Zygote.var"#411#412")(#unused#::Nothing)
    @ Zygote ~/.julia/packages/Zygote/6HN9x/src/lib/array.jl:65
  [3] (::Zygote.var"#2279#back#413"{Zygote.var"#411#412"})(Δ::Nothing)
    @ Zygote ~/.julia/packages/ZygoteRules/OjfTt/src/adjoint.jl:59
  [4] Pullback
    @ ~/.julia/packages/Flux/6o4DQ/src/functor.jl:45 [inlined]
  [5] (::typeof(∂(params!)))(Δ::Nothing)
    @ Zygote ~/.julia/packages/Zygote/6HN9x/src/compiler/interface2.jl:0
  [6] Pullback
    @ ~/.julia/packages/Flux/6o4DQ/src/functor.jl:47 [inlined]
  [7] (::typeof(∂(params!)))(Δ::Nothing)
    @ Zygote ~/.julia/packages/Zygote/6HN9x/src/compiler/interface2.jl:0
  [8] Pullback
    @ ~/.julia/packages/Flux/6o4DQ/src/functor.jl:47 [inlined]
  [9] (::typeof(∂(params!)))(Δ::Nothing)
    @ Zygote ~/.julia/packages/Zygote/6HN9x/src/compiler/interface2.jl:0
 [10] Pullback
    @ ~/.julia/packages/Flux/6o4DQ/src/functor.jl:47 [inlined]
 [11] (::typeof(∂(params!)))(Δ::Nothing)
    @ Zygote ~/.julia/packages/Zygote/6HN9x/src/compiler/interface2.jl:0
 [12] Pullback
    @ ~/.julia/packages/Flux/6o4DQ/src/functor.jl:44 [inlined]
 [13] (::typeof(∂(params!)))(Δ::Nothing)
    @ Zygote ~/.julia/packages/Zygote/6HN9x/src/compiler/interface2.jl:0
 [14] Pullback
    @ ~/.julia/packages/Flux/6o4DQ/src/functor.jl:53 [inlined]
 [15] (::typeof(∂(params)))(Δ::Nothing)
    @ Zygote ~/.julia/packages/Zygote/6HN9x/src/compiler/interface2.jl:0
 [16] Pullback
    @ /media/jstrube/24988e98-7094-4b00-aeb9-5c98c5b52a901/Data/model-zoo/vision/vae_mnist/vae_mnist.jl:66 [inlined]
 [17] (::typeof(∂(model_loss)))(Δ::Float32)
    @ Zygote ~/.julia/packages/Zygote/6HN9x/src/compiler/interface2.jl:0
 [18] Pullback
    @ /media/jstrube/24988e98-7094-4b00-aeb9-5c98c5b52a901/Data/model-zoo/vision/vae_mnist/vae_mnist.jl:142 [inlined]
 [19] (::typeof(∂(λ)))(Δ::Float32)
    @ Zygote ~/.julia/packages/Zygote/6HN9x/src/compiler/interface2.jl:0
 [20] (::Zygote.var"#69#70"{Zygote.Params, typeof(∂(λ)), Zygote.Context})(Δ::Float32)
    @ Zygote ~/.julia/packages/Zygote/6HN9x/src/compiler/interface.jl:252
 [21] train(; kws::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Main /media/jstrube/24988e98-7094-4b00-aeb9-5c98c5b52a901/Data/model-zoo/vision/vae_mnist/vae_mnist.jl:144
 [22] train()
    @ Main /media/jstrube/24988e98-7094-4b00-aeb9-5c98c5b52a901/Data/model-zoo/vision/vae_mnist/vae_mnist.jl:94
 [23] top-level scope
    @ /media/jstrube/24988e98-7094-4b00-aeb9-5c98c5b52a901/Data/model-zoo/vision/vae_mnist/vae_mnist.jl:176
in expression starting at /media/jstrube/24988e98-7094-4b00-aeb9-5c98c5b52a901/Data/model-zoo/vision/vae_mnist/vae_mnist.jl:175

According to discourse, this can be fixed by adding Flux.Zygote.@nograd Flux.params before the function definition of model_loss. This indeed fixes it for me.

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