Skip to content

Commit

Permalink
Performance Tweaks (#297)
Browse files Browse the repository at this point in the history
* Ensure LazyDerivedRule calls inline properly

* Tidy up formatting

* Bump MistyClosures major version
  • Loading branch information
willtebbutt authored Oct 21, 2024
1 parent faa6397 commit 0427a04
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Mooncake"
uuid = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
authors = ["Will Tebbutt, Hong Ge, and contributors"]
version = "0.4.14"
version = "0.4.15"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down Expand Up @@ -55,7 +55,7 @@ Graphs = "1"
JET = "0.9"
LogDensityProblemsAD = "1"
LuxLib = "1.2 - 1.3.3"
MistyClosures = "1.0.3"
MistyClosures = "2"
NNlib = "0.9"
PDMats = "0.11"
Setfield = "1"
Expand Down
47 changes: 24 additions & 23 deletions src/interpreter/s2s_reverse_mode_ad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1480,29 +1480,30 @@ end

_copy(x::P) where {P<:LazyDerivedRule} = P(x.mi, x.debug_mode)

function (rule::LazyDerivedRule{sig, Trule})(args::Vararg{Any, N}) where {N, sig, Trule}
if !isdefined(rule, :rule)
interp = get_interpreter()
derived_rule = build_rrule(interp, rule.mi; debug_mode=rule.debug_mode)
if derived_rule isa Trule
rule.rule = derived_rule
else
@warn "Unable to put rule in rule field. Rule should error."
println("MethodInstance is")
display(rule.mi)
println()
println("with signature")
display(sig)
println()
println("derived_rule is of type")
display(typeof(derived_rule))
println()
println("Expected type is")
display(Trule)
println()
derived_rule(args...)
error("Rule with bad type ran without error.")
end
@noinline function _build_rule!(rule::LazyDerivedRule{sig, Trule}) where {sig, Trule}
derived_rule = build_rrule(get_interpreter(), rule.mi; debug_mode=rule.debug_mode)
if derived_rule isa Trule
rule.rule = derived_rule
else
@warn "Unable to put rule in rule field. Rule should error."
println("MethodInstance is")
display(rule.mi)
println()
println("with signature")
display(sig)
println()
println("derived_rule is of type")
display(typeof(derived_rule))
println()
println("Expected type is")
display(Trule)
println()
derived_rule(args...)
error("Rule with bad type ran without error.")
end
end

@inline function (rule::LazyDerivedRule)(args::Vararg{Any, N}) where {N}
isdefined(rule, :rule) || _build_rule!(rule)
return rule.rule(args...)
end

2 comments on commit 0427a04

@willtebbutt
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/117731

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.15 -m "<description of version>" 0427a044c52845a3e278826fa3790be715e00b93
git push origin v0.4.15

Please sign in to comment.