Skip to content

Use R-only QR for larger static backward messages - #201

Merged
THargreaves merged 1 commit into
mainfrom
th/backward-qr-r-only
Nov 9, 2026
Merged

THargreaves merged 1 commit into
mainfrom
th/backward-qr-r-only

Conversation

@THargreaves

Copy link
Copy Markdown
Collaborator

Square-root backward messages (SqrtBackwardInformationPredictor, used by default for CSMC ancestor sampling and backward simulation) only need the triangular factor of each QR. For static Float32/Float64 matrices beyond the unrolled-QR size, qr(A) falls back to LAPACK, materialises Q, and contends for BLAS workspace when ancestor scoring runs under ThreadedExecution.

This adds _backward_qr_upper, which runs Julia's generic in-place Householder QR on MMatrix storage for those matrices and returns only R. Tiny static matrices keep the unrolled static QR; dense arrays and non-BLAS scalar types (including AD numbers) keep qr's own dispatch. Both residual compression and the identity-plus-root factor use the helper. No Gram matrix is formed and no covariance repair is added.

Measured on a complete CSMC-AS sweep (N=1024, T=20, Float32, state dimension 16, 4 observations):

Before After
Serial 286.7 ms 195.1 ms
Four threads, blocksize 32 616.9 ms 128.5 ms
Serial allocation per sweep 370.8 MB 215.3 MB

Dimension-2 serial timing is unchanged (it keeps the same kernel).

The new test covers Float32/Float64; tall, square and wide static matrices; rank-deficient and badly scaled columns; static result types; dimension-16 normalised suffix likelihoods against a forward Kalman filter; and the ForwardDiff fallback.

Square-root backward messages only need the triangular factor. For static
Float32/Float64 matrices beyond the unrolled size, run Julia's generic in-place
Householder QR on MMatrix storage instead of qr(A), which falls back to LAPACK,
materialises Q and contends for BLAS workspace under threaded ancestor scoring.
Tiny static matrices keep the unrolled QR; other array and scalar types keep
qr's own dispatch, including AD numbers.
@THargreaves
THargreaves merged commit c4194c8 into main Nov 9, 2026
16 checks passed
@THargreaves
THargreaves deleted the th/backward-qr-r-only branch November 9, 2026 15:52
@codecov

codecov Bot commented Nov 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.92%. Comparing base (e7dd125) to head (10d12ab).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #201      +/-   ##
==========================================
+ Coverage   71.89%   71.92%   +0.03%     
==========================================
  Files         104      104              
  Lines        4127     4136       +9     
==========================================
+ Hits         2967     2975       +8     
- Misses       1160     1161       +1     
Flag Coverage Δ
GeneralisedFilters 72.35% <100.00%> (+0.03%) ⬆️
SSMProblems 56.63% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

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