fix(models): validate inputs upfront and fix pickling of the Lightning module - #438
Open
ChrisW09 wants to merge 1 commit into
Open
fix(models): validate inputs upfront and fix pickling of the Lightning module#438ChrisW09 wants to merge 1 commit into
ChrisW09 wants to merge 1 commit into
Conversation
…g module - SklearnBase.__getstate__ set state['task_model'] = None, but the attribute is _task_model, so pickling serialised the full Lightning module -- contradicting the intent documented in _mixins/serialization. - The fit.started event computed len(X.columns) before ensure_dataframe ran in _build_model, so fit() crashed on plain-list X even though the converter accepts lists. - All-zero (or negative) sample_weight now raises a clear ValueError at fit() instead of a cryptic torch.multinomial RuntimeError mid-training. This also satisfies sklearn's check_all_zero_sample_weights_error, the one estimator check currently failing on main. Fixes #424 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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 #424 (the three items with a clear single fix; the remaining items in that issue — the MLflow sqlite directory and the InferenceModel double-load — are left for separate PRs).
Problems
__getstate__nulls the wrong key.state["task_model"] = None— but the attribute is_task_model, so pickling kept the full Lightning module and merely added a spurioustask_modelkey. The docstring in_mixins/serialization.pyexplicitly documents the opposite intent.fit()crashes on plain-listX. Thefit.startedevent evaluatesX.shape[1] if hasattr(X, "shape") else len(X.columns)eagerly, beforeensure_dataframeruns in_build_model— so list input dies withAttributeError: 'list' object has no attribute 'columns'even though the converter handles lists fine.sample_weightfails cryptically. It reachedtorch.multinomialand raised aRuntimeErrormid-training. This is the one failing check in the repo's own suite today:test_sklearn_contract.py::...::check_all_zero_sample_weights_error, which requires aValueErrormatching.*weight.*zero.*.Fix
Null
_task_model; fall back tolen(X[0])for list input in the event payload; validatesample_weightin_resolve_loss_and_sampler(non-negative, at least one non-zero) with actionable messages.Tests
New
tests/test_api_robustness.pycovers all three, plus a positive case confirming valid non-uniform weights still work.tests/test_sklearn_contract.pynow passes fully green (previously 1 failure), andtests/test_class_imbalance.pyis unaffected.🤖 Generated with Claude Code