Skip to content

[nnx] don't share Rngs #4754

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

Open
wants to merge 1 commit into
base: nnx-optax-optimizer
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: 4 additions & 2 deletions flax/nnx/nn/attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def __init__(
dot_general_cls=self.out_dot_general_cls,
rngs=rngs,
)
self.rngs = rngs if keep_rngs and dropout_rate > 0 else None
self.rngs = rngs.fork() if keep_rngs and dropout_rate > 0 else None

self.cached_key: nnx.Cache[Array] | None = None
self.cached_value: nnx.Cache[Array] | None = None
Expand All @@ -454,7 +454,7 @@ def __call__(
*,
mask: Array | None = None,
deterministic: bool | None = None,
rngs: rnglib.Rngs | None = None,
rngs: rnglib.Rngs | jax.Array | None = None,
sow_weights: bool = False,
decode: bool | None = None,
):
Expand Down Expand Up @@ -493,6 +493,8 @@ def __call__(
"""
if rngs is None:
rngs = self.rngs
elif isinstance(rngs, jax.Array):
rngs = rnglib.Rngs(rngs)

if inputs_k is None:
if inputs_v is not None:
Expand Down
Loading