Skip to content

[WIP] values_version cache coherence for Jacobian/Hessian value caches - #113

Open
dance858 wants to merge 1 commit into
mainfrom
values-version
Open

[WIP] values_version cache coherence for Jacobian/Hessian value caches#113
dance858 wants to merge 1 commit into
mainfrom
values-version

Conversation

@dance858

Copy link
Copy Markdown
Collaborator

Claude:
Replace the caller-must-refresh temporal contracts and the per-atom jacobian_csc_filled flags with a monotone values_version counter on matrix: writers bump, consumers refresh iff their recorded version differs. Staleness becomes impossible by construction and shared-operand double-refreshes dedupe for free.

  • eval_jacobian/eval_wsum_hess free-function wrappers run the atom impl (slots renamed *_impl) and bump the output's version; the jacobian wrapper skips the bump for an affine node already evaluated this parameter epoch, preserving today's refresh counts.
  • sparse_matrix csc_cache and stacked_pd csr_cache are version-guarded (the latter skips its per-call block memcpy in to_csr).
  • spd vtable fill adapters and the raw hess_term2 write sites bump their outputs so version-guarded reads stay fresh.
  • expr_set_needs_refresh gains a set_needs_refresh_children hook so the parameter-refresh walk reaches hstack's args[] children; without it a parameter-dependent affine child under hstack/vstack served stale spd Jacobian values after a parameter update (also fixes the pre-existing stale-CSC-mirror bug for args[] children on main).
  • new tests lock the semantics: bump-per-eval, affine bump-skip and re-arm, CSC mirror dedup, spd to_csr freshness, spd hess-term staleness regression, and the hstack parameter-refresh regression.

Replace the caller-must-refresh temporal contracts and the per-atom
jacobian_csc_filled flags with a monotone values_version counter on
matrix: writers bump, consumers refresh iff their recorded version
differs. Staleness becomes impossible by construction and shared-operand
double-refreshes dedupe for free.

- eval_jacobian/eval_wsum_hess free-function wrappers run the atom impl
  (slots renamed *_impl) and bump the output's version; the jacobian
  wrapper skips the bump for an affine node already evaluated this
  parameter epoch, preserving today's refresh counts.
- sparse_matrix csc_cache and stacked_pd csr_cache are version-guarded
  (the latter skips its per-call block memcpy in to_csr).
- spd vtable fill adapters and the raw hess_term2 write sites bump their
  outputs so version-guarded reads stay fresh.
- expr_set_needs_refresh gains a set_needs_refresh_children hook so the
  parameter-refresh walk reaches hstack's args[] children; without it a
  parameter-dependent affine child under hstack/vstack served stale spd
  Jacobian values after a parameter update (also fixes the pre-existing
  stale-CSC-mirror bug for args[] children on main).
- new tests lock the semantics: bump-per-eval, affine bump-skip and
  re-arm, CSC mirror dedup, spd to_csr freshness, spd hess-term
  staleness regression, and the hstack parameter-refresh regression.

Co-Authored-By: Claude Fable 5 <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