Skip to content

Commit

Permalink
Merge pull request #646 from JuliaDiff/ox/nomutationexample
Browse files Browse the repository at this point in the history
Remove example of mutation support config from docs
  • Loading branch information
oxinabox authored Jan 25, 2024
2 parents 1b0e41a + 7e09871 commit 6664e8f
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions docs/src/rule_author/superpowers/ruleconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,11 @@ end

The `>:HasReverseMode` and `>:HasForwardsMode` are two examples of special properties that a `RuleConfig` could allow.
Others could also exist, but right now they are the only two.
It is likely that in the future such will be provided for e.g. mutation support.

Such a thing would look like:
```julia
struct SupportsMutation end

function rrule(
::RuleConfig{>:SupportsMutation}, typeof(push!), x::Vector
)
y = push!(x)

function push!_pullback(ȳ)
pop!(x) # undo change to primal incase it is used in another pullback we haven't called yet
pop!(ȳ) # accumulate gradient via mutating ȳ, then return ZeroTangent
return NoTangent(), ZeroTangent()
end

return y, push!_pullback
end
```
and it would be used in the AD e.g. as follows:
```julia
struct EnzymeRuleConfig <: RuleConfig{Union{SupportsMutation, HasReverseMode, NoForwardsMode}}
```
It is likely that in the future other such will be provided

Note: you can only depend on the presence of a feature, not its absence.
This means we may need to define features and their complements, when one is not the obvious default (as in the case of [`HasReverseMode`](@ref)/[`NoReverseMode`](@ref) and [`HasForwardsMode`](@ref)/[`NoForwardsMode`](@ref).).


Such special properties generally should only be defined in `ChainRulesCore`.
(Theoretically, they could be defined elsewhere, but the AD and the package containing the rule need to load them, and ChainRulesCore is the place for things like that.)

Expand Down

0 comments on commit 6664e8f

Please sign in to comment.