Skip to content

[Feature] Define versioned external draft feature contract - #452

Closed
0z5a wants to merge 3 commits into
vllm-project:0z5a-branchfrom
0z5a:feature/external-draft-feature-contract
Closed

0z5a wants to merge 3 commits into
vllm-project:0z5a-branchfrom
0z5a:feature/external-draft-feature-contract

Conversation

@0z5a

@0z5a 0z5a commented Sep 27, 2026 •

Copy link
Copy Markdown

Incremental review: Files changed.

Base: 0z5a-branch at 791f101e20db377b28e15f12a00863baaea2605f.

Define a versioned, collect-only external-draft feature manifest and causal token map. The schema records target/head versions, model/tokenizer identity and readiness so a consumer can reject incomplete or incompatible batches.

Validation Result
CPU contract checks 12 passed
Ruff / format Passed
Standalone B1 CUDA / model E2E / speed comparison Not run

The collector and its real-model validation are in #454. This layer defines the schema; draft optimization and weight publication require further implementation. Test harnesses and audit reports were removed from the submitted diff.

Signed-off-by: 0z5a <0z5a@users.noreply.github.com>
@read-the-docs-community

read-the-docs-community Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a version and token alignment contract for collect-only draft features, defining data schemas and validation rules for sequences, tokens, and feature manifests, along with corresponding unit tests and documentation. The feedback highlights a potential type mismatch bug when validating sequence offsets against deserialized lists, and suggests improving validation robustness by providing more specific error messages and enforcing strict ordering of selected tokens by their packed positions.

offsets = [0]
for sequence in self.sequences:
offsets.append(offsets[-1] + len(sequence.token_ids))
if tuple(offsets) != self.sequence_offsets or not self.selected_tokens:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Comparing a tuple directly to a list (e.g., tuple(offsets) != self.sequence_offsets) will always evaluate to True in Python because their types differ. Since sequence_offsets is often deserialized as a list from JSON payloads, this direct comparison will cause valid token maps to fail validation. Converting self.sequence_offsets to a tuple before comparison resolves this issue.

Suggested change
if tuple(offsets) != self.sequence_offsets or not self.selected_tokens:
if tuple(offsets) != tuple(self.sequence_offsets) or not self.selected_tokens:

Comment on lines +46 to +57
for token in self.selected_tokens:
if token.sample_id not in samples:
raise ValueError("selected token references an unknown sample")
sequence, start = samples[token.sample_id]
position = token.token_position
if position < 0 or position >= len(sequence.token_ids) - 1 or sequence.loss_mask[position] != 1:
raise ValueError("selected token does not match its source sequence")
if token.packed_position != start + position or token.target_token_id != sequence.token_ids[position + 1]:
raise ValueError("selected token does not match its source sequence")
if (token.sample_id, position) in selected:
raise ValueError("selected token does not match its source sequence")
selected.add((token.sample_id, position))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This block has two opportunities for improvement:\n1. Specific Error Messages: Multiple distinct validation checks raise the exact same generic error message: "selected token does not match its source sequence". This makes debugging extremely difficult. Providing more specific error messages for each failure mode (while retaining the substring "source sequence" to keep existing tests passing) greatly improves maintainability.\n2. Enforce Ordering: There is currently no check to ensure that selected_tokens are strictly ordered by their packed_position. Since downstream consumers likely expect ordered tokens for sequential indexing/slicing, we should enforce that token.packed_position is strictly increasing.

        last_packed = -1\n        for token in self.selected_tokens:\n            if token.sample_id not in samples:\n                raise ValueError(f"selected token references an unknown sample_id: {token.sample_id}")\n            sequence, start = samples[token.sample_id]\n            position = token.token_position\n            if position < 0 or position >= len(sequence.token_ids) - 1 or sequence.loss_mask[position] != 1:\n                raise ValueError(f"selected token position {position} does not match its source sequence mask or bounds")\n            if token.packed_position != start + position or token.target_token_id != sequence.token_ids[position + 1]:\n                raise ValueError(f"selected token packed position or target does not match its source sequence")\n            if (token.sample_id, position) in selected:\n                raise ValueError(f"duplicate selected token does not match its source sequence uniqueness constraint")\n            if token.packed_position <= last_packed:\n                raise ValueError("selected tokens must be strictly ordered by packed position")\n            selected.add((token.sample_id, position))\n            last_packed = token.packed_position

Signed-off-by: 0z5a <0z5a@users.noreply.github.com>
Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>
@0z5a

0z5a commented Oct 6, 2026

Copy link
Copy Markdown
Author

Superseded by #454, now merged into 0z5a-branch. The consolidated implementation and validation are retained there; closing this duplicate PR.

@0z5a 0z5a closed this Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant