Skip to content

Adopt dense-preserving binary sums and benchmark issue 47 - #181

Merged
dance858 merged 8 commits into
mainfrom
issue-47-binary-dense-sums
Dec 3, 2026
Merged

dance858 merged 8 commits into
mainfrom
issue-47-binary-dense-sums

Conversation

@Transurgeon

@Transurgeon Transurgeon commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Summary

Companion to SparseDifferentiation/sparsediff_linalg#48,
addressing the binary-sum portion of
SparseDifferentiation/sparsediff_linalg#47.

  • Replace caller-preallocated sparse binary sums with the returned matrix in
    add, multiply, matmul, quad_over_lin, elementwise Hessians, and
    quad_form.
  • Update the library submodule to the companion PR head (current library main
    plus the binary dense-sum fix).
  • Add small structural/numerical regressions and a standalone, deterministic
    binary_sum_profile target under PROFILE_ONLY.
  • Document the source-breaking allocator migration and benchmark reproduction.

Four-way/n-way sums and their evaluation order are unchanged.

Dependency / merge order

Review and merge the library PR first. This PR currently pins its published
head commit. If the library PR is squash-merged or rebased, update this submodule
pin to the resulting merged commit before merging this integration.

Validation

Engine and library suites pass in Release, Debug with SP_TRACK_MEMORY, and
ASan+UBSan. New tests check dense intermediate kinds and exact nnz, gradients
and Hessians against numerical differentiation at changed inputs, a sparse
control, and composed matmul, quad_over_lin, and quad_form paths.
Changed C files pass clang-format and whitespace checks.

Performance

Apple M2 arm64, macOS 26.7.3, AppleClang 21.0.0, Release, Accelerate,
VECLIB_MAXIMUM_THREADS=1. Each median uses 21 samples after five warmups.
Baseline: engine 1efa7c26 with library a8ee39ff, using the same profile source
as the patched run (so prior library changes are not counted as this fix).

Gradient timings include root forward and Jacobian evaluation. Hessian timings
include those plus Hessian evaluation. Initialization is separate; legitimate
affine caching remains enabled. Conversions, reference checks, and printing are
outside timed evaluation regions.

Model Gradient before -> after (ms) Hessian before -> after (ms)
sum((Ax)^2) 0.590 -> 0.607 2.735 -> 2.711
sum((Ax-b)^2) 0.716 -> 0.529 128.670 -> 2.575
sum(logistic(Ax-b)) 0.729 -> 0.540 128.715 -> 2.568
sum(sqrt((Ax)^2)) 0.849 -> 0.864 5.394 -> 5.444
sum(sqrt(1+(Ax)^2)) 1.697 -> 1.449 132.975 -> 6.185
sum(sqrt((Ax-b)^2)) 0.982 -> 0.866 258.683 -> 5.427
sum(sqrt(1+(Ax-b)^2)) 1.596 -> 1.422 259.772 -> 6.140
Variable intercept 0.735 -> 0.570 130.142 -> 2.904
Two variable blocks 1.505 -> 1.390 508.650 -> 9.661
Multinomial-logit least squares 24.160 -> 19.760 1338.495 -> 48.090
Incomplete sparse control 0.008 -> 0.008 0.013 -> 0.012

Affine workloads use A = 2000 x 400; the two-block model has 800 variables.
Logit uses m=1000, d=20, K=20. Values and gradient/Hessian sums and norms agree
within 1e-9 absolute/relative tolerance; structural counts agree exactly.
The logit Jacobian and final Hessian are dense, but its intermediate n-way
Hessian sum remains sparse and is deferred.

Reproduce

cmake -S . -B build/profile -DCMAKE_BUILD_TYPE=Release -DPROFILE_ONLY=ON
cmake --build build/profile --target binary_sum_profile
VECLIB_MAXIMUM_THREADS=1 ./build/profile/binary_sum_profile

See README for the baseline setup and OpenBLAS thread setting. The CSV output
also includes initialization times, sample ranges, kinds, nnz, and numerical
summaries. No absolute-time CI assertions are introduced.

Migrate all six binary allocator callers, pin sparsediff_linalg to its dense-sum implementation, and add structural/numerical regressions plus a deterministic before/after profiling target. Leave four-way and n-way sums unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Transurgeon and others added 4 commits December 3, 2026 08:17
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Transurgeon and others added 3 commits December 3, 2026 09:10
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the issue-47 model factory with four small explicit tests, drop
the standalone profiling target and the README section, and pin the
submodule to the merge commit of sparsediff_linalg#48.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@dance858
dance858 merged commit d2ae875 into main Dec 3, 2026
14 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.

2 participants