# \#chainrulescore

**URL:** https://discourse.julialang.org/tag/chainrulescore/756.md

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

---

## [DiffOpt / JuMP: zero gradient for variable fixed by equality constraint](https://discourse.julialang.org/t/diffopt-jump-zero-gradient-for-variable-fixed-by-equality-constraint/134041)

<div class="topic-metadata">

**Author:** [@yeomoon](https://discourse.julialang.org/u/yeomoon)\
**Replies:** 12\
**Last updated:** [November 28, 2025, 5:36am UTC](https://discourse.julialang.org/t/diffopt-jump-zero-gradient-for-variable-fixed-by-equality-constraint/134041 "2025-11-28T05:36:03Z")

</div>

Hi all, I’m trying to train a neural network that is followed by a differentiable optimization layer in Julia. Conceptually it’s: Flux NN → Economic Dispatch layer (ED layer) → Loss The ED layer is implemented as a …

---

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

---

## [ChainRules project looking for a new primary maintainer](https://discourse.julialang.org/t/chainrules-project-looking-for-a-new-primary-maintainer/115636)

<div class="topic-metadata">

**Author:** [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Replies:** 8\
**Last updated:** [September 3, 2024, 4:21pm UTC](https://discourse.julialang.org/t/chainrules-project-looking-for-a-new-primary-maintainer/115636 "2024-09-03T16:21:44Z")

</div>

Hi all, I have been leading the ChainRules project since juliacon 2019. I find myself in circumstances very similar to what Jarret was when he transferred leadership of it to me then – this is a very good thing. As su…

---

## [ZeroTangent definition](https://discourse.julialang.org/t/zerotangent-definition/118069)

<div class="topic-metadata">

**Author:** [@mary](https://discourse.julialang.org/u/mary)\
**Replies:** 2\
**Last updated:** [August 12, 2024, 4:55am UTC](https://discourse.julialang.org/t/zerotangent-definition/118069 "2024-08-12T04:55:02Z")

</div>

Hi, I am using chainrulecore for gradient calculation and rrule. I am trying to follow tutorial 18 of gridap. I cant understand the ZeroTangent in the code why we are using that and what it is suppose to do. I’ve read s…

---

## [Questions with building a chainrules for mutating array function](https://discourse.julialang.org/t/questions-with-building-a-chainrules-for-mutating-array-function/117237)

<div class="topic-metadata">

**Author:** [@chooron](https://discourse.julialang.org/u/chooron)\
**Replies:** 2\
**Last updated:** [July 22, 2024, 8:30am UTC](https://discourse.julialang.org/t/questions-with-building-a-chainrules-for-mutating-array-function/117237 "2024-07-22T08:30:42Z")

</div>

I want to build two functions for replacing values in a vector and an array, as shown below: function mutate\_vec(vec::AbstractVector{T}, new\_value::T, idx::Int) where {T} vec\[idx\] = new\_value vec end function m…

---

## [Custom gradients for function. Resource for rrule and frule](https://discourse.julialang.org/t/custom-gradients-for-function-resource-for-rrule-and-frule/117154)

<div class="topic-metadata">

**Author:** [@KapilKhanal](https://discourse.julialang.org/u/KapilKhanal)\
**Replies:** 18\
**Last updated:** [July 20, 2024, 4:37pm UTC](https://discourse.julialang.org/t/custom-gradients-for-function-resource-for-rrule-and-frule/117154 "2024-07-20T16:37:16Z")

</div>

I am trying to create a custom gradients for a greens function whose term by term direct differentiation is not that accurate and we have a derivation of it’s derivatives and would like to use those. For the simple MWE e…

---

## [Rrule (or frule) with kwargs](https://discourse.julialang.org/t/rrule-or-frule-with-kwargs/114150)

<div class="topic-metadata">

**Author:** [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Replies:** 9\
**Last updated:** [July 3, 2024, 3:05pm UTC](https://discourse.julialang.org/t/rrule-or-frule-with-kwargs/114150 "2024-07-03T15:05:34Z")

</div>

How does one define an rrule for a function, where the argument you want the derivative for is a key word argument (kwargs) ? Here is some previous discussion but this is a while ago and the whole structure seems to h…

---

## [Implementing derivative in ChainRules for function with internal fields](https://discourse.julialang.org/t/implementing-derivative-in-chainrules-for-function-with-internal-fields/66844)

<div class="topic-metadata">

**Author:** [@jcallaham](https://discourse.julialang.org/u/jcallaham)\
**Replies:** 5\
**Last updated:** [November 30, 2023, 2:06am UTC](https://discourse.julialang.org/t/implementing-derivative-in-chainrules-for-function-with-internal-fields/66844 "2023-11-30T02:06:25Z")

</div>

I’m trying to define an rrule for a functional, e.g. numerical integration of a given function, and the gradient would be with respect to the parameters of the function. This works no problem with a simple implementatio…

---

## [Gradient accumulation using chainrulecore](https://discourse.julialang.org/t/gradient-accumulation-using-chainrulecore/104208)

<div class="topic-metadata">

**Author:** [@mary](https://discourse.julialang.org/u/mary)\
**Replies:** 1\
**Last updated:** [September 25, 2023, 2:20pm UTC](https://discourse.julialang.org/t/gradient-accumulation-using-chainrulecore/104208 "2023-09-25T14:20:15Z")

</div>

Hi, I am using chainrulecore and zygote and rrule to define my accumulation derivation formulation. the derivative of my function is ∑\_(i=1)^n▒〖w^t da/dr u〗 in order to solve this i have defined below code. Note that…

---

## [Second order derivatives with ChainRules](https://discourse.julialang.org/t/second-order-derivatives-with-chainrules/103606)

<div class="topic-metadata">

**Author:** [@mariusd](https://discourse.julialang.org/u/mariusd)\
**Replies:** 1\
**Last updated:** [September 7, 2023, 1:48pm UTC](https://discourse.julialang.org/t/second-order-derivatives-with-chainrules/103606 "2023-09-07T13:48:54Z")

</div>

How can I get the second order derivarive of a function using ChainRules? Bellow is my approach for the sin function. See the following code: using ChainRules using ChainRulesCore # from the docs, first derivative of …

---

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

---

## [Problem with training a spiking neural network with Flux](https://discourse.julialang.org/t/problem-with-training-a-spiking-neural-network-with-flux/95149)

<div class="topic-metadata">

**Author:** [@Daniele\_Linaro](https://discourse.julialang.org/u/Daniele_Linaro)\
**Replies:** 7\
**Last updated:** [March 6, 2023, 4:30pm UTC](https://discourse.julialang.org/t/problem-with-training-a-spiking-neural-network-with-flux/95149 "2023-03-06T16:30:53Z")

</div>

Hello, I am trying to use Flux to train a simple spiking neural network to perform input classification. The network has 100 inputs that represent incoming spike streams: half of the inputs are “active” (i.e., they rece…

---

## [Automatic gradient ∼10x slower to evaluate than the primal computation](https://discourse.julialang.org/t/automatic-gradient-10x-slower-to-evaluate-than-the-primal-computation/93925)

<div class="topic-metadata">

**Author:** [@user22](https://discourse.julialang.org/u/user22)\
**Replies:** 2\
**Last updated:** [February 3, 2023, 6:15am UTC](https://discourse.julialang.org/t/automatic-gradient-10x-slower-to-evaluate-than-the-primal-computation/93925 "2023-02-03T06:15:44Z")

</div>

I need to evaluate a basic dense and a few-layer neural network with up to tens of thousands of inputs at once. The outputs will be then forwarded to another function, which returns a scalar. However, the performance of …

---

## [How to @opt\_out rules defined with RuleConfig in Zygote](https://discourse.julialang.org/t/how-to-opt-out-rules-defined-with-ruleconfig-in-zygote/92014)

<div class="topic-metadata">

**Author:** [@tansongchen](https://discourse.julialang.org/u/tansongchen)\
**Replies:** 0\
**Last updated:** [December 22, 2022, 6:29pm UTC](https://discourse.julialang.org/t/how-to-opt-out-rules-defined-with-ruleconfig-in-zygote/92014 "2022-12-22T18:29:16Z")

</div>

Let’s say I have a type WeirdNumber \<: Number is so weird that I don’t want its derivative of power function (^) be calculated by rrule of ^ and literal\_pow, and should instead go through and differentiate its definition…

---

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

---

## [Applying Reverse-Mode AD to ForwardDiff Derivatives/Gradients](https://discourse.julialang.org/t/applying-reverse-mode-ad-to-forwarddiff-derivatives-gradients/80446)

<div class="topic-metadata">

**Author:** [@codyrucker](https://discourse.julialang.org/u/codyrucker)\
**Replies:** 0\
**Last updated:** [May 3, 2022, 8:52pm UTC](https://discourse.julialang.org/t/applying-reverse-mode-ad-to-forwarddiff-derivatives-gradients/80446 "2022-05-03T20:52:21Z")

</div>

I am building a neural net and want to be able to differentiate the network with respect to the model input . I would then like to compute the gradient(with respect to the network weights and bias) of this derivative. I …

---

## [Getting ChainRules to work with custom Dense and Chain regularization functions](https://discourse.julialang.org/t/getting-chainrules-to-work-with-custom-dense-and-chain-regularization-functions/79334)

<div class="topic-metadata">

**Author:** [@user22](https://discourse.julialang.org/u/user22)\
**Replies:** 2\
**Last updated:** [April 20, 2022, 7:46pm UTC](https://discourse.julialang.org/t/getting-chainrules-to-work-with-custom-dense-and-chain-regularization-functions/79334 "2022-04-20T19:46:45Z")

</div>

I have encountered a few issues when trying to implement a regularizer function and its pullback in ChainRules to a mildly customized Flux Dense layer and Chain. For simplicity and testing purposes, I just wrote a basic …

---

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

---

## [Troubles with 'train!' under Flux.jl whilst using 'Chain' function](https://discourse.julialang.org/t/troubles-with-train-under-flux-jl-whilst-using-chain-function/75834)

<div class="topic-metadata">

**Author:** [@ashish.pujari](https://discourse.julialang.org/u/ashish.pujari)\
**Replies:** 3\
**Last updated:** [February 5, 2022, 7:49pm UTC](https://discourse.julialang.org/t/troubles-with-train-under-flux-jl-whilst-using-chain-function/75834 "2022-02-05T19:49:18Z")

</div>

I am new to Flux.jl and its application in the domain of Deep Learning. Running the introductory code (provided at Overview · Flux) seems to do a good job of showcasing Flux’s abilities. The issue starts when I replace …

---

## [Custom rrule for Feedback Alignment](https://discourse.julialang.org/t/custom-rrule-for-feedback-alignment/72159)

<div class="topic-metadata">

**Author:** [@Rasmus\_Hoier](https://discourse.julialang.org/u/Rasmus_Hoier)\
**Replies:** 2\
**Last updated:** [November 27, 2021, 8:10pm UTC](https://discourse.julialang.org/t/custom-rrule-for-feedback-alignment/72159 "2021-11-27T20:10:36Z")

</div>

Hi, I am trying to use a custom rrule to implement Feedback Alignment learning (which is just like BP except that the error signals are propagated backwards using random feedback weights B, which is supposed to be more …

---

## [How to write a generic rrule?](https://discourse.julialang.org/t/how-to-write-a-generic-rrule/69058)

<div class="topic-metadata">

**Author:** [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Replies:** 1\
**Last updated:** [October 2, 2021, 9:56pm UTC](https://discourse.julialang.org/t/how-to-write-a-generic-rrule/69058 "2021-10-02T21:56:04Z")

</div>

Consider the following example: function ancestor\_accumulate(x::AbstractMatrix, ancestors::AbstractVector{Int}) @assert size(x, 2) == length(ancestors) @assert issorted(ancestors) && all(a .\< 1:length(ancestors)…

---

## [Diagnosing rrule issues](https://discourse.julialang.org/t/diagnosing-rrule-issues/69036)

<div class="topic-metadata">

**Author:** [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Replies:** 8\
**Last updated:** [October 1, 2021, 2:24pm UTC](https://discourse.julialang.org/t/diagnosing-rrule-issues/69036 "2021-10-01T14:24:01Z")

</div>

I am using ChainRulesTestUtils to test an rrule for a function mulsafe I define below. The idea is that mulsafe(x,y) returns the product x .\* y, but giving a strong zero if x == 0 (even if y is Inf, or NaN). using Chain…

---

## [ChainRulesCore: Custom adjoint ignored in certain cases](https://discourse.julialang.org/t/chainrulescore-custom-adjoint-ignored-in-certain-cases/67814)

<div class="topic-metadata">

**Author:** [@Rasmus\_Hoier](https://discourse.julialang.org/u/Rasmus_Hoier)\
**Replies:** 3\
**Last updated:** [September 7, 2021, 2:32pm UTC](https://discourse.julialang.org/t/chainrulescore-custom-adjoint-ignored-in-certain-cases/67814 "2021-09-07T14:32:10Z")

</div>

Hi, A colleague of mine ran into the issue that custom adjoints get ignored in certain cases in recent versions of ChainRulesCore. Here is a minimal working example: using Flux, ChainRulesCore my\_fun(x) = x\*x …

---

## [Using ChainRules rrule for mutating function to work with Zygote](https://discourse.julialang.org/t/using-chainrules-rrule-for-mutating-function-to-work-with-zygote/67375)

<div class="topic-metadata">

**Author:** [@mrVeng](https://discourse.julialang.org/u/mrVeng)\
**Replies:** 2\
**Last updated:** [August 31, 2021, 10:03am UTC](https://discourse.julialang.org/t/using-chainrules-rrule-for-mutating-function-to-work-with-zygote/67375 "2021-08-31T10:03:39Z")

</div>

Hi there, I would like to add an rrule for a function that mutates an input array that I want to differentiate with. The following functions can be used with Forward/ReverseDiff, but gives me an Mutation error with Zyg…

---

## [Automatic differentiation of \`cispi\`](https://discourse.julialang.org/t/automatic-differentiation-of-cispi/66075)

<div class="topic-metadata">

**Author:** [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Replies:** 4\
**Last updated:** [August 11, 2021, 3:43pm UTC](https://discourse.julialang.org/t/automatic-differentiation-of-cispi/66075 "2021-08-11T15:43:20Z")

</div>

I think the rrule for cispi seems to be missing. Maybe it should be included in the basic set of rules? function loss2(data) sum(abs.(cispi.(data))) end data = ones(2,2) loss2(data) gradient(loss2, data) yields: j…

---

## [Taking Complex Autodiff Seriously in ChainRules](https://discourse.julialang.org/t/taking-complex-autodiff-seriously-in-chainrules/39317)

<div class="topic-metadata">

**Author:** [@Mason](https://discourse.julialang.org/u/Mason)\
**Replies:** 65\
**Last updated:** [July 10, 2020, 1:45pm UTC](https://discourse.julialang.org/t/taking-complex-autodiff-seriously-in-chainrules/39317 "2020-07-10T13:45:07Z")

</div>

So these conversations have been starting up recently again on the Slack autodiff channel and in places like Complex numbers · Issue #159 · JuliaDiff/ChainRulesCore.jl · GitHub. I think there’s a lot of misconceptions o…
