Skip to content

Commit fdca95c

Browse files
oxinaboxwilltebbuttnickrobinson251
authored
Apply suggestions from code review
Co-authored-by: willtebbutt <wt0881@my.bristol.ac.uk> Co-authored-by: Nick Robinson <npr251@gmail.com>
1 parent 3320fba commit fdca95c

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

docs/src/autodiff/operator_overloading.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Operator Overloading
22

3-
The principle interface for using the operator overload generation method is [`on_new_rule`](@ref).
3+
The principal interface for using the operator overload generation method is [`on_new_rule`](@ref).
44
This function allows one to register a hook to be run every time a new rule is defined.
55
The hook receives a signature type-type as input, and generally will use `eval` to define
6-
and overload of AD systems overloaded type.
7-
For example, using the signature type `Tuple{typeof(+), Real, Real}` to define
8-
`+(::DualNumber, ::DualNumber)` as calling the `frule` for `+`.
6+
an overload of an AD system's overloaded type.
7+
For example, using the signature type `Tuple{typeof(+), Real, Real}` to make
8+
`+(::DualNumber, ::DualNumber)` call the `frule` for `+`.
99
A signature type tuple always has the form:
1010
`Tuple{typeof(operation), typeof{pos_arg1}, typeof{pos_arg2...}}`, where `pos_arg1` is the
1111
first positional argument.
12-
One can dispatch on the signature type, to make rules with argument types your AD does not support not call `eval`;
12+
One can dispatch on the signature type to make rules with argument types your AD does not support not call `eval`;
1313
or more simply you can just use conditions for this.
14-
The the hook is automatically triggered whenever a package is loaded.
14+
The hook is automatically triggered whenever a package is loaded.
1515

1616
`refresh_rules`(@ref) is used to manually trigger the hook function on any new rules.
1717
This is useful for example if new rules are define in the REPL, or if a package defining rules is modified.
@@ -45,4 +45,3 @@ $(read(joinpath(@__DIR__,"../../../test/demos/reversediffzero.jl"), String))
4545
```
4646
""")
4747
````
48-

docs/src/autodiff/overview.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
# Using ChainRules in your AutoDiff system
1+
# Using ChainRules in your AD system
22

33
This section is for authors of AD systems.
4-
It assumes a pretty solid understanding of Julia, and of automatic differentiation.
5-
It explains how to make use of ChainRule's rule sets,
4+
It assumes a pretty solid understanding of both Julia and automatic differentiation.
5+
It explains how to make use of ChainRule's "rulesets" ([`frule`](@ref)s, [`rrule`](@ref)s,)
66
to avoid having to code all your own AD primitives / custom sensitives.
77

88
There are 3 main ways to access ChainRules rule sets in your AutoDiff system.
99

1010
1. [Operation Overloading Generation](operator_overloading.html)
11-
- This is primarily intended for operator overloading based AD systems which will generate overloads for primal function based for their overloaded types based on the existance of an `rrule`/`frule`.
11+
- This is primarily intended for operator overloading based AD systems which will generate overloads for primal functions based for their overloaded types based on the existence of an `rrule`/`frule`.
1212
- A source code generation based AD can also use this by overloading their transform generating function directly so as not to recursively generate a transform but to just return the rule.
1313
- This does not play nice with Revise.jl, adding or modifying rules in loaded files will not be reflected until a manual refresh, and deleting rules will not be reflected at all.
1414
2. Source code tranform based on inserting branches that check of `rrule`/`frule` return `nothing`
15-
- if the `rrule`/`frule` returns a rule result then use it, if it return `nothing` then do normal AD path
15+
- If the `rrule`/`frule` returns a rule result then use it, if it returns `nothing` then do normal AD path.
1616
- In theory type inference optimizes these branchs out; in practice it may not.
1717
- This is a fairly simple Cassette overdub (or similar) of all calls, and is suitable for overloading based AD or source code transformation.
1818
3. Source code transform based on `rrule`/`frule` method-table
19-
- Always use `rrule`/`frule` iff and only if use the rules that exist, else generate normal AD path.
19+
- If an applicable `rrule`/`frule` exists in the method table then use it, else generate normal AD path.
2020
- This avoids having branches in your generated code.
21-
- This requires maintaining your own back-edges
21+
- This requires maintaining your own back-edges.
2222
- This is pretty hard-code even by the standard of source code tranformations

src/ruleset_loading.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ _hook_list(::typeof(frule)) = NEW_FRULE_HOOKS
1616
Register a `hook` function to run when new rules are defined.
1717
The hook receives a signature type-type as input, and generally will use `eval` to define
1818
and overload of AD systems overloaded type.
19-
For example, using the signature type `Tuple{typeof(+), Real, Real}` to define
20-
`+(::DualNumber, ::DualNumber)` as calling the `frule` for `+`.
19+
For example, using the signature type `Tuple{typeof(+), Real, Real}` to make
20+
`+(::DualNumber, ::DualNumber)` call the `frule` for `+`.
2121
A signature type tuple always has the form:
2222
`Tuple{typeof(operation), typeof{pos_arg1}, typeof{pos_arg2...}}`, where `pos_arg1` is the
23-
first positional argument
23+
first positional argument.
2424
2525
The hooks are automatically run on new rules whenever a package is loaded.
2626
They can be manually triggered by [`refresh_rules`](@ref).
@@ -74,7 +74,7 @@ last_refresh(::typeof(rrule)) = LAST_REFRESH_RRULE
7474
This triggers all [`on_new_rule`](@ref) hooks to run on any newly defined rules.
7575
It is *automatically* run when ever a package is loaded.
7676
It can also be manually called to run it directly, for example if a rule was defined
77-
in the REPL or with-in the same file as the AD function.
77+
in the REPL or within the same file as the AD function.
7878
"""
7979
refresh_rules() = (refresh_rules(frule); refresh_rules(rrule))
8080
function refresh_rules(rule_kind)

test/demos/reversediffzero.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function define_tracked_overload(sig)
7171
y, y_pullback = rrule(args...; kwargs...)
7272
the_tape = get_tape(tracked_args)
7373
y_tracked = Tracked(y, the_tape) do
74-
# pull this partial back and propagate it to the inputs partial stores
74+
# pull this partial back and propagate it to the input's partial store
7575
_, ārgs = Iterators.peel(y_pullback(ȳ))
7676
accum!.(tracked_args, ārgs)
7777
end

0 commit comments

Comments
 (0)