Skip to content

Refactoring rvs mode: deprecate BBCode. #1152

Draft
yebai wants to merge 38 commits intomainfrom
refactoring-rvs-mode
Draft

Refactoring rvs mode: deprecate BBCode. #1152
yebai wants to merge 38 commits intomainfrom
refactoring-rvs-mode

Conversation

@yebai
Copy link
Copy Markdown
Member

@yebai yebai commented Apr 20, 2026

Deprecates BBCode in favour of Julia’s native IRCode plus a small local helper.

This needs to be split into smaller PRs for a comfortable review.

Do not review, work in progress.

CI Summary — GitHub Actions

Documentation Preview

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

Performance

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 │ 190.0 ns │     1.58 │        1.53 │   0.689 │        3.11 │   5.91 │
│             _sum_1000 │ 972.0 ns │     6.82 │        1.01 │  4570.0 │        36.7 │   1.06 │
│          sum_sin_1000 │  7.09 μs │     3.39 │        1.35 │    1.52 │        11.0 │   1.79 │
│         _sum_sin_1000 │  6.32 μs │     3.39 │        1.79 │   259.0 │        12.6 │   2.08 │
│              kron_sum │ 206.0 μs │     12.6 │        3.22 │    12.8 │       348.0 │   18.9 │
│         kron_view_sum │ 293.0 μs │     11.2 │        5.02 │    14.2 │       319.0 │   12.3 │
│ naive_map_sin_cos_exp │  2.42 μs │     3.06 │        1.48 │ missing │        7.32 │   2.07 │
│       map_sin_cos_exp │   2.4 μs │     3.55 │        1.61 │    1.44 │         6.6 │   2.55 │
│ broadcast_sin_cos_exp │  2.42 μs │     3.12 │        1.58 │    3.81 │        1.41 │   2.06 │
│            simple_mlp │ 391.0 μs │     4.66 │        2.55 │    2.16 │        8.28 │   2.84 │
│                gp_lml │ 397.0 μs │     5.72 │        1.73 │    3.02 │     missing │   2.91 │
│    large_single_block │ 411.0 ns │     5.29 │        2.05 │  5350.0 │        33.1 │    2.1 │
└───────────────────────┴──────────┴──────────┴─────────────┴─────────┴─────────────┴────────┘

yebai and others added 30 commits April 3, 2026 14:38
# Conflicts:
#	.claude/skills/ir-inspect/SKILL.md
After extracting `_plan_call_ad`, `arg_types` (and the first `args` that
fed it) were left in `make_ad_stmts!` but never read — the logic moved
inside the helper. Remove both dead lines and their comment.

Also correct the file-level roadmap comment: the actual section order in
the file is 4 → 5(deferred wrappers) → 6(rule derivation) → 7(fwd/pullback
assembly), not the 4 → 5 → 6 → 7 that was documented.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
yebai added 2 commits April 20, 2026 19:09
# Conflicts:
#	docs/src/developer_documentation/ir_representation.md
#	src/interpreter/bbcode.jl
@yebai yebai changed the title Refactoring rvs mode: deprecate BBCoce. Refactoring rvs mode: deprecate BBCode. Apr 23, 2026
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

❌ Patch coverage is 94.91870% with 25 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/interpreter/reverse_mode.jl 95.03% 23 Missing ⚠️
src/interpreter/ir_utils.jl 88.88% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

yebai and others added 5 commits May 1, 2026 15:14
# Conflicts:
#	src/interpreter/reverse_mode.jl
Type names should be nouns; CallADPlan read as a verb-y bag-of-values.
RuleSelection more honestly names what _plan_call_ad (now _select_rule)
returns -- the resolved rule plus the metadata produced during selection.
Annotate the fields whose types are fixed (args::Tuple, T_pb!!::Type,
output_type::Type); rule_ref stays untyped because it is genuinely
Union{ID, <singleton rule>}.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Five scrutinise findings:
1. Move section-divider comments above docstrings so they no longer break
   docstring association for create_comms_insts!, lower_cfg_blocks_to_ir,
   and pullback_ir.
2. Add the missing block_comms argument to forwards_pass_ir and pullback_ir
   docstrings.
3. Drop redundant pass-through overloads: _ssa_to_ids on QuoteNode/GotoNode
   and _cfg_to_ssas on QuoteNode -- the fallback already handles them.
4. Inline _flatten_cfg_insts and _primal_stmt_metadata into generate_ir;
   each was only used once, and the wrapping obscured what the call site
   was actually computing.
5. Move the unique cases of the ReverseModeCFG.lower_cfg_blocks testset
   (sort_cfg=false, _insert_before_terminator!, _cfg_phi_nodes,
   phi-edge cleanup on dead predecessors) into cfg_builder.jl, and drop
   the testset's basic round-trip case which duplicated cfg_builder.jl
   coverage.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Earlier rewrites converted seven jldoctest blocks to julia-repl, dropping
test coverage on the IR-introduction examples. Convert them back and
restore the bar / my_factorial labels so chained blocks share state.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The previous commit restored jldoctest markers but kept the rewritten
expected outputs, which were missing the `intrinsic ` prefix and the
`=    invoke` spacing that 1.12 prints. Add them back so the doctests
pass under the docs CI (which runs on 1.12). Also fix the
`Compiler.NewInstruction` / `Compiler.NoCallInfo` show form.

Verified with `julia --project=docs docs/make.jl` -- zero doctest
failures.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant