# Mooncake with ForwardDiff

**URL:** https://discourse.julialang.org/t/mooncake-with-forwarddiff/123952
**Category:** Specific Domains
**Tags:** question, package, autodiff
**Created:** [December 18, 2024, 8:04am UTC](https://discourse.julialang.org/t/mooncake-with-forwarddiff/123952 "2024-12-18T08:04:21Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![c\_sell](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/c_sell/32/38854_2.png) [@c\_sell](https://discourse.julialang.org/u/c_sell)
#### Post date: [December 18, 2024, 8:04am UTC](https://discourse.julialang.org/t/mooncake-with-forwarddiff/123952/1 "2024-12-18T08:04:21Z")

</div>

Hello,

I would like to know if:

- It is possible to compute the Hessian using a Mooncake backward pass and a ForwardDiff forward pass? Or are there other efficient methods to compute the Hessian?

I tried using [DifferentiationInterface.jl](https://github.com/JuliaDiff/DifferentiationInterface.jl/tree/main), but it crashes when computing the Hessian with the Mooncake backend.

Thank you for your help.

---

<div class="post-metadata">

### Author: ![willtebbutt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/willtebbutt/32/6790_2.png) [@willtebbutt](https://discourse.julialang.org/u/willtebbutt)
#### Post date: [December 18, 2024, 10:23am UTC](https://discourse.julialang.org/t/mooncake-with-forwarddiff/123952/2 "2024-12-18T10:23:07Z")

</div>

Hello! Sadly it is not presently possible to use Mooncake for Hessian computation. There’s an [open PR](https://github.com/compintell/Mooncake.jl/pull/389) to add a forwards-mode AD to Mooncake itself, which will at some point let us use forwards-over-reverse to compute Hessians, but I don’t know when that will be completed.

@gdalle do you have an existing mechanism in DI that we could hook in to to just throw an informative error message if someone tries to use Mooncake to compute higher order stuff?

---

<div class="post-metadata">

### Author: ![c\_sell](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/c_sell/32/38854_2.png) [@c\_sell](https://discourse.julialang.org/u/c_sell)
#### Post date: [December 18, 2024, 10:35am UTC](https://discourse.julialang.org/t/mooncake-with-forwarddiff/123952/3 "2024-12-18T10:35:08Z")

</div>

Okay then I will have to wait.  
Thank you for you reply.

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [December 19, 2024, 9:59am UTC](https://discourse.julialang.org/t/mooncake-with-forwarddiff/123952/4 "2024-12-19T09:59:01Z")

</div>

> [@willtebbutt](#):
>
> @gdalle do you have an existing mechanism in DI that we could hook in to to just throw an informative error message if someone tries to use Mooncake to compute higher order stuff?

I’m afraid not. You’d have to manually overload all second-order operators for `AutoMooncake` to throw an error, and even then this would not take care of `SecondOrder{AutoForwardDiff, AutoMooncake}`.

---

<div class="post-metadata">

### Author: ![willtebbutt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/willtebbutt/32/6790_2.png) [@willtebbutt](https://discourse.julialang.org/u/willtebbutt)
#### Post date: [December 19, 2024, 11:37am UTC](https://discourse.julialang.org/t/mooncake-with-forwarddiff/123952/5 "2024-12-19T11:37:14Z")

</div>

Ahh okay, understood.
