Repository navigation
Conversation
BFGSUpdate_HInv::update formed (I - rho s y') H (I - rho y s') + rho s s' with two n x n matrix products. Expanded with u = H y it is the rank-two update H + (c s - rho u) s' - rho s u', c = rho^2 y'u + rho.
Before each update except at a reset, H is multiplied by tau = s'y / y'Hy when tau > 1 (Oren-Luenberger sizing restricted to enlarging H). Without it H kept the scale of the curvature at the last reset: started where the curvature is large, it underestimated the inverse curvature in the directions not explored since, and the relative gradient test stopped runs far from the optimum.
jachymb
marked this pull request as draft
October 18, 2026 09:14
Contributor
Jenkins Console Log Machine informationDistributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focal CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian Address sizes: 52 bits physical, 57 bits virtual CPU(s): 192 On-line CPU(s) list: 0-191 Thread(s) per core: 2 Core(s) per socket: 48 Socket(s): 2 NUMA node(s): 2 Vendor ID: AuthenticAMD CPU family: 25 Model: 17 Model name: AMD EPYC 9474F 48-Core Processor Stepping: 1 Frequency boost: enabled CPU MHz: 1494.912 CPU max MHz: 4114.4229 CPU min MHz: 1500.0000 BogoMIPS: 7189.39 Virtualization: AMD-V L1d cache: 3 MiB L1i cache: 3 MiB L2 cache: 96 MiB L3 cache: 512 MiB NUMA node0 CPU(s): 0-47,96-143 NUMA node1 CPU(s): 48-95,144-191 Vulnerability Gather data sampling: Not affected Vulnerability Indirect target selection: Not affected Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Not affected Vulnerability Old microcode: Not affected Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Not affected Vulnerability Spec rstack overflow: Mitigation; Safe RET Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; STIBP always-on; PBRSB-eIBRS Not affected; BHI Not affected Vulnerability Srbds: Not affected Vulnerability Tsa: Mitigation; Clear CPU buffers Vulnerability Tsx async abort: Not affected Vulnerability Vmscape: Mitigation; IBPB before exit to userspace Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good amd_lbr_v2 nopl xtopology nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba perfmon_v2 ibrs ibpb stibp ibrs_enhanced vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local user_shstk avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif x2avic v_spec_ctrl vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid overflow_recov succor smca fsrm flush_l1d debug_swap G++: g++ (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Clang: clang version 10.0.0-4ubuntu1 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin |
3 tasks done
Member
|
Looks good. Couple (Claude assisted) comments
|
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.
Depends on the PR #3443
AI use disclosure: This was developed with the help of Claude Code (Opus 5.5, model ID claude-opus-5-5).
Submission Checklist
./runTests.py src/test/unitmake cpplintSummary
Dense BFGS ($H = (s^\top y / y^\top y) I$ at a reset and then only applies BFGS updates. In the directions that no step has explored since, $H$ keeps that initial scale. Started where the curvature is large, it underestimates the inverse curvature there by orders of magnitude: the steps in those directions are far too short, and the relative gradient test $g^\top H g / \max(|f|, 1)$ , which uses $H$ , can stop the run far from the optimum. For $f(x) = \sum_{i=1}^5 (e^{i x_i} - i x_i)$ from $x_i = 5$ , develop stops at $f - f^* = 7.6 \cdot 10^3$ with CmdStan's default tolerances.
algorithm=bfgs,BFGSUpdate_HInv) sets its inverse Hessian estimate toBefore each update except at a reset,$H$ is now multiplied by
Oren–Luenberger sizing restricted to enlarging$H$ (in the spirit of Al-Baali, Comput. Optim. Appl. 9 (1998) 191–203). Enlarging all of $H$ can overestimate the inverse curvature along earlier steps; a later pair along such a direction has $y^\top H y > s^\top y$ , is not sized, and the update corrects $H$ there.
Depends on the PR #3443, which rewrites$u = H y$ of that form: with $y^\top u$ in place of $y^\top H y$ , both $H$ and $u$ are multiplied by $\tau$ , and $y^\top u = s^\top y$ is used in $c$ .
updateas a rank-two update; until that is merged, the diff here also shows its commit, and only the last commit belongs to this PR. The sizing comes afterIntended Effect
Dense BFGS reaches the optimum where develop stops early or crawls after a start in a region of large curvature. Against develop,$10^4$ .
algorithm=bfgswith CmdStan's defaults on 20 model configurations (GLMs, a hierarchical logistic regression, embedded-Laplace GLMMs and GPs; 30–50 seeds each, 900 runs): 795 instead of 651 runs end at the best log density found, with 0.82 times the gradient evaluations (geometric mean over the configurations; 0.38 on a linear regression, 0.44 on Poisson regressions). On 9 standard test functions with 40 starts each, the evaluations fall on 7 (Beale 541 → 117, Wood 61 → 46), and all 40 runs instead of 32–34 reach the optimum on the extended Rosenbrock and a 30-dimensional quadratic with condition numberHow to Verify
New tests, both failing on develop:
OptimizationBfgsUpdate.BFGSUpdate_HInv_enlarges_small_estimate(bfgs_update_test.cpp): after a reset on curvatureOptimizationBfgsMinimizerExpSum.dense_bfgs_large_initial_curvature(bfgs_minimizer_test.cpp): the example above withtol_rel_grad= 1e7; it reachesChanged expectations, because dense BFGS takes a different path:
OptimizationBfgsMinimizer.minimize(bfgs_minimizer_test.cpp) stops on the absolute change ofServicesOptimize.rosenbrock(services/optimize/bfgs_test.cpp, Rosenbrock from 0) writes 22 iterates instead of 20, calls the interrupt 21 times instead of 19, and ends at (1.0000112, 1.0000218) instead of (1, 1). The L-BFGS version of the same test ends at (0.99998, 0.99997) on develop.Existing tests that reach the changed code pass otherwise unchanged:
bfgs_update_test.cpp,bfgs_test.cpp,bfgs_exponential_boundary_test.cpp,services/optimize/bfgs_jacobian_test.cpp.Side Effects
Measured with an in-process A/B harness, this branch including the rank-two commit against develop; I can share the harness. At the defaults the rank-two commit alone leaves every run unchanged. Dense BFGS iterates change; line-search failures: 106 of 900 on both at the defaults, 296 → 299 with
tol_rel_obj = tol_rel_grad = 1(up on the embedded-Laplace, Poisson, categorical and hierarchical logistic models, down on ordered logistic, logistic and negative binomial regression). Evaluations rise by more than 5% here:tol_rel_obj = tol_rel_grad = 1: four embedded-Laplace modelsL-BFGS is not affected.
Documentation
Doc comment of
BFGSUpdate_HInv::update.Copyright and Licensing
Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company):
Jáchym Barvínek jachymb@gmail.com
By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses: