Skip to content
Merged
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
21 changes: 21 additions & 0 deletions tests/kernels/test_mhc_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,27 @@ def forward(hidden, positions, ids, pre, post, res, residual, **kwargs):
)


@pytest.mark.skipif(not current_platform.is_cuda(), reason="CUDA required")
@pytest.mark.parametrize("num_tokens", [1, 7, 32])
@pytest.mark.parametrize("tp_size", [4, 8])
def test_hc_collapse_before_gather_is_bitwise_equal(num_tokens, tp_size):
"""Simulate SP on one GPU, including padding and ranks without valid tokens."""
set_random_seed(0)
padded_tokens = num_tokens + (-num_tokens) % tp_size
streams = torch.randn(padded_tokens, 4, 5120, dtype=torch.bfloat16, device=DEVICE)
pre_mix = torch.rand(padded_tokens, 4, device=DEVICE)
stream_shards = streams.chunk(tp_size)
mix_shards = pre_mix.chunk(tp_size)
before = hc_collapse_triton(
torch.cat(stream_shards)[:num_tokens], torch.cat(mix_shards)[:num_tokens]
)
after = torch.cat(
[hc_collapse_triton(x, pre) for x, pre in zip(stream_shards, mix_shards)]
)[:num_tokens]
assert after.shape == (num_tokens, 5120)
torch.testing.assert_close(after, before, atol=0, rtol=0)


@pytest.mark.skipif(not HAS_TILELANG_MHC, reason="TileLang MHC support required")
@pytest.mark.parametrize(
"num_tokens,sinkhorn_repeat,norm_eps",
Expand Down
5 changes: 2 additions & 3 deletions vllm/models/deepseek_v41/nvidia/dspark.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,14 @@ def forward(
residual,
)
hidden_states = mhc_post_tilelang(hidden_states, residual, post_mix, res_mix)
if self.use_sequence_parallel:
hidden_states = sp_all_gather(hidden_states)[:full_num_tokens]
pre_mix = sp_all_gather(pre_mix)[:full_num_tokens]
# Collapse the hc copies with the pre-mix from the last layer's FFN
# mixes — the mix the reference forward_head applies (hc_pre with the
# last block's ffn pre-mix). Return the PRE-norm head hidden;
# compute_logits applies self.norm.
assert pre_mix is not None
hidden_states = hc_collapse_triton(hidden_states, pre_mix)
if self.use_sequence_parallel:
hidden_states = sp_all_gather(hidden_states)[:full_num_tokens]
return hidden_states


Expand Down
Loading