Skip to content

Commit

Permalink
Fix Dask estimators serialization prior to training (#6065)
Browse files Browse the repository at this point in the history
Partially answers #6046

Authors:
  - Victor Lafargue (https://github.com/viclafargue)
  - Dante Gama Dessavre (https://github.com/dantegd)

Approvers:
  - Divye Gala (https://github.com/divyegala)

URL: #6065
  • Loading branch information
viclafargue authored Oct 17, 2024
1 parent ef7a61d commit 417d980
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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_")

0 comments on commit 417d980

Please sign in to comment.