I’m trying to implement weight regularisation which requires adding a weight-dependent penalty to the loss function. When I proceed naively, I run into “Mutating arrays is not supported” but I don’t understand what arrays I am mutating. Here’s a MWE:
c = rand(3) julia> gs = gradient(params(c)) do sum(sum.(params(c))) end ERROR: Mutating arrays is not supported
If I delete the second
params the error disappears, but in my problem I don’t have explicit access to the params any other way.
Where is the mutation?
What is the workaround?