Skip to content

Improve L-BFGS - #646

Merged
frapac merged 2 commits into
masterfrom
improve_lbfgs
Sep 21, 2026
Merged

frapac merged 2 commits into
masterfrom
improve_lbfgs

Conversation

@amontoison

@amontoison amontoison commented Aug 30, 2026 •

Copy link
Copy Markdown
Member

I implemented it a long time ago but never opened the PR.
We can dynamically resize the arrays for L-BFGS.
It reduces the pressure on the garbage collector, especially on GPU.

@github-actions

Copy link
Copy Markdown
Contributor

Your PR requires formatting changes to meet the project's style guidelines.
Please consider running Runic (git runic master) to apply these changes.

Click here to view the suggested changes.
diff --git a/src/quasi_newton.jl b/src/quasi_newton.jl
index 06a8a05..423b1ee 100644
--- a/src/quasi_newton.jl
+++ b/src/quasi_newton.jl
@@ -280,14 +280,14 @@ Base.size(qn::CompactLBFGS) = (size(qn.Sk, 1), qn.current_mem)
 
 function _resize!(qn::CompactLBFGS{T, VT, MT}) where {T, VT, MT}
     n, k = size(qn)
-    qn.Lk   = fill!(reshape(resize!(vec(qn.Lk), k*k), k, k), zero(T))
-    qn.Mk   = fill!(reshape(resize!(vec(qn.Mk), k*k), k, k), zero(T))
-    qn.Tk   = fill!(reshape(resize!(vec(qn.Tk), 4*k*k), 2*k, 2*k), zero(T))
-    qn.DkLk = fill!(reshape(resize!(vec(qn.DkLk), k*k), k, k), zero(T))
-    qn.U    = fill!(reshape(resize!(vec(qn.U), n*k), n, k), zero(T))
-    qn.V    = fill!(reshape(resize!(vec(qn.V), n*k), n, k), zero(T))
-    qn._w1  = fill!(resize!(qn._w1, k), zero(T))
-    qn._w2  = fill!(resize!(qn._w2, 2*k), zero(T))
+    qn.Lk = fill!(reshape(resize!(vec(qn.Lk), k * k), k, k), zero(T))
+    qn.Mk = fill!(reshape(resize!(vec(qn.Mk), k * k), k, k), zero(T))
+    qn.Tk = fill!(reshape(resize!(vec(qn.Tk), 4 * k * k), 2 * k, 2 * k), zero(T))
+    qn.DkLk = fill!(reshape(resize!(vec(qn.DkLk), k * k), k, k), zero(T))
+    qn.U = fill!(reshape(resize!(vec(qn.U), n * k), n, k), zero(T))
+    qn.V = fill!(reshape(resize!(vec(qn.V), n * k), n, k), zero(T))
+    qn._w1 = fill!(resize!(qn._w1, k), zero(T))
+    qn._w2 = fill!(resize!(qn._w2, 2 * k), zero(T))
     return
 end
 

@codecov

codecov Bot commented Aug 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.81%. Comparing base (f5ccf8b) to head (a7a5773).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #646      +/-   ##
==========================================
- Coverage   88.83%   88.81%   -0.03%     
==========================================
  Files          56       56              
  Lines        5025     5014      -11     
==========================================
- Hits         4464     4453      -11     
  Misses        561      561              

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

@frapac
frapac merged commit 2472de5 into master Sep 21, 2026
10 of 11 checks passed
@frapac
frapac deleted the improve_lbfgs branch September 21, 2026 14:51
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