[Model][ROCm] Enable DeepSeek V4 Vision (#55107)
Signed-off-by: Andreas Karatzas <Andreas.Karatzas@amd.com> Signed-off-by: Andreas Karatzas <akaratza@amd.com> Co-authored-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
co-authored by
OpenAI Codex
parent
127143e27f
commit
9dd969da09
@@ -336,6 +336,101 @@ def test_compute_global_topk_ragged_indices_and_indptr() -> None:
|
||||
torch.testing.assert_close(actual_lens, expected_lens)
|
||||
|
||||
|
||||
@torch.inference_mode()
|
||||
def test_combine_topk_swa_indices_adds_image_visibility() -> None:
|
||||
from vllm.models.deepseek_v4.amd.rocm import combine_topk_swa_indices
|
||||
|
||||
device = torch.device("cuda")
|
||||
num_tokens = 8
|
||||
topk_indices = torch.full((num_tokens, 1), -1, dtype=torch.int32, device=device)
|
||||
query_start_loc = torch.tensor([0, num_tokens], dtype=torch.int32, device=device)
|
||||
seq_lens = torch.tensor([num_tokens], dtype=torch.int32, device=device)
|
||||
gather_lens = seq_lens.clone()
|
||||
left_visible = torch.tensor(
|
||||
[0, 0, 0, 1, 2, 3, 4, 0], dtype=torch.int32, device=device
|
||||
)
|
||||
right_visible = torch.tensor(
|
||||
[0, 0, 4, 3, 2, 1, 0, 0], dtype=torch.int32, device=device
|
||||
)
|
||||
|
||||
indices, lens = combine_topk_swa_indices(
|
||||
topk_indices,
|
||||
query_start_loc,
|
||||
seq_lens,
|
||||
gather_lens,
|
||||
window_size=4,
|
||||
compress_ratio=1,
|
||||
topk=0,
|
||||
M=16,
|
||||
N=0,
|
||||
max_image_tokens=5,
|
||||
left_visible=left_visible,
|
||||
right_visible=right_visible,
|
||||
)
|
||||
|
||||
expected_rows = [
|
||||
[0],
|
||||
[0, 1],
|
||||
[0, 1, 2, 3, 4, 5, 6],
|
||||
[0, 1, 2, 3, 4, 5, 6],
|
||||
[1, 2, 3, 4, 5, 6],
|
||||
[2, 3, 4, 5, 6],
|
||||
[2, 3, 4, 5, 6],
|
||||
[4, 5, 6, 7],
|
||||
]
|
||||
for token_idx, expected in enumerate(expected_rows):
|
||||
actual = indices[token_idx, : lens[token_idx]].cpu().tolist()
|
||||
assert actual == expected
|
||||
|
||||
|
||||
@torch.inference_mode()
|
||||
def test_combine_topk_swa_indices_apc_hit_inside_image() -> None:
|
||||
from vllm.models.deepseek_v4.amd.rocm import combine_topk_swa_indices
|
||||
|
||||
device = torch.device("cuda")
|
||||
indices, lens = combine_topk_swa_indices(
|
||||
torch.full((2, 1), -1, dtype=torch.int32, device=device),
|
||||
torch.tensor([0, 2], dtype=torch.int32, device=device),
|
||||
torch.tensor([10], dtype=torch.int32, device=device),
|
||||
# Only positions [5, 10) exist in the gathered SWA workspace.
|
||||
torch.tensor([5], dtype=torch.int32, device=device),
|
||||
window_size=4,
|
||||
compress_ratio=1,
|
||||
topk=0,
|
||||
M=10,
|
||||
N=0,
|
||||
max_image_tokens=10,
|
||||
left_visible=torch.tensor([8, 9], dtype=torch.int32, device=device),
|
||||
# Deliberately extends beyond seq_len to exercise the upper clamp too.
|
||||
right_visible=torch.tensor([5, 5], dtype=torch.int32, device=device),
|
||||
)
|
||||
|
||||
assert lens.cpu().tolist() == [5, 5]
|
||||
assert indices[:, :5].cpu().tolist() == [list(range(5)), list(range(5))]
|
||||
|
||||
|
||||
@torch.inference_mode()
|
||||
def test_combine_topk_swa_indices_keeps_vision_row_width_without_images() -> None:
|
||||
from vllm.models.deepseek_v4.amd.rocm import combine_topk_swa_indices
|
||||
|
||||
device = torch.device("cuda")
|
||||
indices, lens = combine_topk_swa_indices(
|
||||
torch.full((1, 1), -1, dtype=torch.int32, device=device),
|
||||
torch.tensor([0, 1], dtype=torch.int32, device=device),
|
||||
torch.tensor([1], dtype=torch.int32, device=device),
|
||||
torch.tensor([1], dtype=torch.int32, device=device),
|
||||
window_size=120,
|
||||
compress_ratio=1,
|
||||
topk=0,
|
||||
M=256,
|
||||
N=0,
|
||||
max_image_tokens=16,
|
||||
)
|
||||
|
||||
assert indices.shape == (1, 256)
|
||||
assert lens.item() == 1
|
||||
|
||||
|
||||
def test_extra_cache_nan_free_provenance_gate(monkeypatch) -> None:
|
||||
from vllm.models.deepseek_v4.amd import rocm as mod
|
||||
|
||||
|
||||
Reference in New Issue
Block a user