Repository navigation
Conversation
LSOptions::maxStep0 limits the first trial step of the first iteration and after a Hessian reset to maxStep0 / |g|_inf (default +inf; the L-BFGS and BFGS services use 1). With a large initial gradient the first trial step overflowed or overshot by orders of magnitude, and the first line search failed. After a step that the cap shortened, the relative convergence tests are skipped once. A first trial step that the cap shortened is searched without the floor minAlpha, the smallest step WolfeLineSearch may return, so that its bracket starts at 0: the floor would forbid moving a parameter by less than minAlpha |g|_inf. The zoom gives up on a bracket narrower than min(1e-16, 1e-13 alpha) instead of 1e-16, so that a bracket from a first trial step below 1e-16 (a gradient above 1e16 with the cap) is still searched.
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: 1498.179 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 |
|
I tried (with Claude) the cap on a two-scale problem: The cause is the inverse Hessian scale. The first pair I pushed one commit to your branch that does two things after a capped first step: it skips
All 14 failures with the commit are at K >= 1e16, where the condition number exceeds 1/eps and the gradient in The cost is close to this PR's. Gradient evaluations (L-BFGS / dense BFGS):
Unscaled Rosenbrock, the Poisson problem from 0 and the quadratic with condition 1e2 are within 10 % of this PR. Dense BFGS on the exp sum from 5 still stops early (f - f* = 1.7, original PR 393, develop 7613); that is the inverse Hessian scale that #3444 addresses. With #3444 as well, the two changes do not interfere (#3444 changes The commit adds a services test ( |
|
@avehtari You didn't actually push any commit yet, you are welcome to do so though. |
|
@jachymb Hah, we two have too many PRs, and I forgot to push that commit! |
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: 43 bits physical, 48 bits virtual CPU(s): 256 On-line CPU(s) list: 0-255 Thread(s) per core: 2 Core(s) per socket: 64 Socket(s): 2 NUMA node(s): 2 Vendor ID: AuthenticAMD CPU family: 23 Model: 49 Model name: AMD EPYC 7742 64-Core Processor Stepping: 0 Frequency boost: enabled CPU MHz: 1497.193 CPU max MHz: 3416.0681 CPU min MHz: 1500.0000 BogoMIPS: 4491.85 Virtualization: AMD-V L1d cache: 4 MiB L1i cache: 4 MiB L2 cache: 64 MiB L3 cache: 512 MiB NUMA node0 CPU(s): 0-63,128-191 NUMA node1 CPU(s): 64-127,192-255 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: Mitigation; untrained return thunk; SMT enabled with STIBP protection 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; Retpolines; IBPB conditional; STIBP always-on; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected Vulnerability Srbds: Not affected Vulnerability Tsa: Not affected 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 nopl xtopology nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 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 ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip rdpid overflow_recov succor smca sev sev_es 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 |
|
@avehtari Thanks, I reproduced your numbers and your change seems like an overall improvement. I pushed a one-liner that writes "capped first step, Hessian reset" to the iteration log for the restart |
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: 1497.751 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 |
This should go after #3444 and probably also #3447. Creating just as a draft for now.
AI use disclosure: This was developed with the help of Claude Code (Opus 5.5).
Submission Checklist
./runTests.py src/test/unitmake cpplintSummary
On the first iteration and after a Hessian reset,$\alpha_0 \cdot (-g)$ with $\alpha_0$ =
BFGSMinimizer::steptries the stepinit_alpha(0.001). With a large initial gradient (Poisson regression with large exposures, a scale parameter initialised far out) that step moves the parameters by orders of magnitude too far: the evaluations overflow or overshoot, the line search halves the step 10 times or brackets nothing, and the run ends at iteration 1 with error 70 (line-search failure). Changes:LSOptions::maxStep0tol_rel_obj,tol_rel_grad) are skipped once: the inverse Hessian estimate rests on that one short step, and the relative gradient test judged convergence from it. The absolute tests still apply.WolfeLineSearchgives up on a bracket narrower thanWolfeLineSearchtakes itsminAlphaargument (LSOptions::minAlpha,minAlpha, with the value and slope at 0 attached to that end. After the cap that floor forbids moving a parameter by less thanBFGSMinimizer::steptherefore passes 0 instead ofminAlphawhen the cap shortened the first trial step, so that its bracket starts at 0, where the value and slope are known. Uncapped searches keep the floor (Pathfinder never caps), andminAlphakeeps its second use, the lower bound of the interpolated first trial step.This PR and the PR of branch
feature/line-search-fewer-evaluationsboth change the last argument of the twoWolfLSZoomcalls inWolfeLineSearch(minRangehere,1e-16, maxLSItsthere); whichever is merged second resolves it tominRange, maxLSIts. With both, that PR's bound ofmaxLSItsevaluations also ends a failing zoom that the narrower limit of change 3 would let run longer.Intended Effect
With L-BFGS, runs that develop ends at iteration 1 with error 70 because of a large initial gradient reach the optimum (dense BFGS: 99 of 100 with
tol_rel_obj = tol_rel_grad = 1, 2 of 100 at the defaults; see Side Effects). Against develop on 20 model configurations (GLMs, a hierarchical logistic regression, embedded-Laplace GLMMs and GPs; 30–100 seeds each), L-BFGS at CmdStan's defaults: none of develop's 220 line-search failures in 1650 runs remain (every run of two Poisson regressions with exposures up to 400, a tenth of two with exposures up to 20), and those runs end at the best log density. L-BFGS needs 0.66–0.91 times develop's gradient evaluations on five configurations (the two with a tenth failing among them) and stays within 5% on the rest, apart from the large-exposure ones, which develop stopped after 13 evaluations. Withtol_rel_obj = tol_rel_grad = 1all 900 L-BFGS runs end at the best log density (develop 794). Dense BFGS: none of develop's 106 failures in 900 runs remain, and withtol_rel_obj = tol_rel_grad = 1898 instead of 793 runs end at the best log density.How to Verify
New tests, all failing on develop:
OptimizationBfgsLinesearch.wolfeLineSearch_tiny_first_step(bfgs_linesearch_test.cpp):ServicesOptimize.lbfgs_large_initial_gradientandbfgs_large_initial_gradient(services/optimize/{lbfgs,bfgs}_jacobian_test.cpp): the services fromOptimizationBfgsMinimizerCosh.large_initial_gradient(bfgs_minimizer_test.cpp):maxStep0 = 1. It sets the new option, so it does not compile on develop; without that line (develop's behaviour) the first iteration fails (return code −1).OptimizationBfgsMinimizerExp.no_relative_convergence_after_reset(bfgs_minimizer_test.cpp):maxStep0 = 1and CmdStan's defaulttol_rel_grad. It guards change 2: without it the relative gradient test stops the run atmaxStep0line) the first line search already fails.OptimizationBfgsMinimizerStiffQuadratic.capped_step_without_floor(bfgs_minimizer_test.cpp):maxStep0 = 1. The capped first stepminAlpha. It guards change 4: without it the step fails (return code −1). It sets the new option, so it does not compile on develop.Existing tests that reach the changed code pass unchanged:
bfgs_linesearch_test.cpp,bfgs_minimizer_test.cpp,bfgs_test.cpp,bfgs_exponential_boundary_test.cpp,services/optimize/{bfgs,lbfgs,bfgs_jacobian,lbfgs_jacobian}_test.cpp, and the Pathfinder testsservices/pathfinder/{eight_schools,normal_glm}_test.cpp.Side Effects
In-process A/B harness against develop; I can share it. Pathfinder never caps; none of its 960 measured runs changes.
feature/bfgs-update-sizing). At the defaults it then stops short of the best log density in 98 of 100 large-exposure Poisson runs (develop: error 70), 6 other former failures, 23 runs that develop ended there (7 others now reach it) and, net, 4 of 380 test-function starts.tol_rel_obj = tol_rel_grad = 1, line-search failures rise on some configurations (by at most 4 runs per configuration) but fall overall (L-BFGS 371 → 323, dense BFGS 296 → 205).init_alphaof the services now bounds the first step, and a capped search may return a step belowminAlpha.More than 5% more evaluations:
tol_rel_obj = tol_rel_grad = 1: Poisson regressiontol_rel_obj = tol_rel_grad = 1: Laplace Poisson GLMM, logisticDocumentation
Comment on
LSOptions::maxStep0and doc comments of the services'init_alphaparameter. The CmdStan documentation ofinit_alphacould say that the first step moves no unconstrained parameter by more than 1.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: