Skip to content

Improve L-BFGS - #646

Open
amontoison wants to merge 1 commit into
masterfrom
improve_lbfgs
Open

Improve L-BFGS#646
amontoison wants to merge 1 commit 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.87%. Comparing base (e5f8cee) to head (fa5011c).
⚠️ Report is 9 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #646      +/-   ##
==========================================
+ Coverage   87.93%   88.87%   +0.94%     
==========================================
  Files          55       55              
  Lines        5071     5015      -56     
==========================================
- Hits         4459     4457       -2     
+ Misses        612      558      -54     

☔ 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