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

Add support for random Generators in Numba backend #691

Merged
merged 15 commits into from
May 29, 2024

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Apr 5, 2024

Description

TODO:

  • Merge code duplication into elemwise_codegen
  • Handle broadcast via size argument
  • Handle more than normal
  • Add expand_dims in make_node. This is actually something that ends up being useful in other places, as in vectorization and dim analysis. It also canonicalizes graphs that are equivalent, as the expand_dims is always implict
  • Handle non-scalar inputs / outputs. This would also solve Blockwise for Numba backend!
  • Find a way to copy RNGs if inplace=False. Not a huge priority, but a nice to have for consistency
  • Remove RandomState from codebase. I vote for no deprecation as this is functionality that was broken in Numba anyway (no way to reseed), and non-default for other backends.

Related Issue

Checklist

Type of change

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

@ricardoV94 ricardoV94 force-pushed the numba_generators branch 2 times, most recently from bfcb8e1 to caeaf02 Compare April 8, 2024 15:48
@ricardoV94 ricardoV94 changed the title First draft implementing Numba Generators with Elemwise iterator Add support for random Generators in Numba backend Apr 17, 2024
@ricardoV94
Copy link
Member Author

Size and rng copy are now supported

@ricardoV94 ricardoV94 force-pushed the numba_generators branch 4 times, most recently from 1aed284 to 769809e Compare April 23, 2024 02:52
@ricardoV94
Copy link
Member Author

@aseyboldt Elemwise is working again in case you want to benchmark before/after

@ricardoV94
Copy link
Member Author

ricardoV94 commented May 27, 2024

Here is a test snippet:

%env NUMBA_DISABLE_ERROR_MESSAGE_HIGHLIGHTING=1
import colorama
import pytensor
import pytensor.tensor as pt
import numpy as np

x = pt.vector("x", shape=(5,), dtype="float64")
out = pt.psi(x) * 2
fn = pytensor.function([x], out, mode="NUMBA")

x_test = np.random.uniform(size=5)
fn(x_test)

Not setting that variable will lead to the warning showing up (if colorama can be imported)

@ricardoV94
Copy link
Member Author

ricardoV94 commented May 27, 2024

Tests pass with a77df24

My only concern is that users with colorama will see the warning. I don't know how to filter that kind of messages, and also agree that filtering any NumbaWarning is a tad too much. Should we perhaps ask Numba to have a subclass for caching warnings? Perhaps that would be more reasonable to filter by default?

For clarity there's a sort of regression when we introduced the store_core_outputs for Elemwise, which now shows a colorized cache warning. The filtering of the numba_funcified_fgraph cache warning still works fine. I couldn't figure out why does one work but not the other.

@ricardoV94
Copy link
Member Author

Ok fixed with some regex, I was being tripped by multiple bold escape codes...

@ricardoV94 ricardoV94 marked this pull request as draft May 27, 2024 15:21
@ricardoV94
Copy link
Member Author

Marking as a draft because I want to merge a bugfix and do a release before this major changes get in

@aseyboldt
Copy link
Member

Sounds like you had a fun afternoon.
But that explains the strange failures....

@ricardoV94 ricardoV94 marked this pull request as ready for review May 29, 2024 12:07
@ricardoV94 ricardoV94 merged commit 5d4b0c4 into pymc-devs:main May 29, 2024
55 of 56 checks passed
@ricardoV94 ricardoV94 deleted the numba_generators branch May 29, 2024 12:08
@twiecki
Copy link
Member

twiecki commented May 30, 2024

Good one!

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