Repository navigation
Say at the call when a step does not return a pair #993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -269,13 +269,27 @@ end | |
|
|
||
| # == The step and its pullback on scalars == | ||
|
|
||
| # A step returns the pair `(v′, s′)`; any other result is said at the call. | ||
| @inline _step_pair(m, r::Tuple{Any, Any}) = r | ||
| @noinline function _step_pair(m, r) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion Shorten the error message, and say why the method is Why and how to fixThe message is three clauses long: what was returned, what a step must return, and the |
||
| throw( | ||
| ArgumentError( | ||
| "step(::$(nameof(typeof(m))), θ, v, s) returned a $(typeof(r)); " * | ||
| "a step returns the new value and state, (v′, s′), with " * | ||
| "nothing as the state of a stateless modifier" | ||
| ) | ||
| ) | ||
| end | ||
|
|
||
| # A stateless modifier's step gets no state and keeps the one it is given. | ||
| # The choice is a dispatch, so the step is compiled for the modifier's own | ||
| # type on either arm. | ||
| @inline _pure_step(m, θ, v, s) = _pure_step(Val(isstateless(m)), m, θ, v, s) | ||
| @inline _pure_step(::Val{false}, m, θ, v, s) = @inline step(m, θ, v, s) | ||
| @inline function _pure_step(::Val{false}, m, θ, v, s) | ||
| return _step_pair(m, @inline step(m, θ, v, s)) | ||
| end | ||
| @inline function _pure_step(::Val{true}, m, θ, v, s) | ||
| v′, _ = @inline step(m, θ, v, nothing) | ||
| v′, _ = _step_pair(m, @inline step(m, θ, v, nothing)) | ||
| return v′, s | ||
| end | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion Reword the comment to say why the check exists, and cover or justify the other
stepcall sites.Why and how to fix
'any other result is said at the call' is vague. Write something like
# A step that returns a bare value would otherwise fail on destructuring with an unrelated error.The check only guards_pure_step._unit_trace_back(src/interface/trace.jl:218) destructuresstepdirectly, and src/adjoints/local.jl:32 callsstepdirectly. Either call_step_pair(m, @inline step(m, θ, v, s))there too, or say in the comment that those paths always follow a checked forward step.