Repository navigation
perf(laplace): reduce matrix memory -- 62.4% less peak memory - #1300
Merged
Merged
Conversation
Release temporary matrices after their last use and reuse owned product buffers for subtraction and diagonal updates. Keep the same matrix products and return values while reducing peak allocated memory by 62.4%. Co-Authored-By: Aiden <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1300 +/- ##
==========================================
+ Coverage 62.15% 62.17% +0.01%
==========================================
Files 206 206
Lines 21955 21962 +7
Branches 2564 2564
==========================================
+ Hits 13646 13654 +8
Misses 7682 7682
+ Partials 627 626 -1
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Member
|
Thanks Dex |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
Laplace._compute_B_statisticsfor dense Gaussian process inference.python3 -m pytest(full command below).What & Why
The function kept temporary matrices alive after their last use and allocated new arrays for subtraction.
It now releases those matrices sooner and writes subtraction results into owned product arrays.
The same matrix products and factorization compute all four return values.
The input arrays remain unchanged.
Validation
Peak allocated bytes for individual calls, measured after creating the inputs:
The combined workload produced these statistics across five fixed inputs and three runs:
The memory measurements use tracemalloc, NumPy, SciPy, Python 3.12, and one BLAS thread.
Numerical comparisons check every return value and unchanged inputs with tolerances of 1e-9.
The individual-call table uses the same cases and memory helper; its allocation boundary differs slightly from the combined workload.
Native tests: 3 passed in 0.89s, run from the repository root:
Both
ruff check GPyandruff format --check GPypass.The reference benchmark measures one dense 1,000-observation call:
Why this is safe and easy to maintain
The change adds seven net lines and no branches.
The calculations stay readable, and outputs are unchanged.
Gamma, Student-T, and Poisson tests cover inference and prediction.
AI assistance
This PR was prepared with AI assistance from Aiden. Candidates were tracked with Weco Observe.
Weco share link: https://dashboard.weco.ai/share/KM2wDuSc3Y5aO2RvMU1tl3Mvj6lBFlWO