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
33 changes: 32 additions & 1 deletion tests/jax/test_fused_attn.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# See LICENSE for license information.
"""Tests for fused attention"""
import os
import sys
from enum import Enum, auto
from dataclasses import dataclass, field
from functools import partial
Expand Down Expand Up @@ -224,7 +225,7 @@ def make_mask(
segment_pos_q,
segment_pos_kv,
window_size,
dtype=jnp.bool,
dtype=jnp.bool_,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We seem to have a few other call sites of jnp.bool? If it's deprecated, could we fix those ones as well? Thanks.

I think we can get away with the test as well.

segment_ids_q=segment_ids_q,
segment_ids_kv=segment_ids_kv,
)
Expand All @@ -236,6 +237,36 @@ def make_mask(
return mask


def test_make_mask_bottom_right_swa_dtype(monkeypatch):
"""Regression test: make_mask bottom-right branch should use jnp.bool_, not jnp.bool."""
captured_dtypes = []
mod = sys.modules[make_mask.__module__]
original_make_swa_mask = mod.make_swa_mask

def _captured_make_swa_mask(*args, **kwargs):
captured_dtypes.append(kwargs.get("dtype"))
return original_make_swa_mask(*args, **kwargs)

monkeypatch.setattr(mod, "make_swa_mask", _captured_make_swa_mask)

batch, seqlen = 2, 16
segment_ids = jnp.ones((batch, seqlen), dtype=jnp.int32)
segment_pos = jnp.broadcast_to(jnp.arange(seqlen, dtype=jnp.int32), (batch, seqlen))
window_size = (4, 0)
mask = make_mask(
segment_ids,
segment_ids,
segment_pos,
segment_pos,
AttnMaskType.PADDING_CAUSAL_BOTTOM_RIGHT_MASK,
window_size,
)
assert mask.dtype == jnp.bool_
Comment thread
greptile-apps[bot] marked this conversation as resolved.
assert (
jnp.bool_ in captured_dtypes
), "bottom-right sliding-window mask should be built with jnp.bool_"


@jax.jit
def get_seqlens_and_offsets(segment_ids):
batch, max_seqlen = segment_ids.shape
Expand Down