# \#zygote

**URL:** https://discourse.julialang.org/tag/zygote/326.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Zygote gradients around closures and objects with custom properties](https://discourse.julialang.org/t/zygote-gradients-around-closures-and-objects-with-custom-properties/136704)

<div class="topic-metadata">

**Author:** [@goerz](https://discourse.julialang.org/u/goerz)\
**Replies:** 1\
**Last updated:** [April 13, 2026, 10:02pm UTC](https://discourse.julialang.org/t/zygote-gradients-around-closures-and-objects-with-custom-properties/136704 "2026-04-13T22:02:15Z")

</div>

I have the following function: function make\_automatic\_xi(g\_b) function automatic\_xi(Ψ, trajectory, tlist, n) grad = Zygote.gradient(psi -\> g\_b(psi, trajectory, tlist, n), Ψ)\[1\] if isnothing(grad) …

---

## [Finding mutations that Zygote complains about](https://discourse.julialang.org/t/finding-mutations-that-zygote-complains-about/135864)

<div class="topic-metadata">

**Author:** [@Neodym](https://discourse.julialang.org/u/Neodym)\
**Replies:** 19\
**Last updated:** [March 1, 2026, 6:47pm UTC](https://discourse.julialang.org/t/finding-mutations-that-zygote-complains-about/135864 "2026-03-01T18:47:53Z")

</div>

Hey, Apparently, I have some hidden mutations in my code that I cannot find. Unfortunately, Zygote easily finds them and complains about it. I get call stacks 40+ layers deep, the last of my own functions being near th…

---

## [Identical input in Zygote leads to different outputs](https://discourse.julialang.org/t/identical-input-in-zygote-leads-to-different-outputs/135120)

<div class="topic-metadata">

**Author:** [@Chrysoberyl](https://discourse.julialang.org/u/Chrysoberyl)\
**Replies:** 1\
**Last updated:** [January 19, 2026, 12:27am UTC](https://discourse.julialang.org/t/identical-input-in-zygote-leads-to-different-outputs/135120 "2026-01-19T00:27:54Z")

</div>

In this script, the forward pass has no error: using GNNGraphs, GraphNeuralNetworks, NNlib, Flux graph = GNNHeteroGraph( Dict( (:A, :a, :B) =\> (\[1, 2\], \[3, 4\]), (:B, :a, :A) =\> (\[1\], \[2\]), ); …

---

## [CUDA Warning about freeing DeviceMemory](https://discourse.julialang.org/t/cuda-warning-about-freeing-devicememory/135042)

<div class="topic-metadata">

**Author:** [@Chrysoberyl](https://discourse.julialang.org/u/Chrysoberyl)\
**Replies:** 1\
**Last updated:** [January 15, 2026, 7:37am UTC](https://discourse.julialang.org/t/cuda-warning-about-freeing-devicememory/135042 "2026-01-15T07:37:09Z")

</div>

I’m using Flux.jl for machine learning. When I run training, I got this error (seems to be generated from compiled code in Zygote) ERROR: LoadError: CUDA error: an illegal memory access was encountered (code 700, ERROR\_…

---

## [High memory usage when training a custom Lux model](https://discourse.julialang.org/t/high-memory-usage-when-training-a-custom-lux-model/134714)

<div class="topic-metadata">

**Author:** [@HMegh](https://discourse.julialang.org/u/HMegh)\
**Replies:** 8\
**Last updated:** [December 26, 2025, 1:22am UTC](https://discourse.julialang.org/t/high-memory-usage-when-training-a-custom-lux-model/134714 "2025-12-26T01:22:11Z")

</div>

I am trying to implement a custom Lux model, but I keep running out of memory even with small number (~500) of parameters. I have two kinds of layers (called sympnets) which take in and return two vectors. Each layer upd…

---

## [Using Neural ODEs to learn a family of ODEs (with Automatic Differentiation)](https://discourse.julialang.org/t/using-neural-odes-to-learn-a-family-of-odes-with-automatic-differentiation/134348)

<div class="topic-metadata">

**Author:** [@leespen1](https://discourse.julialang.org/u/leespen1)\
**Replies:** 13\
**Last updated:** [December 9, 2025, 1:59am UTC](https://discourse.julialang.org/t/using-neural-odes-to-learn-a-family-of-odes-with-automatic-differentiation/134348 "2025-12-09T01:59:34Z")

</div>

I am running into issues when trying to use reverse-mode automatic differentiation via Zygote when trying to solve families of Given u(t), we can train a neural ODE to find the underlying ODE du/dt = f(u, t). For examp…

---

## [Using \`CartesianIndex\` with Flux.jl](https://discourse.julialang.org/t/using-cartesianindex-with-flux-jl/134279)

<div class="topic-metadata">

**Author:** [@Chrysoberyl](https://discourse.julialang.org/u/Chrysoberyl)\
**Replies:** 3\
**Last updated:** [December 3, 2025, 3:49am UTC](https://discourse.julialang.org/t/using-cartesianindex-with-flux-jl/134279 "2025-12-03T03:49:15Z")

</div>

Is it possible to use CartesianIndex with Flux.jl within a Flux.with\_gradient block? Specifically I have a::Vector{Float32} and b::Vector{CartesianIndex}, and a\[b\] is in the gradient block. When I used this I got ERROR…

---

## [Integrals.jl & Zygote not working on 1.12](https://discourse.julialang.org/t/integrals-jl-zygote-not-working-on-1-12/133214)

<div class="topic-metadata">

**Author:** [@marcobonici](https://discourse.julialang.org/u/marcobonici)\
**Replies:** 1\
**Last updated:** [October 16, 2025, 11:43pm UTC](https://discourse.julialang.org/t/integrals-jl-zygote-not-working-on-1-12/133214 "2025-10-16T23:43:49Z")

</div>

Hello, I have been trying to differentiate an IntegralProblem, as defined using Integrals.jl, using Zygote.jl. While on 1.10 and 1.11 it works nicely, I have issues with 1.12. Here a MWE to reproduce the error ▶ Summa…

---

## [Automatic differentiation of loglikelihood function. Am I doing it right?](https://discourse.julialang.org/t/automatic-differentiation-of-loglikelihood-function-am-i-doing-it-right/132157)

<div class="topic-metadata">

**Author:** [@giovannitinervia9](https://discourse.julialang.org/u/giovannitinervia9)\
**Replies:** 5\
**Last updated:** [September 8, 2025, 3:56pm UTC](https://discourse.julialang.org/t/automatic-differentiation-of-loglikelihood-function-am-i-doing-it-right/132157 "2025-09-08T15:56:15Z")

</div>

Hi everyone! I’m a statistician and R user taking my first steps with Julia. I have extensive experience with R, and this summer I spent my free time reimplementing the R package gamlss as a personal exercise. Julia has…

---

## [Rrule for zygote](https://discourse.julialang.org/t/rrule-for-zygote/131069)

<div class="topic-metadata">

**Author:** [@mary](https://discourse.julialang.org/u/mary)\
**Replies:** 7\
**Last updated:** [July 29, 2025, 1:37am UTC](https://discourse.julialang.org/t/rrule-for-zygote/131069 "2025-07-29T01:37:23Z")

</div>

Hi, I am using rrule for gradient calculation in zygote. I defined a function which calculates the gradients and I just call that function inside the entire gradient calculation. Can zygote handle this type of rule? fun…

---

## [Reusing variables with Zygote?](https://discourse.julialang.org/t/reusing-variables-with-zygote/130498)

<div class="topic-metadata">

**Author:** [@MatPeron](https://discourse.julialang.org/u/MatPeron)\
**Replies:** 0\
**Last updated:** [July 5, 2025, 5:58pm UTC](https://discourse.julialang.org/t/reusing-variables-with-zygote/130498 "2025-07-05T17:58:37Z")

</div>

I’ve written a module to perform some physics computations, and have been trying to make it autodifferentiable so I can run it with stuff like Hamilonian Monte Carlo. The computation is specifically about perturbation th…

---

## [Issue with backprop in a custom recurrent \`Lux\` layer](https://discourse.julialang.org/t/issue-with-backprop-in-a-custom-recurrent-lux-layer/128968)

<div class="topic-metadata">

**Author:** [@pietro-butti](https://discourse.julialang.org/u/pietro-butti)\
**Replies:** 6\
**Last updated:** [June 16, 2025, 3:44pm UTC](https://discourse.julialang.org/t/issue-with-backprop-in-a-custom-recurrent-lux-layer/128968 "2025-06-16T15:44:58Z")

</div>

I am trying to implement an autoencoder in Lux, inspired by the excellent one that I found in githun.com/lkulowski/LSTM\_encoder\_decoder, coded with PyTorch. (diagram taken from the link) Model overview The encoder i…

---

## [.== and .\<= inside Zygote.gradient() are inaccurate on GPU](https://discourse.julialang.org/t/and-inside-zygote-gradient-are-inaccurate-on-gpu/128269)

<div class="topic-metadata">

**Author:** [@ivanightingale](https://discourse.julialang.org/u/ivanightingale)\
**Replies:** 10\
**Last updated:** [April 30, 2025, 3:07am UTC](https://discourse.julialang.org/t/and-inside-zygote-gradient-are-inaccurate-on-gpu/128269 "2025-04-30T03:07:05Z")

</div>

Hello, I’ve encountered some very bizzare behaviors with equality .== and inequality .\<= when using Flux.jl on GPU. Below is a small example: using CUDA using Flux device = gpu\_device() # device = cpu\_device() y = \[0,…

---

## [Implementing Three-Dimensional Interpolation, ODEProblem, and Gradient Computation with sensealg=GaussAdjoint(autojacvec=EnzymeVJP())](https://discourse.julialang.org/t/implementing-three-dimensional-interpolation-odeproblem-and-gradient-computation-with-sensealg-gaussadjoint-autojacvec-enzymevjp/128204)

<div class="topic-metadata">

**Author:** [@chooron](https://discourse.julialang.org/u/chooron)\
**Replies:** 2\
**Last updated:** [April 20, 2025, 3:23am UTC](https://discourse.julialang.org/t/implementing-three-dimensional-interpolation-odeproblem-and-gradient-computation-with-sensealg-gaussadjoint-autojacvec-enzymevjp/128204 "2025-04-20T03:23:11Z")

</div>

Hello, the problem I am currently facing is solving an ordinary differential equation (ODE) with interpolated data inputs. The problem can be visualized as a snow layer, where the snow layer represents the intermediate s…

---

## [How to differentiate functions involving arrays with one non-zero element in Zygote](https://discourse.julialang.org/t/how-to-differentiate-functions-involving-arrays-with-one-non-zero-element-in-zygote/127741)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 4\
**Last updated:** [April 13, 2025, 9:27am UTC](https://discourse.julialang.org/t/how-to-differentiate-functions-involving-arrays-with-one-non-zero-element-in-zygote/127741 "2025-04-13T09:27:15Z")

</div>

Hello, I need to differentiate using Zygote.jl a function like using LinearAlgebra function my\_fidelity2(p) ψg = zeros(ComplexF64, 2) ψg\[2\] = 1.0 ψe = zeros(ComplexF64, 2) ψe\[1\] = 1.0 ψgg = kron(ψg, ψg) ψ…

---

## [Automatic Differentiation of quantum master equation using Zygote](https://discourse.julialang.org/t/automatic-differentiation-of-quantum-master-equation-using-zygote/127715)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 14\
**Last updated:** [April 5, 2025, 7:14pm UTC](https://discourse.julialang.org/t/automatic-differentiation-of-quantum-master-equation-using-zygote/127715 "2025-04-05T19:14:43Z")

</div>

Hello, I need to differentiate a quantum master equation over a parameter, using QuantumToolbox.jl. Under the hood it is simply an Ordinary Differential Equation involving SciMLOperators. I’m able to differentiate the …

---

## [AD through DataInterpolations, ODE : Gradient calculation, parameter -\> time series -\> DataInterpolation](https://discourse.julialang.org/t/ad-through-datainterpolations-ode-gradient-calculation-parameter-time-series-datainterpolation/126758)

<div class="topic-metadata">

**Author:** [@Rohan\_Rajagopal](https://discourse.julialang.org/u/Rohan_Rajagopal)\
**Replies:** 2\
**Last updated:** [March 12, 2025, 5:46am UTC](https://discourse.julialang.org/t/ad-through-datainterpolations-ode-gradient-calculation-parameter-time-series-datainterpolation/126758 "2025-03-12T05:46:38Z")

</div>

Greetings! The question is regarding AD through DataInterpolations, ODE. The function is described as follows, using DataInterpolations, OrdinaryDiffEq, SciMLSensitivity, Zygote time = 0.:0.1:20 function temp(ps) …

---

## [Type instability for simple MLP call using ComponentArrays](https://discourse.julialang.org/t/type-instability-for-simple-mlp-call-using-componentarrays/126191)

<div class="topic-metadata">

**Author:** [@lasse](https://discourse.julialang.org/u/lasse)\
**Replies:** 2\
**Last updated:** [March 6, 2025, 5:17pm UTC](https://discourse.julialang.org/t/type-instability-for-simple-mlp-call-using-componentarrays/126191 "2025-03-06T17:17:58Z")

</div>

Hi, Is there a way to make Zygote gradients type stable when optimizing over a ComponentArray of parameters? If not - what is a good alternative that is compatible with the SciML ecosystem? Using @NamedTuple does as I …

---

## [Help with workaround a mutation in an optimization problem](https://discourse.julialang.org/t/help-with-workaround-a-mutation-in-an-optimization-problem/126624)

<div class="topic-metadata">

**Author:** [@abhinav](https://discourse.julialang.org/u/abhinav)\
**Replies:** 1\
**Last updated:** [March 6, 2025, 10:36am UTC](https://discourse.julialang.org/t/help-with-workaround-a-mutation-in-an-optimization-problem/126624 "2025-03-06T10:36:58Z")

</div>

Hi everyone, I’m running into an issue with an optimization problem utilizing gradient-based updates using Zygote where an in-place mutation appears to be causing problems. Specifically, when I update my parameter vecto…

---

## [\`Zygote.gradient\` is 54000 TIMES slower than \`jax.gradient\`](https://discourse.julialang.org/t/zygote-gradient-is-54000-times-slower-than-jax-gradient/125396)

<div class="topic-metadata">

**Author:** [@ForceBru](https://discourse.julialang.org/u/ForceBru)\
**Replies:** 80\
**Last updated:** [February 1, 2025, 9:25pm UTC](https://discourse.julialang.org/t/zygote-gradient-is-54000-times-slower-than-jax-gradient/125396 "2025-02-01T21:25:46Z")

</div>

I’m almost unable to compute ant gradients (EDIT 9 hrs later: meant to say “any gradients”, but got gradients for ants) in Zygote. I initially attempted to optimize my model using around a million parameters, but it got …

---

## [Automatic differentiation minisymposium at JuliaCon](https://discourse.julialang.org/t/automatic-differentiation-minisymposium-at-juliacon/125145)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 0\
**Last updated:** [January 23, 2025, 8:08pm UTC](https://discourse.julialang.org/t/automatic-differentiation-minisymposium-at-juliacon/125145 "2025-01-23T20:08:44Z")

</div>

Some love Julia for its speed. Some love it for its scientific computing packages. Some love it because the people are nice. But we love it for one reason and one reason only: because it makes our gradients go brrrrr …

---

## [Help using CUDA, Zygote, and random numbers](https://discourse.julialang.org/t/help-using-cuda-zygote-and-random-numbers/123458)

<div class="topic-metadata">

**Author:** [@bgctw](https://discourse.julialang.org/u/bgctw)\
**Replies:** 4\
**Last updated:** [December 23, 2024, 8:59am UTC](https://discourse.julialang.org/t/help-using-cuda-zygote-and-random-numbers/123458 "2024-12-23T08:59:15Z")

</div>

I get the error “llvmcall requires the compiler” when trying to take the gradient of a function that involves generating random numbers in CUDA. Here is a minimal example: using GPUArraysCore: GPUArraysCore using CUDA, …

---

## [Custom stuct and Jacobian: Issue with Zygote not understanding custom struct](https://discourse.julialang.org/t/custom-stuct-and-jacobian-issue-with-zygote-not-understanding-custom-struct/123781)

<div class="topic-metadata">

**Author:** [@KapilKhanal](https://discourse.julialang.org/u/KapilKhanal)\
**Replies:** 0\
**Last updated:** [December 12, 2024, 6:35pm UTC](https://discourse.julialang.org/t/custom-stuct-and-jacobian-issue-with-zygote-not-understanding-custom-struct/123781 "2024-12-12T18:35:38Z")

</div>

The function with ‘normals’ input is fine but when it’s inside the struct, Zygote returns (nothing) # MWE struct MeshExample normals::AbstractMatrix other::Float64 end function radiation\_using\_struct(mesh::Mesh…

---

## [Cannot differentiate through a multivariate log normal probability density with Zygote](https://discourse.julialang.org/t/cannot-differentiate-through-a-multivariate-log-normal-probability-density-with-zygote/123571)

<div class="topic-metadata">

**Author:** [@DoktorMike](https://discourse.julialang.org/u/DoktorMike)\
**Replies:** 4\
**Last updated:** [December 11, 2024, 3:10pm UTC](https://discourse.julialang.org/t/cannot-differentiate-through-a-multivariate-log-normal-probability-density-with-zygote/123571 "2024-12-11T15:10:38Z")

</div>

I’ve built a loss function based on the negative log likelihood of a multivariate log normal distribution. However, when I try to calculate the gradients I hit the following error which I would think stems from the handl…

---

## [AD Troubles in Flux and Unusual Loss](https://discourse.julialang.org/t/ad-troubles-in-flux-and-unusual-loss/122995)

<div class="topic-metadata">

**Author:** [@gideonsimpson](https://discourse.julialang.org/u/gideonsimpson)\
**Replies:** 1\
**Last updated:** [November 24, 2024, 12:09am UTC](https://discourse.julialang.org/t/ad-troubles-in-flux-and-unusual-loss/122995 "2024-11-24T00:09:08Z")

</div>

I’m struggling with the following issue. I want to train on a somewhat nonstandard loss function involving the gradient of the target. If everything worked, I would. use the following code: using Flux using Random usi…

---

## [Autodiff with Zygote: issues with setting seeds](https://discourse.julialang.org/t/autodiff-with-zygote-issues-with-setting-seeds/121957)

<div class="topic-metadata">

**Author:** [@weltenbummler](https://discourse.julialang.org/u/weltenbummler)\
**Replies:** 9\
**Last updated:** [November 11, 2024, 9:08am UTC](https://discourse.julialang.org/t/autodiff-with-zygote-issues-with-setting-seeds/121957 "2024-11-11T09:08:34Z")

</div>

Hello all, I would like to differentiate a function with fixed seed but obtain a “can’t differentiate foreign call” error when using Zygote. Any advise would be appreciated. The following is a minimal working example …

---

## [Impossible to perform autodiff on simple ODE](https://discourse.julialang.org/t/impossible-to-perform-autodiff-on-simple-ode/120861)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 22\
**Last updated:** [November 1, 2024, 10:47am UTC](https://discourse.julialang.org/t/impossible-to-perform-autodiff-on-simple-ode/120861 "2024-11-01T10:47:16Z")

</div>

Hello, I was trying to differentiate a simple ODE using Zygote.jl, but it returns the following error: ERROR: \`p\` is not a SciMLStructure. This is required for adjoint sensitivity analysis. For more information, see th…

---

## [Odd warning and issues with optimization only when inside Optimization.jl. Zygote.hessian works fine](https://discourse.julialang.org/t/odd-warning-and-issues-with-optimization-only-when-inside-optimization-jl-zygote-hessian-works-fine/121967)

<div class="topic-metadata">

**Author:** [@Hareruya](https://discourse.julialang.org/u/Hareruya)\
**Replies:** 8\
**Last updated:** [October 30, 2024, 7:39pm UTC](https://discourse.julialang.org/t/odd-warning-and-issues-with-optimization-only-when-inside-optimization-jl-zygote-hessian-works-fine/121967 "2024-10-30T19:39:55Z")

</div>

Greetings, everyone. Apologies if the query is too basic, as it does not impede optimization in one case. I have graduated from my PhD program and have gotten a job at a company that offers me freedom in what programmin…

---

## [Using NonlinearSolve with autodiff](https://discourse.julialang.org/t/using-nonlinearsolve-with-autodiff/121333)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 9\
**Last updated:** [October 17, 2024, 9:18pm UTC](https://discourse.julialang.org/t/using-nonlinearsolve-with-autodiff/121333 "2024-10-17T21:18:38Z")

</div>

Hello, I was trying to test NonlinearSolve.jl with automatic differentiation like Enzyme.jl or Zygote.jl. But the following simple code fails f(x, p) = p.a \* x^2 - p.b prob = NonlinearProblem(f, 0.0, (a=1.0, b=2.0)) so…

---

## [Jacobian&vectors in Zygote](https://discourse.julialang.org/t/jacobian-vectors-in-zygote/121381)

<div class="topic-metadata">

**Author:** [@blob](https://discourse.julialang.org/u/blob)\
**Replies:** 3\
**Last updated:** [October 16, 2024, 1:44pm UTC](https://discourse.julialang.org/t/jacobian-vectors-in-zygote/121381 "2024-10-16T13:44:33Z")

</div>

I have a function with three inputs and two outputs. The first argument is a vector, the two others are scalars. The function is built from smaller functions. I want to get derivatives of the composite function with resp…

[Next page](https://discourse.julialang.org/tag/zygote/326.md?match_all_tags=true&page=1&tags%5B%5D=zygote)
