Skip to content

Remove const M in macros: @zero_derivative and @from_chainrules#694

Closed
yebai wants to merge 5 commits intomainfrom
yebai-patch-1
Closed

Remove const M in macros: @zero_derivative and @from_chainrules#694
yebai wants to merge 5 commits intomainfrom
yebai-patch-1

Conversation

@yebai
Copy link
Member

@yebai yebai commented Aug 13, 2025

Fix #692 for @penelopeysm

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>
Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>
@yebai yebai changed the title Remove const M in @from_chainrules macro Remove const M in @zero_derivative macro Aug 13, 2025
@github-actions
Copy link
Contributor

Mooncake.jl documentation for PR #694 is available at:
https://chalk-lab.github.io/Mooncake.jl/previews/PR694/

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>
@yebai yebai changed the title Remove const M in @zero_derivative macro Remove const M in macros: @zero_derivative and @from_chainrules Aug 13, 2025
yebai and others added 2 commits August 13, 2025 17:00
Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Aug 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions
Copy link
Contributor

Performance Ratio:
Ratio of time to compute gradient and time to compute function.
Warning: results are very approximate! See here for more context.

┌────────────────────────────┬──────────┬──────────┬─────────────┬─────────┬─────────────┬─────────┐
│                      Label │   Primal │ Mooncake │ MooncakeFwd │  Zygote │ ReverseDiff │  Enzyme │
│                     String │   String │   String │      String │  String │      String │  String │
├────────────────────────────┼──────────┼──────────┼─────────────┼─────────┼─────────────┼─────────┤
│                   sum_1000 │ 100.0 ns │      1.8 │         1.8 │     1.1 │         5.5 │    8.21 │
│                  _sum_1000 │ 941.0 ns │     6.75 │        1.01 │  1410.0 │        34.0 │    1.09 │
│               sum_sin_1000 │  6.56 μs │     2.17 │        1.37 │    1.69 │        10.9 │    2.21 │
│              _sum_sin_1000 │  5.17 μs │     2.66 │        2.22 │   270.0 │        13.4 │     2.5 │
│                   kron_sum │ 293.0 μs │     61.4 │        3.22 │    5.96 │       230.0 │    9.73 │
│              kron_view_sum │ 355.0 μs │     39.4 │        3.44 │    10.5 │       230.0 │    6.32 │
│      naive_map_sin_cos_exp │   2.1 μs │     2.25 │        1.41 │ missing │        7.34 │    2.34 │
│            map_sin_cos_exp │  2.13 μs │     2.43 │        1.47 │    1.51 │        6.08 │     2.9 │
│      broadcast_sin_cos_exp │  2.26 μs │     2.29 │        1.38 │    2.36 │        1.46 │    2.27 │
│                 simple_mlp │ 199.0 μs │     6.36 │        2.95 │    1.72 │        10.7 │    3.45 │
│                     gp_lml │ 248.0 μs │     8.92 │        2.15 │    3.63 │     missing │    5.64 │
│ turing_broadcast_benchmark │  1.96 ms │     3.88 │        3.03 │ missing │        25.8 │ missing │
│         large_single_block │ 381.0 ns │     4.55 │        2.02 │  4500.0 │        31.9 │    2.23 │
└────────────────────────────┴──────────┴──────────┴─────────────┴─────────┴─────────────┴─────────┘

Comment on lines 282 to +286
# which does not escape the mode argument. This will work even if the names `Mooncake`
# or `Mooncake.Mode` are not available in the scope which calls this macro.
is_primitive_ex = quote
const M = $mode
function Mooncake.is_primitive(
::Type{$(esc(ctx))}, ::Type{<:M}, ::Type{<:$(esc(sig))}
::Type{$(esc(ctx))}, ::Type{<:($(esc(mode)))}, ::Type{<:($(esc(sig)))}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The comment above says to not escape mode, so I wonder if $(mode) would be better?

Copy link
Member Author

Choose a reason for hiding this comment

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

I won't have time for this in the next few days. Please feel free to take over and merge it.

@yebai yebai mentioned this pull request Aug 14, 2025
@yebai
Copy link
Member Author

yebai commented Aug 14, 2025

Replaced by #696

@yebai yebai closed this Aug 14, 2025
@yebai yebai deleted the yebai-patch-1 branch August 14, 2025 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unsupported const declaration in @from_rrule output

2 participants