Skip to content
Open
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
10 changes: 10 additions & 0 deletions flax/nnx/nn/attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ def dot_product_attention_weights(
Returns:
Output of shape `[batch..., num_heads, q_length, kv_length]`.
"""
if not (0.0 <= dropout_rate < 1.0):
raise ValueError(
f'dropout_rate must be in the range [0, 1), got {dropout_rate!r}. '
'A negative or NaN value silently disables dropout without regularizing.'
)
if not deterministic and dropout_rate > 0.0 and dropout_rng is None:
raise ValueError(
'dropout_rng must be provided when dropout_rate > 0.0 and '
'deterministic=False. Pass a JAX PRNGKey as dropout_rng.'
)
query, key = promote_dtype((query, key), dtype=dtype) # type: ignore[bad-unpacking]
dtype = query.dtype

Expand Down
Loading