Skip to content

Do not use Numba objmode for supported advanced indexing operations #805

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

Merged
merged 2 commits into from
Jun 21, 2024

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Jun 5, 2024

Description

Several cases of advanced indexing are supported by Numba these days. This PR makes sure we don't skip on those!

Related Issue

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

@ricardoV94 ricardoV94 changed the title Do not use Numba objmode for supported AdvancedSubtensor operations Do not use Numba objmode for supported advanced indexing operations Jun 5, 2024
@ricardoV94 ricardoV94 force-pushed the numba_advanced_idx_cleanup branch 3 times, most recently from 959b7f6 to 8fd718c Compare June 5, 2024 16:00
@ricardoV94 ricardoV94 added the enhancement New feature or request label Jun 5, 2024
Copy link

codecov bot commented Jun 5, 2024

Codecov Report

Attention: Patch coverage is 94.78261% with 6 lines in your changes missing coverage. Please review.

Project coverage is 80.87%. Comparing base (36c55f5) to head (b6ee8e7).
Report is 191 commits behind head on main.

Files with missing lines Patch % Lines
pytensor/link/numba/dispatch/subtensor.py 94.39% 3 Missing and 3 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #805      +/-   ##
==========================================
+ Coverage   80.76%   80.87%   +0.11%     
==========================================
  Files         163      164       +1     
  Lines       46941    46891      -50     
  Branches    11499    11474      -25     
==========================================
+ Hits        37912    37925      +13     
+ Misses       6786     6752      -34     
+ Partials     2243     2214      -29     
Files with missing lines Coverage Δ
pytensor/link/numba/dispatch/__init__.py 100.00% <100.00%> (ø)
pytensor/link/numba/dispatch/basic.py 86.35% <ø> (+0.80%) ⬆️
pytensor/tensor/subtensor.py 89.89% <100.00%> (+0.02%) ⬆️
pytensor/tensor/type_other.py 74.15% <100.00%> (-8.99%) ⬇️
pytensor/link/numba/dispatch/subtensor.py 94.39% <94.39%> (ø)

... and 12 files with indirect coverage changes

@ricardoV94 ricardoV94 force-pushed the numba_advanced_idx_cleanup branch from 8fd718c to 9fe718a Compare June 5, 2024 16:34
@ricardoV94 ricardoV94 removed the request for review from kc611 June 5, 2024 16:36
@ricardoV94
Copy link
Member Author

@kc611 sorry for tagging if your review, fat fingers on my side! Do keep the cool work on extending advanced indexing on the Numba side!!!

@ricardoV94 ricardoV94 force-pushed the numba_advanced_idx_cleanup branch 3 times, most recently from c0e2255 to 478cd14 Compare June 5, 2024 18:06
@kc611
Copy link
Contributor

kc611 commented Jun 6, 2024

@kc611 sorry for tagging if your review, fat fingers on my side! Do keep the cool work on extending advanced indexing on the Numba side!!!

No worries! 🙂 I took a quick look at this PR and I'd say if you guys are using string-based function creation anyways then it's completely possible to support the full set of advanced indexing cases by simply creating the required loops within the string-based functions.

@ricardoV94
Copy link
Member Author

@kc611 sorry for tagging if your review, fat fingers on my side! Do keep the cool work on extending advanced indexing on the Numba side!!!

No worries! 🙂 I took a quick look at this PR and I'd say if you guys are using string-based function creation anyways then it's completely possible to support the full set of advanced indexing cases by simply creating the required loops within the string-based functions.

Yeah, but we are not doing that yet. We are just creating dumb stuff like x[indices] = y. We'll come to that if we need it, or perhaps Numba will support it first :D

Thanks for checking it out!

@ricardoV94 ricardoV94 force-pushed the numba_advanced_idx_cleanup branch from 478cd14 to b6ee8e7 Compare June 11, 2024 17:20
@ricardoV94
Copy link
Member Author

This should be ready for review. After this we can start adding some simple non-supported cases like boolean indexing with indices.shape == x.shape, and some multiple vector index cases

Copy link
Member

@jessegrabowski jessegrabowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. The duplicate indices thing isn't really clear to me. Also curious if the lines codecov is complaining about are unreachable, and, if so, whether we can just get rid of them.

# Numba does not support indexes with more than one dimension
# Nor multiple vector indexes
(len(adv_idxs_dims) > 1 or adv_idxs_dims[0] > 1)
# The default index implementation does not handle duplicate indices correctly
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here "default" means on our end? Is that a problem?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means the code returned by numba_funcify_default_subtensor. Shouldn't be a problem as long as we don't try to use it when it's not valid

@ricardoV94 ricardoV94 merged commit a14cb2b into pymc-devs:main Jun 21, 2024
55 of 56 checks passed
@ricardoV94 ricardoV94 deleted the numba_advanced_idx_cleanup branch April 21, 2025 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants