Skip to content

Stop pre-constructing reverse-mode tape blocks, and reuse them after a rewind - #1625

Open
NAThompson wants to merge 1 commit into
developfrom
autodiff-reverse-allocator
Open

NAThompson wants to merge 1 commit into
developfrom
autodiff-reverse-allocator

Conversation

@NAThompson

Copy link
Copy Markdown
Collaborator

Blocks are raw storage now, so a second-order tape adds no leaves to the first-order tape,
and a rewound tape refills its blocks instead of allocating new ones. Documents that rvar copies share a node.

Closes #1624

Rewinding now destroys the discarded elements, so the blocks no longer have to do it.

develop this PR
order-1 tape nodes after get_active_tape<double, 2>() 262146 2
order-1 grad of x*x*y + sin(y) after that 722 µs 0.15 µs
Rosenbrock n = 1000 gradient, order-2 tape created first 812 µs 82 µs
RSS after 200 rewind cycles of 100k nodes 1020 MB and growing 13.9 MB, flat

Apple M-series, clang -O2; the reproducers are in #1624. The reverse-mode and gradient-optimizer tests pass, also under ASan/UBSan.

@demroz, this changes your allocator; would you take a look?

🤖 Generated with Claude Code

…a rewind

Blocks are raw storage now, so a second-order tape adds no leaves to the first-order tape,
and a rewound tape refills its blocks instead of allocating new ones. Documents that rvar copies share a node.

Closes #1624

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NAThompson
NAThompson force-pushed the autodiff-reverse-allocator branch from 0ab9b02 to 6cf5581 Compare November 3, 2026 04:30
@demroz

demroz commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

thanks, i'll take a look at this tomorrow

This branch has not been deployed

No deployments
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.

Reverse-mode autodiff: order-2 tape slows order-1 gradients, rewound tapes keep allocating blocks, rvar copies silently share a node

2 participants