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

ENH: speed up _harmonize_tensor #603

Merged
merged 2 commits into from
Mar 15, 2025

Conversation

DerWeh
Copy link
Contributor

@DerWeh DerWeh commented Mar 14, 2025

As far as I can see, cell_map is typically a list with a single tuple. This function call incurs tremendous function overhead for doing nothing (multiplying a single number with 1): first we generate a list, then go through all the NumPy dispatching.

If this indeed is the common case, it's much faster to avoid creating a list (using a generator) and using the simple Python math.prod.

Equivalently, we could use

prod(len(x) for x in cell_map)

This is mostly a matter of taste (the performance is identical).

For the simple case of merging a model with itself, this yielded a speed-up of the factor 4 for me. Can you please comment @paulbkoch if my assumptions are correct, or if there are use cases I am overlooking?


This speed up is part of PR #578. It doesn't seem that I'll find the time soon to fix the remaining bug in _harmonize_tensor. So I thought it's a good idea to include this performance improvement right away.

Weh Andreas and others added 2 commits March 14, 2025 22:36
Common case is just a single element, thus that the overhead of NumPy is
very large.
Copy link

codecov bot commented Mar 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.62%. Comparing base (9b7dfd6) to head (3a511bc).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #603   +/-   ##
========================================
  Coverage    76.62%   76.62%           
========================================
  Files           72       72           
  Lines         9672     9672           
========================================
  Hits          7411     7411           
  Misses        2261     2261           
Flag Coverage Δ
bdist_linux_310_python 76.29% <100.00%> (+0.03%) ⬆️
bdist_linux_311_python 76.29% <100.00%> (-0.03%) ⬇️
bdist_linux_312_python 76.29% <100.00%> (+0.07%) ⬆️
bdist_linux_39_python 76.22% <100.00%> (+0.05%) ⬆️
bdist_mac_310_python 76.45% <100.00%> (+0.08%) ⬆️
bdist_mac_311_python 76.40% <100.00%> (-0.12%) ⬇️
bdist_mac_312_python 76.35% <100.00%> (-0.06%) ⬇️
bdist_mac_39_python 76.28% <100.00%> (-0.13%) ⬇️
bdist_win_310_python 76.31% <100.00%> (-0.13%) ⬇️
bdist_win_311_python 76.48% <100.00%> (ø)
bdist_win_312_python 76.43% <100.00%> (-0.10%) ⬇️
bdist_win_39_python 76.40% <100.00%> (-0.08%) ⬇️
sdist_linux_310_python 76.05% <100.00%> (-0.18%) ⬇️
sdist_linux_311_python 76.23% <100.00%> (+0.03%) ⬆️
sdist_linux_312_python 76.15% <100.00%> (-0.03%) ⬇️
sdist_linux_39_python 76.21% <100.00%> (ø)
sdist_mac_310_python 76.29% <100.00%> (-0.12%) ⬇️
sdist_mac_311_python 76.26% <100.00%> (-0.17%) ⬇️
sdist_mac_312_python 76.20% <100.00%> (-0.18%) ⬇️
sdist_mac_39_python 76.28% <100.00%> (-0.09%) ⬇️
sdist_win_310_python 76.31% <100.00%> (-0.18%) ⬇️
sdist_win_311_python 76.48% <100.00%> (ø)
sdist_win_312_python 76.41% <100.00%> (-0.10%) ⬇️
sdist_win_39_python 76.35% <100.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@paulbkoch paulbkoch merged commit 3fed134 into interpretml:develop Mar 15, 2025
57 of 58 checks passed
@paulbkoch
Copy link
Collaborator

Thanks @DerWeh -- I was wondering why merging EBMs had become so slow in more recent versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants