Skip to content

fix(models): validate inputs upfront and fix pickling of the Lightning module - #438

Open
ChrisW09 wants to merge 1 commit into
mainfrom
fix/api-robustness
Open

fix(models): validate inputs upfront and fix pickling of the Lightning module#438
ChrisW09 wants to merge 1 commit into
mainfrom
fix/api-robustness

Conversation

@ChrisW09

Copy link
Copy Markdown
Collaborator

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

  1. __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 spurious task_model key. The docstring in _mixins/serialization.py explicitly documents the opposite intent.
  2. fit() crashes on plain-list X. The fit.started event evaluates X.shape[1] if hasattr(X, "shape") else len(X.columns) eagerly, before ensure_dataframe runs in _build_model — so list input dies with AttributeError: 'list' object has no attribute 'columns' even though the converter handles lists fine.
  3. All-zero sample_weight fails cryptically. It reached torch.multinomial and raised a RuntimeError mid-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 a ValueError matching .*weight.*zero.*.

Fix

Null _task_model; fall back to len(X[0]) for list input in the event payload; validate sample_weight in _resolve_loss_and_sampler (non-negative, at least one non-zero) with actionable messages.

Tests

New tests/test_api_robustness.py covers all three, plus a positive case confirming valid non-uniform weights still work. tests/test_sklearn_contract.py now passes fully green (previously 1 failure), and tests/test_class_imbalance.py is unaffected.

🤖 Generated with Claude Code

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Assorted public-API crashes and robustness gaps (fit on lists, pickling, sample_weight, data API)

1 participant