Expose speculative draft proposals through runtime APIs - #2493
Open
Tianlei Wu (tianleiwu) wants to merge 4 commits into
Open
Expose speculative draft proposals through runtime APIs#2493Tianlei Wu (tianleiwu) wants to merge 4 commits into
Tianlei Wu (tianleiwu) wants to merge 4 commits into
Conversation
This was referenced Aug 28, 2026
Tianlei Wu (tianleiwu)
force-pushed
the
tlwu/20260828/runtime-spec-api
branch
from
August 29, 2026 00:02
0b37dce to
57b52d5
Compare
Tianlei Wu (tianleiwu)
force-pushed
the
tlwu/20260828/runtime-spec-api
branch
from
August 29, 2026 08:45
57b52d5 to
6cd7e94
Compare
Tianlei Wu (tianleiwu)
force-pushed
the
tlwu/20260828/runtime-spec-api
branch
from
August 29, 2026 17:03
6cd7e94 to
3ad848f
Compare
Tianlei Wu (tianleiwu)
marked this pull request as ready for review
August 29, 2026 17:04
Contributor
There was a problem hiding this comment.
Pull request overview
This PR exposes speculative draft token proposals through the public runtime APIs (C/C++/Python) and integrates draft verification into the dynamic batching engine, including a fast-path that verifies contiguous draft rows via a single device argmax and a stop-token safeguard to preserve turn-completion semantics.
Changes:
- Add runtime APIs to set per-step speculative draft proposals and query engine draft support/limits.
- Update dynamic scheduling/resource planning to account for draft-driven step length and cache needs.
- Optimize draft verification with a contiguous-row device argmax path, retain host fallback, and add engine test coverage for drafted stop-token behavior.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/cpp/engine/engine_step_tests.cpp | Adds a regression test ensuring drafted stop tokens do not bypass normal end-of-turn handling. |
| src/python/python.cpp | Exposes Request.set_draft_tokens and Engine.max_draft_tokens_per_step in Python bindings. |
| src/ort_genai.h | Adds C++ RAII wrapper methods for setting draft tokens and querying max draft tokens per step. |
| src/ort_genai_c.h | Adds C API declarations + documentation for draft-token proposals and engine draft-limit query. |
| src/ort_genai_c.cpp | Implements the new C API entry points for draft proposals and max-draft query. |
| src/engine/scheduler.cpp | Plans cache capacity for base token + drafts before final token budgeting is applied. |
| src/engine/scheduled_requests.cpp | Adds a device argmax fast-path for draft verification and stop-token rejection in draft prefix acceptance. |
| src/engine/request.h | Adds stop-token query and refactors staging boundary tracking for transaction sampling. |
| src/engine/request.cpp | Implements stop-token detection and refactors transaction sampling boundary handling to match draft semantics. |
| src/engine/decoders/varlen_decoder_io.cpp | Improves the error message when draft verification is attempted with non-per-token logits. |
Suppressed comments (1)
src/ort_genai_c.cpp:1470
- The OGA_TRY macro is placed on the same line as the function signature here, unlike the rest of this file (where OGA_TRY starts on its own line). This looks like an accidental formatting regression and makes the C API wrapper harder to read.
OgaResult* OgaRequestHasUnseenTokens(const OgaRequest* request, bool* out) { OGA_TRY
*out = request->HasUnseenTokens();
return nullptr;
OGA_CATCH
}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Tianlei Wu (tianleiwu)
force-pushed
the
tlwu/20260828/runtime-spec-api
branch
from
August 29, 2026 21:52
3ad848f to
3c02645
Compare
Tianlei Wu (tianleiwu)
force-pushed
the
tlwu/20260828/runtime-spec-api
branch
from
August 30, 2026 06:41
3c02645 to
283f985
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Expose speculative draft proposals through the runtime APIs and verify them within the dynamic batching engine. The verify path preserves request transaction boundaries and uses one batched device argmax for contiguous logits rows, with the existing host path retained as a compatibility fallback.
Stack
Depends on #2491.
This runtime change does not depend on an ONNX Runtime version bump.
Changes
Testing
cmake --build build/Linux/Debug --parallel $(nproc) ./build/Linux/Debug/engine_unit_tests286 tests passed.
The built Python module also exposes
Request.set_draft_tokensandEngine.max_draft_tokens_per_step.