Repository navigation
FIX metaedata routing with dask backend on joblib - #34077
Conversation
| This should be of the form ``process_routing()["step_name"]``. | ||
| """ | ||
| res = transformer.transform(X, **params.transform) | ||
| res = transformer.transform(X, **params["transform"]) |
There was a problem hiding this comment.
this is what actually fixes the original issue trigering this work.
| # Routing disabled: fit_params for a step are forwarded to whichever | ||
| # of fit/fit_transform/fit_predict the step's caller invokes. | ||
| per_step = { | ||
| name: {"fit": {}, "fit_transform": {}, "fit_predict": {}} | ||
| for name, step in self.steps | ||
| if step is not None | ||
| } | ||
| for pname, pval in props.items(): | ||
| if "__" not in pname: | ||
| raise ValueError( | ||
| "Pipeline.fit does not accept the {} parameter. " | ||
| "You can pass parameters to specific steps of your " | ||
| "pipeline using the stepname__parameter format, e.g. " | ||
| "`Pipeline.fit(X, y, logisticregression__sample_weight" | ||
| "=sample_weight)`.".format(pname) | ||
| ) | ||
| step, param = pname.split("__", 1) | ||
| per_step[step]["fit"][param] = pval | ||
| per_step[step]["fit_transform"][param] = pval | ||
| per_step[step]["fit_predict"][param] = pval | ||
| return _manual_routing(per_step) |
There was a problem hiding this comment.
This part is just de-indentation of the above code, since we do early-return anyway.
StefanieSenger
left a comment
There was a problem hiding this comment.
Nice, looks good to me. Thank you, @adrinjalali.
I have a few nit comments only.
| contain keys for the metadata which should be routed to them. Consumers should | ||
| use item access (``routed_params[child][method]``) rather than attribute access, |
There was a problem hiding this comment.
| contain keys for the metadata which should be routed to them. Consumers should | |
| use item access (``routed_params[child][method]``) rather than attribute access, | |
| contain keys for the metadata which should be routed to them. Consumers have to | |
| use item access (``routed_params[child][method]``) as opposed to attribute access, |
Use a bit stronger language.
There was a problem hiding this comment.
they don't have to, we're being nice here since dask backend has a bug.
There was a problem hiding this comment.
Hm, you're thinking about third party estimators that are consumers here. I didn't see from that perspective, but I can now go along with it.
Inside scikit-learn, I think we should always use dict access, especially while implementing new consumers, like callbacks (FYI @FrancoisPgm).
There was a problem hiding this comment.
Should we use dict access in the metadata routing docs then?
There was a problem hiding this comment.
yeah doing that in the docs makes sense. Bur here's also the fix on joblib side: joblib/joblib#1798
| method_mapping=MethodMapping().add(caller="fit", callee="fit"), | ||
| method_mapping=MethodMapping() | ||
| .add(caller="fit", callee="fit") | ||
| .add(caller="predict", callee="predict"), |
| routed_params = _manual_routing( | ||
| { | ||
| name: { | ||
| "score": { |
There was a problem hiding this comment.
| "score": { | |
| "score": { | |
| # **common_kwargs copies its keys and values into a new dict, | |
| # so each scorer gets its own values |
Let's add a comment indicating that common_kwargs gets copied. I was very surprised about that.
There was a problem hiding this comment.
they get the same values, they're not copied:
In [1]: a = [1]
In [2]: d1 = {1: a}
In [3]: d2 = {**d1, **{2: 3}}
In [4]: a.append(2)
In [5]: d1
Out[6]: {1: [1, 2]}
In [6]: d2
Out[7]: {1: [1, 2], 2: 3}There was a problem hiding this comment.
Yes, I see, the values (list a) can still change, because it is a shallow copy of common_kwargs.
I just wonder that we may not want to allow metadata to be able to change between metrics, probably not. We allowed it before though.
|
@OmarManzoor this should be ready to merge now if you could review. |
OmarManzoor
left a comment
There was a problem hiding this comment.
LGTM. Thank you @adrinjalali
Fixes #34005
In the process, found some inconsistencies wrt how we handle "empty requests", and this PR unifies them at the same time.
AI usage disclosure
I used AI assistance for:
cc @StefanieSenger