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
19 changes: 18 additions & 1 deletion tests/jax/test_distributed_fused_attn.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ def test(self, cp_size, shape, qkv_format, reorder_strategy, stripe_size):
seq_dim = 0

if reorder_strategy == ReorderStrategy.Striped:
seq_lens = shape[seq_dim]
seq_lens = tensor.shape[seq_dim]
if seq_lens < (cp_size * stripe_size):
pytest.skip(f"{seq_lens=} must be larger than {cp_size*stripe_size=}")

Expand All @@ -681,3 +681,20 @@ def test(self, cp_size, shape, qkv_format, reorder_strategy, stripe_size):
inversed = inverse(reordered, reorder_strategy, cp_size, seq_dim, stripe_size)

assert jnp.array_equal(inversed, ref)

@pytest.mark.parametrize("stripe_size", [1, 4])
def test_sbhd_striped_uses_swapped_seq_dim(self, stripe_size):
"""Regression test: SBHD Striped skip must use the swapped sequence dim."""
cp_size = 2
shape = (1, 16, 1, 1) # original [batch, seq, heads, dim]
tensor = random.normal(random.PRNGKey(42), shape, dtype=jnp.bfloat16)
tensor = tensor.swapaxes(0, 1) # SBHD: [seq, batch, heads, dim]

# Old logic read original shape[0]=1 (batch) and skipped; seq_len after swap is 16.
reorder = jax.jit(reorder_causal_load_balancing, static_argnums=[1, 2, 3, 4])
inverse = jax.jit(inverse_reorder_causal_load_balancing, static_argnums=[1, 2, 3, 4])

reordered = reorder(tensor, ReorderStrategy.Striped, cp_size, 0, stripe_size)
inversed = inverse(reordered, ReorderStrategy.Striped, cp_size, 0, stripe_size)

assert jnp.array_equal(inversed, tensor)
Comment on lines +685 to +700

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Regression test bypasses skip logic

This test calls the reorder and inverse functions directly instead of exercising the changed skip branch, so reverting tensor.shape[seq_dim] to the original expression leaves it green and allows the erroneous loss of SBHD Striped coverage to recur undetected.

Knowledge Base Used: Tests and QA

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!