Repository navigation
PERF Cache inspect.signature in GPR kernels - #33067
Conversation
|
Similar optimization can be applied to |
|
caching keeping this PR focused on GPR kernels seems reasonable. a similar change for |
inspect.signature in GPR kernelsinspect.signature in GPR kernels
|
So there is a 30% overhead on a dataset with a single feature and 1000 points. However, I suspect that the benefits would be much less for more features or data points. |
|
@ogrisel in a real workload I measured 140 seconds of training time spent in I have verified that this patch has significant positive impact on the training time I observe, saving more than 15%. I can try to write a bigger benchmark if you wish. My case is specifically limited to small (under 1K typically) amount of data points and less than 100 features - many inputs are around 20 features x 200 points. |
|
Thanks for the more detailed real-world impact estimate. Could you please add a changelog entry of the "efficiency" kind? |
Co-authored-by: Olivier Grisel <[email protected]>
|
Apologies for the delay, I have added a changelog entry and committed your suggested comment. I also retried two training jobs with and without this patch, getting approx. 7% saving on 400 data points (4 folds x 42 candidates) and approx. 18% saving on 70 data points (also 4 folds x 42 candidates) - both in a single noisy sample, but still shows that this is probably worth trying, provided that there are no obvious negative consequences. |
|
This looks like a nice improvement. I do wonder if we need that However this might be a bigger change compared to caching the results. What do people think? I think it would be interesting to see the code for your |
Do you propose to replace this inspection with another Introspection/reflection is often costly - using The original code depends on a multi-layer model wrappers architecture, but I can extract a benchmark from local values in pdb, and I can publish that dataset just fine (I generated it manually for testing). I'll try to free up a few minutes and post it here within a couple of days. |
|
Thanks for the detailed answer. I think based on what you said and the fact that for me it was more speculation than a well thought out plan we should go ahead with this PR as it is. We can investigate alternatives and/or adding more caching for normal estimators in a new issue. |
|
I merged |
jeremiedbb
left a comment
There was a problem hiding this comment.
LGTM. Thanks @sterliakov
I agree with Tim that this signature inspection should be done as a common test for kernels instead. Doing it at runtime allows customs kernels still (although the warning message is about scikit-learn kernels). But let's revisit that in a different issue/PR.
Reference Issues/PRs
None
What does this implement/fix? Explain your changes.
inspect.signatureis known to be very slow, it is not the best function for a hot path. It was identified as a performance bottleneck in our real workload. Since the method signature cannot change while maintaining method's identity, it becomes a perfect target for caching. Cache size of 32 should be sufficient to cover all currently existing kernels at once (and the memory footprint is about zero).AI usage disclosure
I used AI assistance for: never
Any other comments?
Initially I identified this with cProfile in our real workload, and then confirmed with a tiny benchmark:
Output: