Skip to content

Commit f1aef53

Browse files
committed
Replace assert with explicit ValueError for shape validation
Use explicit if/raise instead of assert to ensure shape validation is not stripped when Python runs with -O flag in production. Signed-off-by: dongbo910220 <1275604947@qq.com>
1 parent 8afa06d commit f1aef53

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

vllm/v1/spec_decode/medusa.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ def propose(
4747
# Shape: [batch_size, num_heads]
4848
draft_tokens = torch.stack([logit.argmax(dim=-1) for logit in logits], dim=1)
4949

50-
# Sanity check to catch any unexpected shape mismatch early
50+
# Always validate shape (avoid assert being stripped by -O)
5151
batch_size = target_hidden_states.shape[0]
5252
num_heads = len(logits)
53-
assert draft_tokens.shape == (
54-
batch_size,
55-
num_heads,
56-
), f"Expected shape ({batch_size}, {num_heads}), got {draft_tokens.shape}"
53+
if draft_tokens.shape != (batch_size, num_heads):
54+
raise ValueError(
55+
f"Expected shape ({batch_size}, {num_heads}), got {draft_tokens.shape}"
56+
)
5757

5858
return draft_tokens
5959

0 commit comments

Comments
 (0)