Skip to content

Commit 559fe54

Browse files
committed
test(dsv4): disable sa_block_kv hardware grid padding to secure unmasked reference numerical parity
1 parent e45d4ff commit 559fe54

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

tests/unit/deepseek_v4_vs_reference_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,6 +1831,12 @@ def test_attention_layer_parity(self):
18311831
layer_types=["heavily_compressed_attention"] * 10,
18321832
o_groups=config.o_groups,
18331833
o_lora_rank=config.o_lora_rank,
1834+
# Disabling hardware MXU grid alignment padding (sa_block_kv=0).
1835+
# By default, AttentionOp enforces sa_block_kv=512 grid bounds, automatically padding trailing sequence length
1836+
# (S=128 + W=32 = 160) to 512 with zero vectors. Under dot-product attention without explicit causal padding masks
1837+
# (attention_mask=None), Softmax evaluates unmasked zero vectors to positive probability weightings (e^{0.0} = 1.0),
1838+
# artificially inflating the local exponential normalizer sum denominator and distorting numerical parity bounds.
1839+
sa_block_kv=0,
18341840
)
18351841

18361842
devices = jax.devices()
@@ -2253,6 +2259,9 @@ def forward(self, input_ids: torch.Tensor, position_ids: torch.Tensor) -> torch.
22532259
index_topk=config_pt.index_topk,
22542260
mlp_activations=["silu", "linear"],
22552261
scan_layers=scan_mode,
2262+
# Explicitly disable hardware MXU grid sequence padding (sa_block_kv=0) to ensure dot-product Softmax
2263+
# normalization sums match unpadded PyTorch reference bounds precisely without exponential denominator drift.
2264+
sa_block_kv=0,
22562265
)
22572266
decoder_jax = NNXDecoder(config=jax_config, mesh=mesh, rngs=nnx.Rngs(0))
22582267

0 commit comments

Comments
 (0)