# AD of UDEs - how to set it up?

**URL:** https://discourse.julialang.org/t/ad-of-udes-how-to-set-it-up/133461
**Category:** Modelling & Simulations
**Tags:** diffeq, sciml, autodiff
**Created:** [October 27, 2025, 3:28pm UTC](https://discourse.julialang.org/t/ad-of-udes-how-to-set-it-up/133461 "2025-10-27T15:28:56Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![ForceBru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/forcebru/32/21389_2.png) [@ForceBru](https://discourse.julialang.org/u/ForceBru)
#### Post date: [October 28, 2025, 1:43pm UTC](https://discourse.julialang.org/t/ad-of-udes-how-to-set-it-up/133461/3 "2025-10-28T13:43:26Z")

</div>

> [@Emil\_Martinsen](#):
>
> which seems like a lot for just computing the gradient..?!

Are you comparing against some baseline approach that isn’t considered slow? How much time does that approach take?

In my experience Zygote can be extremely slow: [`Zygote.gradient` is 54000 TIMES slower than `jax.gradient`](https://discourse.julialang.org/t/zygote-gradient-is-54000-times-slower-than-jax-gradient/125396). I ran into this once and never used Zygote since. ForwardDiff seems to be the fastest, easiest to use and most stable. Just browsing this forum I see people having trouble with Enzyme, for example (usually crashes and unintuitive behavior), but I don’t think I’ve ever seen anyone struggle with ForwardDiff: it usually just works, and it’s often surprisingly fast.

EDIT recent examples of people having issues with Enzyme:

- [Lux/Enzyme error when Training my model?](https://discourse.julialang.org/t/lux-enzyme-error-when-training-my-model/133442)
- [Issue: Enzyme + Flux double differentiation on custom layer](https://discourse.julialang.org/t/issue-enzyme-flux-double-differentiation-on-custom-layer/133503)
- People struggling with Enzyme’s native API: [Make mutating function more AD-friendly - #5 by MrMR](https://discourse.julialang.org/t/make-mutating-function-more-ad-friendly/133356/5)
- Zygote works, but Enzyme errors: [Type instability in custom Lux masking layer when using Enzyme/Reactant](https://discourse.julialang.org/t/type-instability-in-custom-lux-masking-layer-when-using-enzyme-reactant/133042)

---

_[View the full topic](https://discourse.julialang.org/t/ad-of-udes-how-to-set-it-up/133461)._
