Repository navigation
Conversation
The parameter transforms of BaseDistribution were lambdas, so pickling a distribution family, a fitted LSS estimator or the LSS training module (e.g. for Lightning's ddp_spawn strategy) failed with "Can't get local object". Use module-level functions with the same behaviour. Fixes #557
This branch has not been deployed
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.
Fixes #557
Problem
BaseDistribution.__init__stored the"none","square","probabilities"and"log"parameter transforms as lambdas, andget_transform()fell back to another lambda. Lambdas defined inside a function can't be pickled, so pickling failed withCan't get local object 'BaseDistribution.__init__.<locals>.<lambda>'for:ddp_spawnstrategy.Fix
deeptab/distributions/base.pyreplaces the lambdas with module-level functions (_identity,_square,_softmax_last_dim,_stable_log) that compute exactly the same values. Theget_transform()fallback uses_identity. The behaviour is unchanged otherwise. Unknown transform names still map to the identity; that's a separate question.Tests
In
tests/integration/test_save_load.py, the module that already holds the pickle tests and has the S301 ruff exemption:test_every_distribution_family_survives_a_pickle_round_trip[<all 16 registered families>]: same class and parameter names afterpickle.loads(pickle.dumps(...)). Fornormal, the restored family also produces the same transformed parameters.test_fitted_lss_can_be_pickled[normal|quantile|categorical]: a fittedMLPLSSpickles and unpickles as an unfitted estimator, as documented for the other estimators.All 19 fail on
mainand pass with this change. I confirmed theddp_spawnfailure onmain(MLPLSS(...).fit(..., accelerator="cpu", devices=2, strategy="ddp_spawn")raises the sameAttributeError). In my sandbox, an end-to-endddp_spawnrun can't complete for any estimator, includingMLPRegressor, becausetorch_shm_managercan't bind. With this change the LSS run gets past pickling to that same environment error.Docs
No change needed.
Checks
just test: 3255 passed, 46 skipped, 28 xfailed; coverage 91.28%just docs: build succeeded (warnings treated as errors)just check: all hooks passed (ruff, prettier, pyright)