Skip to content

Keep config tapes idle when recording or differentiation throws - #339

Open
devmotion wants to merge 1 commit into
masterfrom
config-tape-exceptions
Open

devmotion wants to merge 1 commit into
masterfrom
config-tape-exceptions

Conversation

@devmotion

Copy link
Copy Markdown
Member

Follow-up to #338. If f threw while a config tape was recording, the tape stayed recording with partial instructions: later calls with the config appended to them (wrong derivatives) and a deepcopy of the config gave zero gradients again (#337). If the reverse pass threw, e.g. in a custom @grad pullback, the tape stayed finished and the config could not be used anymore.

  • record_finished! replaces reopen!: it reopens an idle tape, records and finishes it, and makes the tape idle again if recording throws. Tapes holding a recording are still left alone.
  • gradient, gradient!, jacobian and jacobian! make the config tape idle in a finally; HessianTape does the same for its intermediate gradient tape.
  • Adds tests for configs (and their copies) after exceptions, and for the in-place Jacobian with tuple inputs (previously untested).

🤖 Generated with Claude Code

If `f` threw while a config tape was recording, the tape stayed recording with
stale nodes: later calls appended to them and a `deepcopy` of the config gave
zero gradients again (#337). If the reverse pass threw, the tape stayed
finished and the config could not record anymore.

`record_finished!` reopens an idle tape, records and finishes it, and makes it
idle again if recording throws; `gradient` and `jacobian` make the tape idle in
a `finally`. Tapes that hold a recording are still left alone. Also adds a test
for the in-place Jacobian with tuple inputs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.30%. Comparing base (bf30545) to head (ed4fbc6).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #339      +/-   ##
==========================================
+ Coverage   94.77%   95.30%   +0.53%     
==========================================
  Files          19       19              
  Lines        1721     1724       +3     
==========================================
+ Hits         1631     1643      +12     
+ Misses         90       81       -9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant