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

Remove unnecessary handling of no longer supported RandomState #1300

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pytensor/link/jax/linker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import warnings

from numpy.random import Generator, RandomState
from numpy.random import Generator

from pytensor.compile.sharedvalue import SharedVariable, shared
from pytensor.link.basic import JITLinker
Expand All @@ -21,7 +21,7 @@ def fgraph_convert(self, fgraph, input_storage, storage_map, **kwargs):

# Replace any shared RNG inputs so that their values can be updated in place
# without affecting the original RNG container. This is necessary because
# JAX does not accept RandomState/Generators as inputs, and they will have to
# JAX does not accept Generators as inputs, and they will have to
# be tipyfied
if shared_rng_inputs:
warnings.warn(
Expand Down Expand Up @@ -79,7 +79,7 @@ def create_thunk_inputs(self, storage_map):
thunk_inputs = []
for n in self.fgraph.inputs:
sinput = storage_map[n]
if isinstance(sinput[0], RandomState | Generator):
if isinstance(sinput[0], Generator):
new_value = jax_typify(
sinput[0], dtype=getattr(sinput[0], "dtype", None)
)
Expand Down
20 changes: 1 addition & 19 deletions pytensor/link/numba/linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,4 @@ def jit_compile(self, fn):
return jitted_fn

def create_thunk_inputs(self, storage_map):
from numpy.random import RandomState

from pytensor.link.numba.dispatch import numba_typify

thunk_inputs = []
for n in self.fgraph.inputs:
sinput = storage_map[n]
if isinstance(sinput[0], RandomState):
new_value = numba_typify(
sinput[0], dtype=getattr(sinput[0], "dtype", None)
)
# We need to remove the reference-based connection to the
# original `RandomState`/shared variable's storage, because
# subsequent attempts to use the same shared variable within
# other non-Numba-fied graphs will have problems.
sinput = [new_value]
thunk_inputs.append(sinput)

return thunk_inputs
return [storage_map[n] for n in self.fgraph.inputs]