Proposal for Caching the Within-Preconditioner#1264
Open
Proposal for Caching the Within-Preconditioner#1264
Conversation
…r_ attribute for reuse across model fits
…en inner tolerance is tighened. in addition, add inner tolerance tighening to fepois
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.
Summary
This PR introduces a typed fixed-effects demeaning API, passes it through the code base, and adds reusable
withinpreconditioners to speed up repeated multi-way FE estimation.The main user-facing additions are:
demeaner=objects:MapDemeaner(...)WithinDemeaner(...)LsmrDemeaner(...)demeanernow takes precedence overdemeaner_backend,fixef_tol, andfixef_maxiterfeolsnow exposesfit.preconditioner_forWithinDemeanerWithinDemeaner(preconditioner=...)WithinPreconditionercan be pickled across sessions, following the upstreamwithin-pypatternWhat Changed
1. Typed demeaner API
We now support a typed
demeaner=interface instead of relying only on string backend selection viademeaner_backend. This makes the demeaner backend configuration explicit, extensible, and easier to validate.The typed demeaner objects control actual runtime execution.
WithinDemeaneroptions flowing into thewithinbackendLsmrDemeaneroptions flowing into the SciPy/CuPy solversMapDemeaneroptions flowing into the MAP solvers2. Reusable
withinpreconditionersFor multi-way FE
WithinDemeanerfits, we now build and cache a reusableWithinPreconditioner.That preconditioner is:
feolsasfit.preconditioner_WithinDemeaner(preconditioner=...)feglmandfepois3. IWLS reuse
For
feglmandfepois, we now reuse a fit-localwithinpreconditioner across IWLS iterations.Current policy is intentionally simple:
@schroedk - For generalized linear models, we need to demean repeatedly with "different weights". Here we currently say it is better to run on "stale" preconditions for a while than to update the preconditioner in every iteration. This can of course be refined later.
4. Persistence
WithinPreconditioneris pickleable across sessions.This mirrors
within-pyclosely:FePreconditioneris serialized withpostcard__reduce__Key Design Choices
Why expose preconditioners, but not solvers?
We intentionally expose preconditioners as reusable objects, but not solvers.
Because reusing a
withinpreconditioner is where most of the practical speedup comes from. It is "ok" if the preconditioner becomes "a bit stale" - this is a feature, not a bug imo. Plus, we do not need to check that the fixed effects and the sample and weights are identical, which is what we would have needed to do if we allowed users to pass solvers.For iterated weighted least squares as used for GLMs, the preconditioner is the better choice as in each iteration, a stale preconditioner will be "good enough".
Stay close to
within-pyTried to stay close to the implementation in
within-py.In particular:
within-pyWorkflow
Typical usage now looks like:
For persistent reuse, you can do:
And then fit the regression model.