You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
check_estimator_internal_state_unchanged_by_inference: only compute per-attribute diagnostics when the check fails #35592
This issue is not yet ready for a PR. If you are interested in contributing to scikit-learn, please have a look at our contributing guidelines, and in particular the sections for new contributors and the "Needs triage" label.
#34729 added check_estimator_internal_state_unchanged_by_inference. Before and after each inference method, it pickles two things:
the whole estimator, _pickled_bytes(estimator), which is what the assert compares;
every value in estimator.__dict__, one at a time, used only to name the mismatching attributes in the error message.
Step 2 runs every time, not only when the check fails, and it pickles attribute values directly, bypassing the estimator's __getstate__. An estimator that holds unpicklable state (a native handle, a GPU index) and handles it in __getstate__ passes step 1 but errors in step 2. The check then fails even when inference changed nothing.
We hit this in cuML, where several estimators keep opaque GPU objects as attributes. Our current workaround monkeypatches the private _StatePickler in our test suite, which we'd like to avoid.
Would it be possible to compare only the whole-estimator bytes? When they differ, compute the per-attribute pickles to build the error message, and skip any attribute that can't be pickled on its own (not sure what we do wrt error message if this happens). The contract being tested stays the same, I think.
From memory, you need to get attributes (or the moral equivalent) initially because the whole problem is they might be mutated in inference; there's nothing to compare to if you only start looking once a difference has emerged.
But that being said, this is all for debugging purposes, and really shouldn't break things. I'll open a PR to fix this.
Activity
itamarst commentedon Dec 1, 2026
From memory, you need to get attributes (or the moral equivalent) initially because the whole problem is they might be mutated in inference; there's nothing to compare to if you only start looking once a difference has emerged.
But that being said, this is all for debugging purposes, and really shouldn't break things. I'll open a PR to fix this.