Repository navigation
Description
The Mooncake gradient of the BVDOutbreakSize occupancy kernel (Recurrence with Depletion and Split) is about 3 times the hand rule, so BVDOutbreakSize keeps its own rule.
What is known
- After Run a grouped modifier's groups in the series step, on the host and on a device #946, at T = 200: forward 1.9 times the hand loop, Mooncake reverse 3.1 times, Enzyme reverse 2.8 times.
- The flows' arithmetic is level with the hand loop; the gap is the buffer, the records, the output copies and BVDOutbreakSize's separate output pass.
- Inside the model's full loss the two are level (0.98 to 1.00), because the loss's own broadcasts cost as much as the kernel.
- The local changes listed in the earlier text gave no gain.
- Closing the gap needs a strata × time buffer (GPU performance: measure buffer layout and kernel overhead on a GPU #512) or a model-specific rule.
Done when
-
bvd_occupancy_kernel's Mooncake gradient is within about 1.3 times the hand rule.
Earlier text
Earlier title: Occupancy (Recurrence + Depletion + Split) gradient is about 3–4× BVD's hand rule
BVDOutbreakSize keeps its own occupancy rule, because the CR spelling is still several times slower.
#860 (closed) has the earlier work and profiles.
Numbers
Kernel only, Mooncake gradient, CR main after #890:
| Steps | CR | BVD hand rule | Ratio |
|---|---|---|---|
| 200 | 24.0 µs | 6.4 µs | 2.7–3.8× |
| 400 | 3.2–4.1× |
Per step that is about 105 ns against 33 ns.
CR's plain forward pass is about 25 ns per step.
Where the time goes
Reverse profile of the Recurrence + Depletion + Split path:
- Count-flow pullbacks: about 49% (Split 24%).
Three count flows cost about 76 ns per step, or 20 ns per step with their parameter writes out of a 65 ns reverse step. - Group bookkeeping: 10%.
- Stage dispatch: 8%.
- Clamp: 7%.
- Row copy: 7% (since cut by Time the occupancy kernels alone, and copy a reverse row by index #890).
Already tried, no gain
- Computing the Split parts once: slower (11 → 18 ns).
- Caching forward partials: saves at most 2.8 ns.
- Stage machinery (
_split_pullback!,_group_back!,_group_pullback): at most about 5% in total. - A fused group step needs a type-level group count, which was ruled out earlier.
What would close it
A design change rather than a local tweak.
For example, a fused pullback for a Depletion with count flows that keeps per-step partials in registers, as the hand rule does.
Done when
The BVD occupancy kernel's Mooncake gradient is within about 1.3× of the hand rule.
Then BVD can drop the rule.
Generated by Claude Code
Activity
seabbs-bot commentedon Dec 1, 2026
Outcome: reproduced on the redesigned branch; not fixed; left open
This one does not wait on anyone else.
It is open because the fix is a design change that was not made here.
Measured on the redesigned branch (#907 at 21fb0bb), Julia 1.13.4, Mooncake 0.5.74, one thread,
benchmark/matrix.jl --tier=realistic --targets="Mooncake reverse", minimum times.This machine is shared and the same arm moved by up to 50% between runs, so each ratio is given for every run made.
bvd_occupancy_kernel(the kernels alone)bvd_occupancy_kernelbvd_occupancy(the model's loss around them)bvd_occupancyDepletion's count flows.What remains
The reverse step of a
Depletionwith count flows: the profile in the issue body (count-flow pullbacks 49%, group bookkeeping 10%, stage dispatch 8%) still describes it.The local changes listed under "Already tried" stay ruled out.
The candidate is one reverse step per group that carries the flows' partials from the forward step, in place of one pullback per flow.
It has to be written for any number of flows from the operator's types, with no group count in the code, and it needs timings steadier than this machine gives to judge a change of tens of nanoseconds a step.
Done when
As in the issue:
bvd_occupancy_kernelwithin about 1.3× of the hand rule.Generated by Claude Code
seabbs-bot commentedon Dec 2, 2026
Outcome: improved, the 1.3× bar is not met; left open
#946 has the change, the evidence and the full tables.
Where the time went
The package's call took 30 ns a step.
Splitflow's pullback divided the cotangents by the pools' total twice, on the chain each step waits on.What #946 changes
Splitpullback multiplies by one reciprocal of the total. Interleaved over six rounds it took 1.3 to 6.4 ns a step off the group pullback in every round.Numbers
bvd_occupancy_kernel, T = 200,benchmark/ab.jl, three interleaved rounds,mainat 4ce03f8 against the branch.The machine was noisy: the A/A band was 12 to 31%.
The forward and Enzyme gains are outside the noise band.
The Mooncake gradient was faster in each round (0.72, 0.84, 0.89) but inside a ±31% band, so the harness calls it within noise.
What remains, and why
The flows' arithmetic is not the gap: the bare group step with its records and its pullback come to about 8 to 9 µs, about 1.3 times the hand kernel and rule.
A profile of the gradient on the branch:
occupancy_outputsand its ruleThe structure the hand rule uses and the generic path does not:
A strata × time buffer would let the output and its cotangent share the buffer's memory and remove two of those arrays and both transposed copies.
That is the core change #512 asks for too; it is not made in #946.
Writing the outputs inside the loop would need a model-specific loop in the package.
Tried and dropped: removing additions of structural zeros from the pullback gave no consistent gain over five interleaved rounds.
For the maintainer
The 1.3× bar needs either the buffer layout change or a model-specific rule.
With neither, about 3× is where the generic path sits, and BVD keeps its rule.
Whether to close this as the cost of generality or keep it for the buffer change is your call.
Generated by Claude Code
[-]Occupancy (Recurrence + Depletion + Split) gradient is about 3–4× BVD's hand rule[/-][+]Occupancy kernel gradient is about 3 times BVDOutbreakSize's hand rule[/+]seabbs-bot commentedon Dec 2, 2026
The occupancy and census work on branch
bvd-parity(#1008) addresses this.Generated by Claude Code