Skip to content

Commit e4457cf

Browse files
Add DSpark verification capacity modes
Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
1 parent dd127d8 commit e4457cf

36 files changed

Lines changed: 2222 additions & 137 deletions

tests/engine/test_arg_utils.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,43 @@ def test_jit_monitor_mode_arg(mode):
225225
assert engine_args.create_observability_config().jit_monitor_mode == mode
226226

227227

228+
def test_dspark_capacity_verification_mode_arg():
229+
parser = EngineArgs.add_cli_args(FlexibleArgumentParser())
230+
args = parser.parse_args(
231+
[
232+
"--spec-method",
233+
"ngram",
234+
"--spec-tokens",
235+
"1",
236+
"--dspark-capacity-verification-mode",
237+
"mask",
238+
]
239+
)
240+
241+
engine_args = EngineArgs.from_cli_args(args)
242+
assert engine_args.dspark_capacity_verification_mode == "mask"
243+
speculative_config = engine_args.create_speculative_config(None, None)
244+
assert speculative_config is not None
245+
assert speculative_config.dspark_capacity_verification_mode == "mask"
246+
247+
248+
def test_dspark_capacity_verification_mode_conflicts_with_speculative_config():
249+
parser = EngineArgs.add_cli_args(FlexibleArgumentParser())
250+
args = parser.parse_args(
251+
[
252+
"--speculative-config",
253+
'{"method":"ngram","num_speculative_tokens":1,'
254+
'"dspark_capacity_verification_mode":"mask"}',
255+
"--dspark-capacity-verification-mode",
256+
"varlen",
257+
]
258+
)
259+
260+
engine_args = EngineArgs.from_cli_args(args)
261+
with pytest.raises(ValueError, match="dspark_capacity_verification_mode"):
262+
engine_args.create_speculative_config(None, None)
263+
264+
228265
def test_hf_token_get_kwargs():
229266
kwargs = get_kwargs(ModelConfig)["hf_token"]
230267

tests/test_config.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,55 @@ def test_draft_sample_method_gumbel_is_rejected():
15721572
)
15731573

15741574

1575+
def test_dspark_capacity_config_validation():
1576+
speculative_config = SpeculativeConfig(
1577+
method="ngram",
1578+
num_speculative_tokens=1,
1579+
dspark_confidence_threshold=0.25,
1580+
dspark_budget_frac=0.5,
1581+
dspark_capacity_verification_mode="mask",
1582+
)
1583+
assert speculative_config.dspark_confidence_threshold == 0.25
1584+
assert speculative_config.dspark_budget_frac == 0.5
1585+
assert speculative_config.dspark_capacity_verification_mode == "mask"
1586+
assert (
1587+
SpeculativeConfig(
1588+
method="ngram", num_speculative_tokens=1
1589+
).dspark_capacity_verification_mode
1590+
== "varlen"
1591+
)
1592+
assert (
1593+
SpeculativeConfig(
1594+
method="ngram",
1595+
num_speculative_tokens=1,
1596+
dspark_capacity_verification_mode="compact",
1597+
).dspark_capacity_verification_mode
1598+
== "varlen"
1599+
)
1600+
assert (
1601+
SpeculativeConfig(
1602+
method="ngram", num_speculative_tokens=1
1603+
).dspark_confidence_threshold
1604+
== 0.0
1605+
)
1606+
1607+
for threshold in (-0.1, 1.1):
1608+
with pytest.raises(ValueError, match="dspark_confidence_threshold"):
1609+
SpeculativeConfig(
1610+
method="ngram",
1611+
num_speculative_tokens=1,
1612+
dspark_confidence_threshold=threshold,
1613+
)
1614+
1615+
for budget_frac in (0.0, -0.1, 1.1):
1616+
with pytest.raises(ValueError, match="dspark_budget_frac"):
1617+
SpeculativeConfig(
1618+
method="ngram",
1619+
num_speculative_tokens=1,
1620+
dspark_budget_frac=budget_frac,
1621+
)
1622+
1623+
15751624
def test_ir_op_priority_default():
15761625
"""Test that IR op priority defaults are set correctly."""
15771626
from vllm.config.kernel import IrOpPriorityConfig

tests/v1/spec_decode/test_rejection_sampler_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def test_stochastic_rejection_sample(num_speculative_steps: int, temperature: fl
150150

151151
torch.manual_seed(42)
152152
device = "cuda"
153-
num_trials = 10 * VOCAB_SIZE
153+
num_trials = 64
154154

155155
target_logits_1d = torch.randn(VOCAB_SIZE, device=device, dtype=torch.float32)
156156
draft_logits_1d = torch.randn(VOCAB_SIZE, device=device, dtype=torch.float32)
@@ -288,7 +288,7 @@ def test_placeholder_draft_token_rejected():
288288
"""
289289
torch.manual_seed(0)
290290
device = "cuda"
291-
num_trials = 64
291+
num_trials = 10 * VOCAB_SIZE
292292
K = 1
293293
temperature = 0.6
294294

tests/v1/worker/test_gpu_block_table.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import torch
66

77
from vllm.platforms import current_platform
8+
from vllm.v1.attention.backends.utils import PAD_SLOT_ID
89
from vllm.v1.worker.gpu.block_table import BlockTables
910

1011
pytestmark = pytest.mark.skipif(
@@ -130,3 +131,49 @@ def test_block_tables_apply_staged_writes_single_group():
130131
block_tables.block_tables[0].gpu[0, :2],
131132
torch.tensor([1, 2], dtype=torch.int32, device=device),
132133
)
134+
135+
136+
def test_compute_slot_mappings_applies_padding_mask():
137+
device = torch.device("cuda")
138+
block_tables = BlockTables(
139+
block_sizes=[16],
140+
max_num_reqs=2,
141+
max_num_batched_tokens=8,
142+
max_num_blocks_per_group=[4],
143+
device=device,
144+
kernel_block_sizes=[16],
145+
)
146+
147+
block_tables.append_block_ids(
148+
req_index=0,
149+
new_block_ids=([2],),
150+
overwrite=True,
151+
)
152+
block_tables.append_block_ids(
153+
req_index=1,
154+
new_block_ids=([3],),
155+
overwrite=True,
156+
)
157+
block_tables.apply_staged_writes()
158+
159+
idx_mapping = torch.tensor([0, 1], dtype=torch.int32, device=device)
160+
query_start_loc = torch.tensor([0, 3, 5], dtype=torch.int32, device=device)
161+
positions = torch.tensor([0, 1, 2, 0, 1], dtype=torch.int64, device=device)
162+
is_padding = torch.tensor(
163+
[False, True, False, False, True, False, False, False],
164+
dtype=torch.bool,
165+
device=device,
166+
)
167+
168+
slot_mappings = block_tables.compute_slot_mappings(
169+
idx_mapping,
170+
query_start_loc,
171+
positions,
172+
num_tokens_padded=8,
173+
is_padding=is_padding,
174+
)
175+
torch.accelerator.synchronize()
176+
177+
assert slot_mappings.cpu().tolist() == [
178+
[32, PAD_SLOT_ID, 34, 48, PAD_SLOT_ID, PAD_SLOT_ID, PAD_SLOT_ID, PAD_SLOT_ID]
179+
]

0 commit comments

Comments
 (0)