# \#reversediff

**URL:** https://discourse.julialang.org/tag/reversediff/583.md

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

---

## [Understanding the Lux.jl + ReverseDiff TrackedArray Warning in UDEs](https://discourse.julialang.org/t/understanding-the-lux-jl-reversediff-trackedarray-warning-in-udes/132488)

<div class="topic-metadata">

**Author:** [@guscaldas](https://discourse.julialang.org/u/guscaldas)\
**Replies:** 2\
**Last updated:** [September 22, 2025, 1:47pm UTC](https://discourse.julialang.org/t/understanding-the-lux-jl-reversediff-trackedarray-warning-in-udes/132488 "2025-09-22T13:47:43Z")

</div>

Hello everyone, I’m working with Universal Differential Equations (UDEs) using Lux.jl and Optimization.jl, and I consistently encounter the following warning when the training process begins. This also happens when runn…

---

## [Avoiding redundant computation when using Zygote and ForwardDiff for forward-over-reverse hessians](https://discourse.julialang.org/t/avoiding-redundant-computation-when-using-zygote-and-forwarddiff-for-forward-over-reverse-hessians/126827)

<div class="topic-metadata">

**Author:** [@IvanBioli](https://discourse.julialang.org/u/IvanBioli)\
**Replies:** 4\
**Last updated:** [March 12, 2025, 8:53am UTC](https://discourse.julialang.org/t/avoiding-redundant-computation-when-using-zygote-and-forwarddiff-for-forward-over-reverse-hessians/126827 "2025-03-12T08:53:29Z")

</div>

I am computing the Hessian of a function using a combination of Zygote (reverse-mode AD) and ForwardDiff (forward-mode AD). A MWE of my current implementation is as follows: using Zygote, ForwardDiff, DiffResults # Def…

---

## [Parameters of the neural network not updating after training in a Neural ODE problem](https://discourse.julialang.org/t/parameters-of-the-neural-network-not-updating-after-training-in-a-neural-ode-problem/125554)

<div class="topic-metadata">

**Author:** [@Ashima\_Kalathingal](https://discourse.julialang.org/u/Ashima_Kalathingal)\
**Replies:** 13\
**Last updated:** [February 16, 2025, 10:57pm UTC](https://discourse.julialang.org/t/parameters-of-the-neural-network-not-updating-after-training-in-a-neural-ode-problem/125554 "2025-02-16T22:57:09Z")

</div>

Hello, I have been struggling with this problem for some time now. I have constructed an example neural ode problem related to my work using the following example. https://docs.sciml.ai/Overview/stable/showcase/missing\_…

---

## [Enzyme not working](https://discourse.julialang.org/t/enzyme-not-working/116214)

<div class="topic-metadata">

**Author:** [@miguelborrero](https://discourse.julialang.org/u/miguelborrero)\
**Replies:** 10\
**Last updated:** [July 23, 2024, 9:07pm UTC](https://discourse.julialang.org/t/enzyme-not-working/116214 "2024-07-23T21:07:18Z")

</div>

Hi there, Opening this issue to see whether I could get some help (@wsmoses ) with making Reverse mode in autodiff work. I made it work on trivial examples, even containing conditional statements but for some reason it …

---

## [Enzyme "Attempting to call an indirect active function whose runtime value is inactive" in Forward Over Reverse Mode](https://discourse.julialang.org/t/enzyme-attempting-to-call-an-indirect-active-function-whose-runtime-value-is-inactive-in-forward-over-reverse-mode/116841)

<div class="topic-metadata">

**Author:** [@dleather](https://discourse.julialang.org/u/dleather)\
**Replies:** 7\
**Last updated:** [July 10, 2024, 9:34pm UTC](https://discourse.julialang.org/t/enzyme-attempting-to-call-an-indirect-active-function-whose-runtime-value-is-inactive-in-forward-over-reverse-mode/116841 "2024-07-10T21:34:36Z")

</div>

I’m attempting to apply forward over reverse mode following the Enzyme.jl tutorial. The function, f:\\mathbb{R}^N \\rightarrow \\mathbb{R^{++}}, is complicated but doesn’t involve any terms more difficult than hyperbolic fu…

---

## [How to: High-performance differentiable programming with broad AD-library support?](https://discourse.julialang.org/t/how-to-high-performance-differentiable-programming-with-broad-ad-library-support/113884)

<div class="topic-metadata">

**Author:** [@ThummeTo](https://discourse.julialang.org/u/ThummeTo)\
**Replies:** 13\
**Last updated:** [May 6, 2024, 3:35pm UTC](https://discourse.julialang.org/t/how-to-high-performance-differentiable-programming-with-broad-ad-library-support/113884 "2024-05-06T15:35:28Z")

</div>

Hi at all, I am currently struggling with three (competing?) goals on code design. I want code, that: (1) is fast, (b) is differentiable and (c) differentiable by current (and future) AD-libraries (like at least Forward…

---

## [Trouble writing custom rule in Enzyme: \`AssertionError: !(overwritten\[end\])\`](https://discourse.julialang.org/t/trouble-writing-custom-rule-in-enzyme-assertionerror-overwritten-end/108939)

<div class="topic-metadata">

**Author:** [@Gianluca\_Fuwa](https://discourse.julialang.org/u/Gianluca_Fuwa)\
**Replies:** 3\
**Last updated:** [February 20, 2024, 11:25pm UTC](https://discourse.julialang.org/t/trouble-writing-custom-rule-in-enzyme-assertionerror-overwritten-end/108939 "2024-02-20T23:25:57Z")

</div>

Hi, I am currently trying to use Enzyme to get the derivative of a function that takes a multidimensional array of 3x3 matrices and outputs a scalar. The caveat is that these matrices are elements of the Lie-group of sp…

---

## [ReverseDiff.jl failing with the Base.tanh function?](https://discourse.julialang.org/t/reversediff-jl-failing-with-the-base-tanh-function/107474)

<div class="topic-metadata">

**Author:** [@Alejandro\_Quiaro\_San](https://discourse.julialang.org/u/Alejandro_Quiaro_San)\
**Replies:** 5\
**Last updated:** [December 12, 2023, 9:52pm UTC](https://discourse.julialang.org/t/reversediff-jl-failing-with-the-base-tanh-function/107474 "2023-12-12T21:52:45Z")

</div>

Hello Guys, I’m trying to build a probabilistic model in Turing.jl, and it is supposed that when you change the AD backend to :reversediff you get computational improvements. I have a forward operator inside my probabil…

---

## [Nesting the GLM.jl in the objective function when formulating the ReverseDiff gradient generates StackOverflowError](https://discourse.julialang.org/t/nesting-the-glm-jl-in-the-objective-function-when-formulating-the-reversediff-gradient-generates-stackoverflowerror/107050)

<div class="topic-metadata">

**Author:** [@xxxxx](https://discourse.julialang.org/u/xxxxx)\
**Replies:** 5\
**Last updated:** [December 4, 2023, 8:01pm UTC](https://discourse.julialang.org/t/nesting-the-glm-jl-in-the-objective-function-when-formulating-the-reversediff-gradient-generates-stackoverflowerror/107050 "2023-12-04T20:01:54Z")

</div>

Hi, in formulating my objective function for optimization, in one of the steps, the parameters will enter a Poisson regression as the weight, which I implemented through GLM.jl package. However, when generating the gradi…

---

## [Improve speed of vector-jacobian product](https://discourse.julialang.org/t/improve-speed-of-vector-jacobian-product/106312)

<div class="topic-metadata">

**Author:** [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Replies:** 2\
**Last updated:** [November 16, 2023, 6:31pm UTC](https://discourse.julialang.org/t/improve-speed-of-vector-jacobian-product/106312 "2023-11-16T18:31:59Z")

</div>

Hi, I would like to improve some part of a code which relies on vector-jacobian product (vjp), ie computing the action of the adjoint of an operator. On my computer, the computation of vjp is ~100x slower than the evalu…

---

## [Novel method for feature importance using ReverseMode + ForwardMode autodiff?](https://discourse.julialang.org/t/novel-method-for-feature-importance-using-reversemode-forwardmode-autodiff/105837)

<div class="topic-metadata">

**Author:** [@nielsls](https://discourse.julialang.org/u/nielsls)\
**Replies:** 4\
**Last updated:** [November 7, 2023, 8:04am UTC](https://discourse.julialang.org/t/novel-method-for-feature-importance-using-reversemode-forwardmode-autodiff/105837 "2023-11-07T08:04:33Z")

</div>

Using a combination of reverse- and forward-mode autodiff I have come across a highly efficient method for attributing the change in a differentiable scalar-valued function f: R^N-\>R^1 (e.g. a neural network) to the inpu…

---

## [Breakpoint/infiltrate inside a gradient calculation (Zygote or ReverseDiff)?](https://discourse.julialang.org/t/breakpoint-infiltrate-inside-a-gradient-calculation-zygote-or-reversediff/104568)

<div class="topic-metadata">

**Author:** [@Qfl3x](https://discourse.julialang.org/u/Qfl3x)\
**Replies:** 4\
**Last updated:** [October 4, 2023, 12:20pm UTC](https://discourse.julialang.org/t/breakpoint-infiltrate-inside-a-gradient-calculation-zygote-or-reversediff/104568 "2023-10-04T12:20:23Z")

</div>

I’m trying to debug why Zygote and ReverseDiff don’t work with MethodOfLines, however, I’m struggling to break inside the gradient calculation. Zygote and ReverseDiff are changing the types of some inputs. Breakpoints in…

---

## [Calculating Third (and Higher) Derivatives: ReverseDiff gives 0s while ForwardDiff works](https://discourse.julialang.org/t/calculating-third-and-higher-derivatives-reversediff-gives-0s-while-forwarddiff-works/101095)

<div class="topic-metadata">

**Author:** [@HappyQuokka](https://discourse.julialang.org/u/HappyQuokka)\
**Replies:** 1\
**Last updated:** [July 3, 2023, 2:14am UTC](https://discourse.julialang.org/t/calculating-third-and-higher-derivatives-reversediff-gives-0s-while-forwarddiff-works/101095 "2023-07-03T02:14:33Z")

</div>

I am trying to calculate the third derivative (tensor). ForwardDiff seems to work but is incredibly slow, also for lower orders. ReverseDiff, while fast for lower derivatives, doesn’t seem to work for third derivatives o…

---

## [Zygote.jl: How to get the gradient of sparse matrix](https://discourse.julialang.org/t/zygote-jl-how-to-get-the-gradient-of-sparse-matrix/59067)

<div class="topic-metadata">

**Author:** [@Richard-Li](https://discourse.julialang.org/u/Richard-Li)\
**Replies:** 11\
**Last updated:** [June 13, 2023, 5:17pm UTC](https://discourse.julialang.org/t/zygote-jl-how-to-get-the-gradient-of-sparse-matrix/59067 "2023-06-13T17:17:20Z")

</div>

Hi there, I am trying to differentiate through sparse matrix, and here is the MWE: using LinearAlgebra using SparseArrays using ChainRulesCore using Zygote Zygote.@adjoint function SparseMatrixCSC{T,N}(arr) where {T,N}…

---

## [Issue while using ReverseDiff in turing model](https://discourse.julialang.org/t/issue-while-using-reversediff-in-turing-model/99723)

<div class="topic-metadata">

**Author:** [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Replies:** 4\
**Last updated:** [June 1, 2023, 1:16pm UTC](https://discourse.julialang.org/t/issue-while-using-reversediff-in-turing-model/99723 "2023-06-01T13:16:39Z")

</div>

Hello, In discourse I found out that using reversediff is better for performance when you have high dimensional model. So, I’m trying to switch to reversediff from forwarddiff. But at the moment I’m facing this issue n…

---

## [ReverseDiff over ForwardDiff behaves strangely with Lux networks (Issue)](https://discourse.julialang.org/t/reversediff-over-forwarddiff-behaves-strangely-with-lux-networks-issue/99175)

<div class="topic-metadata">

**Author:** [@Bizzi](https://discourse.julialang.org/u/Bizzi)\
**Replies:** 3\
**Last updated:** [May 23, 2023, 2:06am UTC](https://discourse.julialang.org/t/reversediff-over-forwarddiff-behaves-strangely-with-lux-networks-issue/99175 "2023-05-23T02:06:13Z")

</div>

Hello everyone. For my work with PINNs, I am trying to use ReverseDiff to calculate the gradient of a loss function that itself contains a ForwardDiff gradient. It is easy enough to do so with explicitly-parametrized dec…

---

## [Ignore derivatives in ReverseDiff](https://discourse.julialang.org/t/ignore-derivatives-in-reversediff/97252)

<div class="topic-metadata">

**Author:** [@skrinkle](https://discourse.julialang.org/u/skrinkle)\
**Replies:** 0\
**Last updated:** [April 8, 2023, 5:30pm UTC](https://discourse.julialang.org/t/ignore-derivatives-in-reversediff/97252 "2023-04-08T17:30:26Z")

</div>

I want to exclude some functions in my model code from gradient calculations, using @ignore\_derivatives from ChainRulesCore. It works with Zygote, but not with ReverseDiff. Here’s a MWE. using Zygote, ReverseDiff import…

---

## [ReverseDiff with Flux model](https://discourse.julialang.org/t/reversediff-with-flux-model/96452)

<div class="topic-metadata">

**Author:** [@Avec](https://discourse.julialang.org/u/Avec)\
**Replies:** 2\
**Last updated:** [March 23, 2023, 10:04am UTC](https://discourse.julialang.org/t/reversediff-with-flux-model/96452 "2023-03-23T10:04:28Z")

</div>

Hi all, I am trying to get a gradient of a Flux model with a different package than Zygote or ForwardDiff (Zygote cannot get through my real loss function and ForwardDiff is too slow). Since my loss function returns scal…

---

## [Possible to save compiled GradientTape after compile in ReverseDiff](https://discourse.julialang.org/t/possible-to-save-compiled-gradienttape-after-compile-in-reversediff/95693)

<div class="topic-metadata">

**Author:** [@xxxxx](https://discourse.julialang.org/u/xxxxx)\
**Replies:** 8\
**Last updated:** [March 8, 2023, 12:38am UTC](https://discourse.julialang.org/t/possible-to-save-compiled-gradienttape-after-compile-in-reversediff/95693 "2023-03-08T00:38:25Z")

</div>

Hi, I was wondering if it would be possible to save the compiled GradientTape that is used in ReverseDiff.jl. Using the gradient example from the package, I’d like to save compiled\_f\_tape # some objective function t…

---

## [ReverseDiff method error in multiplication](https://discourse.julialang.org/t/reversediff-method-error-in-multiplication/91758)

<div class="topic-metadata">

**Author:** [@slwu89](https://discourse.julialang.org/u/slwu89)\
**Replies:** 1\
**Last updated:** [December 21, 2022, 8:49pm UTC](https://discourse.julialang.org/t/reversediff-method-error-in-multiplication/91758 "2022-12-21T20:49:21Z")

</div>

Hi all, I have a question about a method error in ReverseDiff.jl, which arises in my function when calling \* (line p/g + p\*(a-am) in my MWE below), and using ReverseDiff to calculate the Hessian matrix. I’ve checked tha…

---

## [Concatenation causes multiplication type problems in ReverseDiff](https://discourse.julialang.org/t/concatenation-causes-multiplication-type-problems-in-reversediff/91917)

<div class="topic-metadata">

**Author:** [@fratrik](https://discourse.julialang.org/u/fratrik)\
**Replies:** 0\
**Last updated:** [December 20, 2022, 9:38pm UTC](https://discourse.julialang.org/t/concatenation-causes-multiplication-type-problems-in-reversediff/91917 "2022-12-20T21:38:19Z")

</div>

using ReverseDiff function f(a) b = \[1 2\] (\[a; b\]\*a)\*a \[a\*a\*a; b\*a\*a\] \[a\*a; b\*a\]\*a # error here 0 end ReverseDiff.hessian(f, randn(2, 2)) the code fails on \[a\*a; b\*a\]\*a with message ERROR: L…

---

## [ReverseDiff not using custom derivative from ChainRules](https://discourse.julialang.org/t/reversediff-not-using-custom-derivative-from-chainrules/89888)

<div class="topic-metadata">

**Author:** [@mrVeng](https://discourse.julialang.org/u/mrVeng)\
**Replies:** 3\
**Last updated:** [November 7, 2022, 6:02pm UTC](https://discourse.julialang.org/t/reversediff-not-using-custom-derivative-from-chainrules/89888 "2022-11-07T18:02:18Z")

</div>

Hi there, I would like to use a custom derivative for a function - the cdf of a T distribution wrt to the data. I keep the parameter of this distribution fixed, so NoTangent for the parameter is enough for me here. Here…

---

## [ReverseDiff friendly code and domain errors](https://discourse.julialang.org/t/reversediff-friendly-code-and-domain-errors/89007)

<div class="topic-metadata">

**Author:** [@Luis\_Calderon](https://discourse.julialang.org/u/Luis_Calderon)\
**Replies:** 1\
**Last updated:** [October 20, 2022, 4:10pm UTC](https://discourse.julialang.org/t/reversediff-friendly-code-and-domain-errors/89007 "2022-10-20T16:10:16Z")

</div>

Dear all, At the moment, I have the following set-up: Opts = Optim.Options( x\_tol = 0.0, f\_tol = 0.0, g\_…

---

## [Clarification on Setrdcache in Turing?](https://discourse.julialang.org/t/clarification-on-setrdcache-in-turing/88767)

<div class="topic-metadata">

**Author:** [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Replies:** 7\
**Last updated:** [October 16, 2022, 2:20pm UTC](https://discourse.julialang.org/t/clarification-on-setrdcache-in-turing/88767 "2022-10-16T14:20:53Z")

</div>

So, https://turing.ml/dev/docs/using-turing/autodiff says: However, note that the use of caching in certain types of models can lead to incorrect results and/or errors. Models for which the compiled tape can be safely …

---

## [ReverseDiff - differentiating with respect to some parameters but not others](https://discourse.julialang.org/t/reversediff-differentiating-with-respect-to-some-parameters-but-not-others/84345)

<div class="topic-metadata">

**Author:** [@Nathaniel](https://discourse.julialang.org/u/Nathaniel)\
**Replies:** 6\
**Last updated:** [July 18, 2022, 3:42am UTC](https://discourse.julialang.org/t/reversediff-differentiating-with-respect-to-some-parameters-but-not-others/84345 "2022-07-18T03:42:50Z")

</div>

I’m planning on training some neural networks using ReverseDiff.jl (which I think makes sense because I’ll be training lots of small networks on the CPU), but I have a basic question about how ReverseDiff is intended to …

---

## [Correct Way to Compose ReverseDiff and ForwardDiff](https://discourse.julialang.org/t/correct-way-to-compose-reversediff-and-forwarddiff/83708)

<div class="topic-metadata">

**Author:** [@RS-Coop](https://discourse.julialang.org/u/RS-Coop)\
**Replies:** 8\
**Last updated:** [July 4, 2022, 3:22pm UTC](https://discourse.julialang.org/t/correct-way-to-compose-reversediff-and-forwarddiff/83708 "2022-07-04T15:22:45Z")

</div>

I am trying to use ReverseDiff.jl and ForwardDiff.jl as a mixed mode AD approach to computing a Hessian vector product. I am using the following function: import ForwardDiff as fdiff import ReverseDiff as rdiff functio…

---

## [Mutating array workaround for reverse AD?](https://discourse.julialang.org/t/mutating-array-workaround-for-reverse-ad/81009)

<div class="topic-metadata">

**Author:** [@beryl](https://discourse.julialang.org/u/beryl)\
**Replies:** 5\
**Last updated:** [May 18, 2022, 12:00pm UTC](https://discourse.julialang.org/t/mutating-array-workaround-for-reverse-ad/81009 "2022-05-18T12:00:18Z")

</div>

Hi, I have yet another unsolved problem for reverse mode AD (or I think, this is the same problem as the one I posted previously: LoadError: ArgumentError: Converting an instance of ReverseDiff.TrackedReal{Float64, Floa…

---

## [Zygote / ReverseDiff not matching input types](https://discourse.julialang.org/t/zygote-reversediff-not-matching-input-types/80838)

<div class="topic-metadata">

**Author:** [@evolbio](https://discourse.julialang.org/u/evolbio)\
**Replies:** 0\
**Last updated:** [May 10, 2022, 7:27pm UTC](https://discourse.julialang.org/t/zygote-reversediff-not-matching-input-types/80838 "2022-05-10T19:27:06Z")

</div>

In my code, the line (y ./ k).^h throws a Zygote / ReverseDiff error but works without problem with ForwardDiff. Here, k and h are views of a parameter vector and y is a subset of the variable vector that depends on the …

---

## [LoadError: ArgumentError: Converting an instance of ReverseDiff.TrackedReal{Float64, Float64, Nothing} to Float64 is not defined. Please use \`ReverseDiff.value\` instead](https://discourse.julialang.org/t/loaderror-argumenterror-converting-an-instance-of-reversediff-trackedreal-float64-float64-nothing-to-float64-is-not-defined-please-use-reversediff-value-instead/80544)

<div class="topic-metadata">

**Author:** [@beryl](https://discourse.julialang.org/u/beryl)\
**Replies:** 0\
**Last updated:** [May 5, 2022, 2:02pm UTC](https://discourse.julialang.org/t/loaderror-argumenterror-converting-an-instance-of-reversediff-trackedreal-float64-float64-nothing-to-float64-is-not-defined-please-use-reversediff-value-instead/80544 "2022-05-05T14:02:16Z")

</div>

Hi, I’d like to take a gradient of a simple function using ReverseDiff, however I stumbled upon an error which I haven’t been able figure out, the code which throws the error is using ReverseDiff function f\_V(R, a, b,…

---

## [Custom ChainRulesCore rrule with ReverseDiff](https://discourse.julialang.org/t/custom-chainrulescore-rrule-with-reversediff/77389)

<div class="topic-metadata">

**Author:** [@smharwood](https://discourse.julialang.org/u/smharwood)\
**Replies:** 2\
**Last updated:** [March 4, 2022, 2:50pm UTC](https://discourse.julialang.org/t/custom-chainrulescore-rrule-with-reversediff/77389 "2022-03-04T14:50:43Z")

</div>

I’m having trouble finding documentation to get ReverseDiff to use a custom adjoint defined using ChainRulesCore.rrule. MWE: import Zygote, ReverseDiff import ChainRulesCore function f(x) x'\*x end function ChainRulesC…

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