Skip to content

Numba: SIMD-friendly maximum/minimum - #2370

Open
ricardoV94 wants to merge 1 commit into
pymc-devs:mainfrom
ricardoV94:slow_numba_max
Open

Numba: SIMD-friendly maximum/minimum#2370
ricardoV94 wants to merge 1 commit into
pymc-devs:mainfrom
ricardoV94:slow_numba_max

Conversation

@ricardoV94

@ricardoV94 ricardoV94 commented Aug 20, 2026

Copy link
Copy Markdown
Member

Closes #2367

This PR goes from 5x to 1.1-1.3x slower than numpy on my machine. I don't think we can go below that because numba/llvm won't SIMD these operations automatically. Numpy has a SIMD dispatcher instead.

In my experience this is not super critical as max/min are usually fused in loops that are order of magnitude worse, usually exp in a stable softmax or logsumexp

@ricardoV94
ricardoV94 force-pushed the slow_numba_max branch 3 times, most recently from 3824ebf to 9fc0f1f Compare August 20, 2026 15:45

@jessegrabowski jessegrabowski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For the record it came up in maxpool layers here: pymc-devs/pytensor_ml#100

@ricardoV94

Copy link
Copy Markdown
Member Author

For the record it came up in maxpool layers here: pymc-devs/pytensor_ml#100

Does it fix it on your end?

@ricardoV94
ricardoV94 marked this pull request as ready for review August 20, 2026 15:53
@jessegrabowski

jessegrabowski commented Aug 20, 2026

Copy link
Copy Markdown
Member

I switched to a custom kernel for those layers so it was moot, I just raised the issue because i found it was slow.

I'll re-try the naive path tonight and let you know

@ricardoV94

Copy link
Copy Markdown
Member Author

I switched to a custom kernel for those layers so it was moot, I just raised the issue because i found it was slow.

I'll re-try the naive path tonight and let you know

If the layer is literally a max it's probably one of those you'd want to fuse with whatever produces it

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.

numba max reduction is 10x slower than sum on the same array

2 participants