Skip to content
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

Improve safe mode options #149

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Tapir"
uuid = "07d77754-e150-4737-8c94-cd238a1fb45b"
authors = ["Will Tebbutt, Hong Ge, and contributors"]
version = "0.2.9"
version = "0.2.10"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
15 changes: 12 additions & 3 deletions src/interpreter/s2s_reverse_mode_ad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -722,11 +722,13 @@ function rule_type(interp::TapirInterpreter{C}, ::Type{sig}) where {C, sig}
end

"""
build_rrule(args...)
build_rrule(args...; safety_on=false)

Helper method. Only uses static information from `args`.
"""
build_rrule(args...) = build_rrule(PInterp(), _typeof(TestUtils.__get_primals(args)))
function build_rrule(args...; safety_on=false)
return build_rrule(PInterp(), _typeof(TestUtils.__get_primals(args)); safety_on)
end

"""
build_rrule(interp::PInterp{C}, sig::Type{<:Tuple}; safety_on=false) where {C}
Expand All @@ -736,7 +738,14 @@ for `rrule!!` for more info.

If `safety_on` is `true`, then all calls to rules are replaced with calls to `SafeRRule`s.
"""
function build_rrule(interp::PInterp{C}, sig::Type{<:Tuple}; safety_on=false) where {C}
function build_rrule(
interp::PInterp{C}, sig::Type{<:Tuple}; safety_on=false, silence_safety_messages=true
) where {C}

# If we're compiling in safe mode, let the user know by default.
if !silence_safety_messages
@info "Compiling rule for $sig in safe mode. Disable for best performance."
end

# Reset id count. This ensures that the IDs generated are the same each time this
# function runs.
Expand Down
Loading