# \#autodiff

**URL:** https://discourse.julialang.org/tag/autodiff/676.md

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

---

## [Where do these NaNs in my KernelAbstraction derivative come from?](https://discourse.julialang.org/t/where-do-these-nans-in-my-kernelabstraction-derivative-come-from/139105)

<div class="topic-metadata">

**Author:** [@rkube](https://discourse.julialang.org/u/rkube)\
**Replies:** 0\
**Last updated:** [August 30, 2026, 5:35pm UTC](https://discourse.julialang.org/t/where-do-these-nans-in-my-kernelabstraction-derivative-come-from/139105 "2026-08-30T17:35:37Z")

</div>

Hi, I (mostly chatgpt though) am working on an MHD code using KernelAbstractions.jl, Reactant.jl and Enzyme.jl. In one step, a kernel derivative produces NaNs whereas the reactant gradient using plain arrays gives corre…

---

## [Mooncake.jl with variable sized input](https://discourse.julialang.org/t/mooncake-jl-with-variable-sized-input/137943)

<div class="topic-metadata">

**Author:** [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Replies:** 5\
**Last updated:** [July 6, 2026, 1:58pm UTC](https://discourse.julialang.org/t/mooncake-jl-with-variable-sized-input/137943 "2026-07-06T13:58:40Z")

</div>

This post is intended as a log for people interested in Mooncake. Similarly, I am interested in feedback. Background: I am interested in learning from structured data, under which you can think about JSON documents. I a…

---

## [How to use ForwardDiff.jl with inv and matrix exponential?](https://discourse.julialang.org/t/how-to-use-forwarddiff-jl-with-inv-and-matrix-exponential/137880)

<div class="topic-metadata">

**Author:** [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Replies:** 15\
**Last updated:** [July 4, 2026, 8:31pm UTC](https://discourse.julialang.org/t/how-to-use-forwarddiff-jl-with-inv-and-matrix-exponential/137880 "2026-07-04T20:31:45Z")

</div>

I have a question listed here: Why does ForwardDiff.jl give me all-zero Jacobian matrix?, and I found it might be due to part of the function which contains inv and exp (matrix exponential…) from ExponentialUtilities. I …

---

## [How does ForwardDiff.jl and FiniteDiff.jl handle edge-hitting cases?](https://discourse.julialang.org/t/how-does-forwarddiff-jl-and-finitediff-jl-handle-edge-hitting-cases/137828)

<div class="topic-metadata">

**Author:** [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Replies:** 3\
**Last updated:** [June 27, 2026, 11:18pm UTC](https://discourse.julialang.org/t/how-does-forwarddiff-jl-and-finitediff-jl-handle-edge-hitting-cases/137828 "2026-06-27T23:18:02Z")

</div>

Hi guys, I am using ForwardDiff.jl to calculate the parameter uncertainty in my model (see below about the more detailed information…). I am wondering, how does ForwardDiff.jl and FiniteDiff.jl handle the edge-hitting p…

---

## [Auto-differentiation of Numba LLVM IR using Enzyme.jl: linear algebra and opaque external functions](https://discourse.julialang.org/t/auto-differentiation-of-numba-llvm-ir-using-enzyme-jl-linear-algebra-and-opaque-external-functions/137799)

<div class="topic-metadata">

**Author:** [@ymardoukhi](https://discourse.julialang.org/u/ymardoukhi)\
**Replies:** 0\
**Last updated:** [June 25, 2026, 12:43pm UTC](https://discourse.julialang.org/t/auto-differentiation-of-numba-llvm-ir-using-enzyme-jl-linear-algebra-and-opaque-external-functions/137799 "2026-06-25T12:43:56Z")

</div>

This is related to the thread Get Numba LLVM IR differentiated in Julia using Enzyme.jl: differentiating Python functions decorated as Numba CFunc functions. I am sorry that this thread is quite long, but I tried to be a…

---

## [Why does ForwardDiff.jl give me all-zero Jacobian matrix?](https://discourse.julialang.org/t/why-does-forwarddiff-jl-give-me-all-zero-jacobian-matrix/137714)

<div class="topic-metadata">

**Author:** [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Replies:** 5\
**Last updated:** [June 22, 2026, 7:45am UTC](https://discourse.julialang.org/t/why-does-forwarddiff-jl-give-me-all-zero-jacobian-matrix/137714 "2026-06-22T07:45:14Z")

</div>

Hi guys, I am using one Julia-based model from https://github.com/LandEcosystems/Sindbad.jl, and tries to use ForwardDiff.jl to calculate the Jacobian of the cost function to the optimized parameters. I run the pipeline…

---

## [ForwardDiff Lie brackets allocate with StaticArrays](https://discourse.julialang.org/t/forwarddiff-lie-brackets-allocate-with-staticarrays/137248)

<div class="topic-metadata">

**Author:** [@tremelow](https://discourse.julialang.org/u/tremelow)\
**Replies:** 0\
**Last updated:** [May 22, 2026, 9:34pm UTC](https://discourse.julialang.org/t/forwarddiff-lie-brackets-allocate-with-staticarrays/137248 "2026-05-22T21:34:52Z")

</div>

I’m working on a code where I need Lie brackets of Lie brackets, but computing the Jacobian of a Lie bracket allocates data. Here’s a MWE using StaticArrays using BenchmarkTools import ForwardDiff f(x::SVector{2,T}) wh…

---

## [Cannot use AD as shown in ControlSystems.jl example](https://discourse.julialang.org/t/cannot-use-ad-as-shown-in-controlsystems-jl-example/136292)

<div class="topic-metadata">

**Author:** [@vtfanta](https://discourse.julialang.org/u/vtfanta)\
**Replies:** 2\
**Last updated:** [March 19, 2026, 7:18pm UTC](https://discourse.julialang.org/t/cannot-use-ad-as-shown-in-controlsystems-jl-example/136292 "2026-03-19T19:18:51Z")

</div>

I’m trying to replicate the example of using AD with ControlSystems.jl from the JuliaCon 2022 presentation (this moment), but the ForwardDiff gradient calculation errors, since there is the matrix exponential LinearAlgeb…

---

## [Good practices regarding automatic differentiation in a Gaussian process implementation](https://discourse.julialang.org/t/good-practices-regarding-automatic-differentiation-in-a-gaussian-process-implementation/135990)

<div class="topic-metadata">

**Author:** [@Nikos\_Gianniotis](https://discourse.julialang.org/u/Nikos_Gianniotis)\
**Replies:** 14\
**Last updated:** [March 5, 2026, 8:48am UTC](https://discourse.julialang.org/t/good-practices-regarding-automatic-differentiation-in-a-gaussian-process-implementation/135990 "2026-03-05T08:48:10Z")

</div>

(Related to Large memory consumption when using Mooncake via DifferentiationInterface for Gaussian process optimisation) I’m starting this thread to discuss good practices for using Mooncake.jl via DifferentiationInterf…

---

## [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…

---

## [Reactant: how to use it, limititations and opportunities?](https://discourse.julialang.org/t/reactant-how-to-use-it-limititations-and-opportunities/135559)

<div class="topic-metadata">

**Author:** [@marcobonici](https://discourse.julialang.org/u/marcobonici)\
**Replies:** 1\
**Last updated:** [February 11, 2026, 12:49am UTC](https://discourse.julialang.org/t/reactant-how-to-use-it-limititations-and-opportunities/135559 "2026-02-11T00:49:04Z")

</div>

After reading a few posts (and some suggestion from @wmshen0323 to try Enzyme), Reactant got my attention. My understanding is that, if I manage to compile my code with Reactant, I get for free to run my code on GPUs and…

---

## [Best way to forcibly passify a result using ForwardDiff?](https://discourse.julialang.org/t/best-way-to-forcibly-passify-a-result-using-forwarddiff/135283)

<div class="topic-metadata">

**Author:** [@afleming](https://discourse.julialang.org/u/afleming)\
**Replies:** 3\
**Last updated:** [January 28, 2026, 10:30am UTC](https://discourse.julialang.org/t/best-way-to-forcibly-passify-a-result-using-forwarddiff/135283 "2026-01-28T10:30:33Z")

</div>

I’m working on the implementation of a time-stepping method and would like to force that part of the computation always be a passive value (in the AD sense). The function in question is a simple broadcasted computation,…

---

## [Are there alternatives to Diagonal and eigvals compatible with Reactant?](https://discourse.julialang.org/t/are-there-alternatives-to-diagonal-and-eigvals-compatible-with-reactant/135081)

<div class="topic-metadata">

**Author:** [@marcsgil](https://discourse.julialang.org/u/marcsgil)\
**Replies:** 13\
**Last updated:** [January 26, 2026, 3:22am UTC](https://discourse.julialang.org/t/are-there-alternatives-to-diagonal-and-eigvals-compatible-with-reactant/135081 "2026-01-26T03:22:02Z")

</div>

Hello! I’m in the process of refactoring a complicated function so that it can be compiled by Reactant. It has not been very straightforward, but the speedup I’ve seen so far certainly justifies the effort. Nonetheless…

---

## [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…

---

## [ChainRules error when using Mooncake in Optimization.jl](https://discourse.julialang.org/t/chainrules-error-when-using-mooncake-in-optimization-jl/134240)

<div class="topic-metadata">

**Author:** [@slwu89](https://discourse.julialang.org/u/slwu89)\
**Replies:** 0\
**Last updated:** [November 30, 2025, 7:10pm UTC](https://discourse.julialang.org/t/chainrules-error-when-using-mooncake-in-optimization-jl/134240 "2025-11-30T19:10:28Z")

</div>

Hi all, I am testing out using the SciML ecosystem to fit constrained splines inside of an ODE (some terms on the RHS of the ODE are given by evaluating a spline where the point of evaluation on the domain of the spline …

---

## [Type Stabled Jacobian of a Hessian](https://discourse.julialang.org/t/type-stabled-jacobian-of-a-hessian/134148)

<div class="topic-metadata">

**Author:** [@JPCAM](https://discourse.julialang.org/u/JPCAM)\
**Replies:** 3\
**Last updated:** [November 28, 2025, 11:41am UTC](https://discourse.julialang.org/t/type-stabled-jacobian-of-a-hessian/134148 "2025-11-28T11:41:28Z")

</div>

I’ve run into a type-stability issue when trying to compute third-order derivatives with ForwardDiff. I have a potential function that takes a vector as input. Computing the Hessian with ForwardDiff.hessian works well a…

---

## [Mooncake, Turing, and CI](https://discourse.julialang.org/t/mooncake-turing-and-ci/134067)

<div class="topic-metadata">

**Author:** [@marcobonici](https://discourse.julialang.org/u/marcobonici)\
**Replies:** 3\
**Last updated:** [November 24, 2025, 11:20am UTC](https://discourse.julialang.org/t/mooncake-turing-and-ci/134067 "2025-11-24T11:20:45Z")

</div>

Hello, I finally am switching to DifferentiationInterface for the tests of a package of mine and I don’t think I could be happier! It lets me quickly write tests in a coherent manner, to try different backends. Amazing…

---

## [Efficient way to implement multi-index nonlinear constraints in ExaModels? (PCE-expanded AC power flow)](https://discourse.julialang.org/t/efficient-way-to-implement-multi-index-nonlinear-constraints-in-examodels-pce-expanded-ac-power-flow/133934)

<div class="topic-metadata">

**Author:** [@yanlingogo](https://discourse.julialang.org/u/yanlingogo)\
**Replies:** 4\
**Last updated:** [November 24, 2025, 4:24am UTC](https://discourse.julialang.org/t/efficient-way-to-implement-multi-index-nonlinear-constraints-in-examodels-pce-expanded-ac-power-flow/133934 "2025-11-24T04:24:44Z")

</div>

Hi all, I’m implementing a PCE-expanded AC power flow model. In JuMP, one of my nonlinear constraints looks like: @constraint(opf, pfP\[i=1:n\_bus, k=1:K\], p\[i,k\] \* T2\_diag\[k\] == sum( (G\[i,j\]\*(E\[i…

---

## [CasADiNLPModels.jl: an interface for CasADi via loading code generated functions](https://discourse.julialang.org/t/casadinlpmodels-jl-an-interface-for-casadi-via-loading-code-generated-functions/133925)

<div class="topic-metadata">

**Author:** [@apozharski](https://discourse.julialang.org/u/apozharski)\
**Replies:** 1\
**Last updated:** [November 19, 2025, 11:35am UTC](https://discourse.julialang.org/t/casadinlpmodels-jl-an-interface-for-casadi-via-loading-code-generated-functions/133925 "2025-11-19T11:35:02Z")

</div>

We (@frapac, @apozharski, and Armin Nurkanović) have released a small new package for easily interfacing NLPs modeled in CasADi with the NLPModels.jl ecosystem. The package implements loading of CasÄDi code generated fun…

---

## [Computing Hessian of the Langrangian efficiently with DI.jl](https://discourse.julialang.org/t/computing-hessian-of-the-langrangian-efficiently-with-di-jl/133462)

<div class="topic-metadata">

**Author:** [@franckgaga](https://discourse.julialang.org/u/franckgaga)\
**Replies:** 15\
**Last updated:** [November 4, 2025, 5:16pm UTC](https://discourse.julialang.org/t/computing-hessian-of-the-langrangian-efficiently-with-di-jl/133462 "2025-11-04T17:16:42Z")

</div>

Hello, The new MOI.VectorNonlinearOracle support providing the Hessian of the Langrangian function, defined as, according to MOI.jl doc: \\sum\_i \\mu\_i \\nabla^2 f\_i(\\mathbf{x}) but the Langrangian typically also includ…

---

## [AD of UDEs - how to set it up?](https://discourse.julialang.org/t/ad-of-udes-how-to-set-it-up/133461)

<div class="topic-metadata">

**Author:** [@Emil\_Martinsen](https://discourse.julialang.org/u/Emil_Martinsen)\
**Replies:** 13\
**Last updated:** [October 31, 2025, 7:13am UTC](https://discourse.julialang.org/t/ad-of-udes-how-to-set-it-up/133461 "2025-10-31T07:13:44Z")

</div>

Hi! Im new to Julia and SciML but I am really curious to see how combining ODE’s with neural network could improve the predictive performance of the model we are developing for solvent-based CO2 capture. My current setu…

---

## [New "easy rule" system for Enzyme](https://discourse.julialang.org/t/new-easy-rule-system-for-enzyme/133522)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 4\
**Last updated:** [October 29, 2025, 9:27pm UTC](https://discourse.julialang.org/t/new-easy-rule-system-for-enzyme/133522 "2025-10-29T21:27:57Z")

</div>

Hi there @wsmoses and friends, Thanks for the new easy rule system! Making rules more accessible is a great idea to get more people into autodiff (that’s how I got hooked in the first place). I’m curious to understand …

---

## [Preserving ComponentArray structure with DifferentiationInterface](https://discourse.julialang.org/t/preserving-componentarray-structure-with-differentiationinterface/133390)

<div class="topic-metadata">

**Author:** [@charlesknipp](https://discourse.julialang.org/u/charlesknipp)\
**Replies:** 2\
**Last updated:** [October 23, 2025, 6:23pm UTC](https://discourse.julialang.org/t/preserving-componentarray-structure-with-differentiationinterface/133390 "2025-10-23T18:23:52Z")

</div>

I’m building a DSGE modeling language (lol what else is new) where I want to use something like ComponentArrays.jl for the construction of first order perturbations using DifferentiationInterface.jl. The point here is th…

---

## [Make mutating function more AD-friendly](https://discourse.julialang.org/t/make-mutating-function-more-ad-friendly/133356)

<div class="topic-metadata">

**Author:** [@MrMR](https://discourse.julialang.org/u/MrMR)\
**Replies:** 10\
**Last updated:** [October 23, 2025, 9:52am UTC](https://discourse.julialang.org/t/make-mutating-function-more-ad-friendly/133356 "2025-10-23T09:52:03Z")

</div>

Dear all, since this is my first post, I want to thank you for the help I got in many years I used Julia (I always found the answer to my problems in previous posts!). Diving into the problem: what I need to do is to …

---

## [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…

---

## [Speeding up per-sample gradients?](https://discourse.julialang.org/t/speeding-up-per-sample-gradients/109322)

<div class="topic-metadata">

**Author:** [@AlexLewandowski](https://discourse.julialang.org/u/AlexLewandowski)\
**Replies:** 25\
**Last updated:** [October 7, 2025, 5:14pm UTC](https://discourse.julialang.org/t/speeding-up-per-sample-gradients/109322 "2025-10-07T17:14:36Z")

</div>

I am trying to speed up the calculation of per-sample (or per-example) gradients. This can be done via a loop or a jacobian in Julia, but this is slow. The calculation of individual gradients can be batched in several py…

---

## [KernelAbstractions + Enzyme - how to do GPU-side autodiff?](https://discourse.julialang.org/t/kernelabstractions-enzyme-how-to-do-gpu-side-autodiff/132643)

<div class="topic-metadata">

**Author:** [@jl\_enthusiast](https://discourse.julialang.org/u/jl_enthusiast)\
**Replies:** 1\
**Last updated:** [September 25, 2025, 6:34am UTC](https://discourse.julialang.org/t/kernelabstractions-enzyme-how-to-do-gpu-side-autodiff/132643 "2025-09-25T06:34:49Z")

</div>

Hello, I recently tried to (and failed) to auto-differentiate kernels with Enzyme.jl, written using KernelAbstractions.jl. I tried to search for examples in other packages, but could not find any concrete examples of E…

---

## [What is the correct way to autodiff a simple CUDA kernel using Reactant.jl and Enzyme.jl](https://discourse.julialang.org/t/what-is-the-correct-way-to-autodiff-a-simple-cuda-kernel-using-reactant-jl-and-enzyme-jl/132572)

<div class="topic-metadata">

**Author:** [@TiangeHuang-Cedric](https://discourse.julialang.org/u/TiangeHuang-Cedric)\
**Replies:** 20\
**Last updated:** [September 23, 2025, 7:58pm UTC](https://discourse.julialang.org/t/what-is-the-correct-way-to-autodiff-a-simple-cuda-kernel-using-reactant-jl-and-enzyme-jl/132572 "2025-09-23T19:58:25Z")

</div>

I’m new to Reactant.jl and Enzyme.jl, and I want to use them to calculate the grad of a CUDA kernel. Here is my script: using Random, Reactant, CUDA, Test, Enzyme const ReactantCUDAExt = Base.get\_extension(Reactant, :R…

---

## [Plugging DifferentiationInterface.jl into pytorch](https://discourse.julialang.org/t/plugging-differentiationinterface-jl-into-pytorch/132598)

<div class="topic-metadata">

**Author:** [@mattsignorelli](https://discourse.julialang.org/u/mattsignorelli)\
**Replies:** 5\
**Last updated:** [September 23, 2025, 7:32pm UTC](https://discourse.julialang.org/t/plugging-differentiationinterface-jl-into-pytorch/132598 "2025-09-23T19:32:28Z")

</div>

I preface this with saying that I really am not very experienced with both pytorch and juliatorch, and apologize for any misunderstandings that I have. We are developing a physics simulation ecosystem that can be differ…

---

## [How to debug ODE model aborting midway on sensitivity computation](https://discourse.julialang.org/t/how-to-debug-ode-model-aborting-midway-on-sensitivity-computation/132096)

<div class="topic-metadata">

**Author:** [@Neodym](https://discourse.julialang.org/u/Neodym)\
**Replies:** 9\
**Last updated:** [September 15, 2025, 9:25pm UTC](https://discourse.julialang.org/t/how-to-debug-ode-model-aborting-midway-on-sensitivity-computation/132096 "2025-09-15T21:25:06Z")

</div>

Hi there, I have an ODE model that results from the spatial discretization of a PDE including reaction terms. The rate coefficient of the reaction is calculated from an interpolation that is provided externally. I can …

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