Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Dask estimators serialization prior to training #6065

Open
wants to merge 3 commits into
base: branch-24.10
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion python/cuml/cuml/dask/common/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def __init__(self, *, client=None, verbose=False, **kwargs):
self.internal_model = None

def __getstate__(self):
internal_model = self._get_internal_model().result()
internal_model = self._get_internal_model()
if internal_model:
internal_model = internal_model.result()
state = {
"verbose": self.verbose,
"kwargs": self.kwargs,
Expand Down
13 changes: 13 additions & 0 deletions python/cuml/cuml/tests/dask/test_dask_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,16 @@ def test_serialize_mnmg_model(client):
unpickled_model = pickle.loads(pickled_model)

assert np.allclose(unpickled_model.coef_, model.coef_)


def test_serialize_before_training(client):
X, y = make_regression(n_samples=1000, n_features=20, random_state=0)
X, y = da.from_array(X), da.from_array(y)

model = LinearRegression(client=client)
pickled_model = pickle.dumps(model)
unpickled_model = pickle.loads(pickled_model)

unpickled_model.client = client
unpickled_model.fit(X, y)
assert hasattr(unpickled_model, "coef_")
Loading