You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This part of the docstring is related to the use of `AutoReactant` inside [DifferentiationInterface.jl](https://github.com/JuliaDiff/DifferentiationInterface.jl), or DI for short.
4
+
Reactant's tutorial on [partial evaluation](https://enzymead.github.io/Reactant.jl/stable/tutorials/partial-evaluation) is useful reading to understand what follows.
5
+
6
+
The `AutoReactant` backend inside DI imposes the following restrictions / assumptions:
7
+
8
+
- The only supported operator (at the moment) is `DI.gradient` (along with its variants).
9
+
- The input `x` must be an `AbstractArray` such that `Reactant.ConcreteRArray(x)` is well-defined.
10
+
- By default, contexts such as `DI.Constant` and `DI.Cache` will be partially evaluated inside the compiled differentiation operator at preparation time. This means that the context value provided at preparation will be reused at every subsequent execution, while the context value provided at execution will be ignored. In particular, `DI.Cache` contexts will usually error and `DI.Constant` contexts will be frozen to one value.
11
+
12
+
To disable partial evaluation and enforce tracing of contexts instead, first wrap them into types that _you own_.
13
+
Then, overload [`DifferentiationInterface.to_reactant`](@ref) on these types to perform tracing in the way you see fit, for instance with `Reactant.to_rarray`.
14
+
Every value you choose not to trace will still be partially evaluated at preparation time.
g ≈ a0.u * 2 * (a.v .* x) # a0.u is partially evaluated, a0.v is traced
45
+
46
+
# output
47
+
48
+
true
49
+
```
50
+
"""
51
+
AutoReactant
52
+
53
+
"""
54
+
to_reactant(a)
55
+
56
+
Convert an argument `a` to an object `ar` containing the same values, where all the fields and subfields that can contain active (differentiated) data have been translated to [Reactant.jl](https://github.com/EnzymeAD/Reactant.jl) types such as [`ConcreteRArray`](@extref Reactant.ConcreteRArray) or [`ConcreteRNumber`](@extref Reactant.ConcreteRNumber).
57
+
58
+
!!! danger
59
+
DifferentiationInterface.jl implements this function as the identity, on purpose.
60
+
It should not be overloaded on base types, but only on types that you own, to modify the default behavior of `AutoReactant`.
0 commit comments