Repository navigation
Conversation
|
@cola1917, please be cautious about modifying the LM logic here. This logic is shared across multiple libraries, including the LM implementation in Please compare the trial acceptance/rejection and parameter rollback changes with the corresponding implementations and coordinate any necessary updates so the libraries remain consistent. |
|
Thanks for flagging this. I compared both BAE overrides at Across the implementations, finite acceptance/retry-limit behavior and strategy-update ordering remain unchanged. Non-finite trials are always rejected, including at the retry limit, and restore the exact pre-trial parameter values and loss rather than applying I also pushed With BAE installed, the full PyPose suite is 254 passed / 1 failed: the existing sparse chain-PGO translation assertion fails identically on unmodified main (max error 0.00099018 vs tolerance 0.0002). I recorded that and the BAE broader-suite limitations in the PR descriptions; I have not changed existing assertions or skips. |
Summary
Fixes #441.
LM currently accepts a NaN trial loss because
last < lossis false for NaN. It can also retain an infinite trial when its rejection budget is exhausted. For example, fittingsqrt(x)to0.1fromx=1takes a finite first step to approximately-0.8, returns NaN without a rejection, and fails the next Jacobian evaluation.The implementation change is confined to
LevenbergMarquardt.step()and therejectargument documentation. It does not change Jacobian conventions, sparse linear algebra, or the work in #405/#407/#440.Regression coverage
The new tests use deterministic inputs and do not advance the global RNG:
sqrtdomain overshoot, followed by successful damped retries and convergence, in float32/float64.reject=0and exhausted positive retry budgets, using Constant, Adaptive, and TrustRegion strategies.On unmodified main
9345958013d4cc73b3d03f6be54236135332699b, the new CPU file has 16 failures and 2 passing controls. The same file passes with this fix on CPU and CUDA.Validation
TestOptim.test_optim_anybatch, fixed seeds 100 through 264: 5 failures on main (139/159/236: NaN; 211/264: convergence bound), 0 failures with this fix. This is supporting evidence, not a claim that every numerical-instability source is fixed.git diff --checkpasses.Full suites were run with initial
torch.manual_seed(0)andOMP_NUM_THREADS=2 MKL_NUM_THREADS=2. No existing assertions, skips, RNG seeds, or CI configuration were changed.Cross-library follow-up
Compared against BAE
afad40e, including bothLM.step()andSchur.step()and their explicit/matrix-free paths. Both override PyPose's step, so a coordinated fix is proposed in pypose/bae#50. Finite acceptance and retry-budget rules are preserved; non-finite trials always restore the pre-trial parameters/loss. Strategy update ordering is unchanged.Additional validation with Warp 1.13.0+cu12 and compiled BAE CUDA extensions on the same RTX 4080 SUPER / PyTorch 2.7.0+cu128 environment:
9345958.0.000990183836037493, tolerance0.0002). This pre-existing failure is reported rather than changing its threshold.Cost and limits
Exact rollback temporarily stores one copy of the trainable parameter values per parameter group: O(P) additional memory, not another Jacobian/Hessian copy. The copies are local to
step()and do not enter the optimizer state dict.The initial CUDA suite above skipped the optional BAE tests. The follow-up now exercises that backend; the existing PGO precision failure is documented above. Model buffers and other side effects of
forward()are not rolled back; this fix restores optimizer-owned trainable parameters only. It assumes the starting loss/Jacobian are valid and does not turn an initially invalid model into a valid one.