Replies: 2 comments 5 replies
-
Hi @RoyCCWang . Thanks for opening this discussion (, and for your issue regarding the docs!) This sounds like an example that Mooncake.jl ought (in principle) to handle fine without any additional rules.
This sounds like it should be fine. Could you provide an example of what you'd like to do?
You shouldn't usually have to do this. It would be really very helpful if you could provide a minimal working example (MWE) that demonstrates the kind of thing that you're trying to do / is characteristic of the code you are trying to differentiate. I'm very happy to help with any problems you have, but it's easiest to help if we have some specific code to anchor conversation. |
Beta Was this translation helpful? Give feedback.
-
Here is a long example. This code is intended to eventually be statically compiled when trim + smaller binaries arrive, so a few constrained type annotations are used. The goal is to get the derivatives of There is a The
On my machine, I have the following in my REPL:
In this case, the non-in-place
On my machine, my REPL shows:
If I don't use
and use only Mooncake.jl commands, how can I directly differentiate Currently, I need to use a closure |
Beta Was this translation helpful? Give feedback.
-
I work with Julia functions of the form:
f!(state, input, params)
, whereinput
is the variable that I want to differentiate.f!
returns a scalar value of typeReal
.state
andparams
are some custom data type implemented as astruct
, which might contain heap-allocated types likeMemory
or something fromAbstractVector
.input
can be of a type fromAbstractVector{<:Real}
, like `Memory{Float64}.state
is mutated whenf!
is evaluated.params
andinput
are unchanged whenf!
is evaluated.f!
is type stable, and does not allocate memory when it is evaluated.I just discovered Mooncake.jl, and got it working via the quick-start section of the readme. I used DifferentiationInterface.jl just to test correctness without worrying allocation and type stability, so I'm using a closure to define
f
. The rough code looks likeThis works, and my micro benchmark speed shows promise!
I am now going through Mooncake.jl's documentation to see if I can directly differentiate
f!
without wrapping it in a callable struct or closure, in a type stable and non-allocating manner. I suspect I need to define custom rules for suchf!
and any mutating functions that is called whenf!
is evaluated. I'm about to start with the section "Mooncake.jl's Rules System". Does anyone have tips or suggestions on which sections of the documentation to focus on for my usage case?Beta Was this translation helpful? Give feedback.
All reactions