Skip to content

feat: deferred leaf tangent injection for HVP#7

Merged
shinaoka merged 2 commits intomainfrom
deferred-hvp-tangents-v2
Mar 28, 2026
Merged

feat: deferred leaf tangent injection for HVP#7
shinaoka merged 2 commits intomainfrom
deferred-hvp-tangents-v2

Conversation

@shinaoka
Copy link
Copy Markdown
Member

Summary

Closes #6

  • chainrules-core: Add forward_tangents() method and input_tangents closure parameter to pullback_with_tangents() on ReverseRule trait (chainrules-rs branch)
  • tidu: Two-phase hvp_from algorithm — forward tangent propagation then reverse pass with tangent provider
  • Tape::hvp() now takes leaf_tangents: &HashMap<NodeId, V::Tangent> instead of relying on leaf_with_tangent()
  • Rules become stateless w.r.t. tangents (no more saved_dx fields)
  • Edge-case tests for empty and partial tangent maps

Breaking Changes

  • Tape::hvp signature changed: new leaf_tangents parameter
  • ReverseRule::pullback_with_tangents gains input_tangents closure parameter
  • Requires chainrules-rs deferred-hvp-tangents branch

Test plan

  • 62/62 unit tests pass (cargo nextest run --release)
  • 24/24 doctests pass (cargo test --doc --release)
  • clippy clean (only pre-existing type_complexity warning)
  • Edge-case: empty tangent map gives zero HVP
  • Edge-case: partial tangent map (tangent on one leaf, not another)

🤖 Generated with Claude Code

shinaoka and others added 2 commits March 28, 2026 05:47
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace the "tangents baked into rules at construction time" HVP workflow
with a fully deferred model. Leaf tangent directions v are now passed as
a HashMap<NodeId, V::Tangent> to Tape::hvp() at call time.

Changes:
- chainrules-core: add forward_tangents() method and input_tangents
  closure param to pullback_with_tangents() on ReverseRule trait
- tidu: two-phase hvp_from algorithm (forward tangent propagation +
  reverse pass with tangent provider)
- Tape::hvp() takes leaf_tangents HashMap instead of relying on
  leaf_with_tangent()
- Add edge-case tests for empty/partial tangent maps

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@shinaoka shinaoka enabled auto-merge (squash) March 28, 2026 00:52
@shinaoka shinaoka merged commit cf576e7 into main Mar 28, 2026
5 checks passed
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.

Support deferred leaf tangent injection for HVP

1 participant