You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add structured ranking and decision runtime APIs - #2649
Add production-oriented non-generative inference for multi-component CLM ranking and KEV decision packages without routing them through the autoregressive Generator API.
The public surface is intentionally small: one package-selected session, configured through the existing OgaConfig, with a JSON request/response boundary.
OgaConfig remains the source of truth for the package path, providers, provider options, hardware selection, overlays, session options, tokenizer settings, pad token, and context length. The session copies the effective configuration during construction.
Supported workflows
CLM free ranking
Request:
{
"state": {},
"instructions": "Choose the best candidate",
"temperature": 1.0,
"candidates": {
"candidate-a": {},
"candidate-b": {}
}
}
The package contents select the private ranking or decision implementation. No public component-session, recursive-value, cache-control, prefix-control, benchmark, or model-specific handle families are introduced.
Runtime architecture
Loads and validates a component manifest once into an immutable package record.
Supports Mobius and Model Builder CLM/KEV component layouts.
Reuses existing ORT GenAI Config, Tokenizer, Tensor, NamedTensors, provider, and session-option infrastructure.
Runs one private ORT session per named component.
Applies normal thread defaults, provider options, path resolution, and custom-op registration to every component session.
Keeps CLM projection caches and KEV token/prefix caches private, bounded, and session-local.
Serializes execution and cache mutation per session.
Disables CUDA graph capture for component sessions until cross-component capture is qualified.
Reliability and portability
Enforces configured context limits without silently truncating requests.
Prevents fused CLM buckets from exceeding model capacity.
Uses stable double-precision softmax for extreme valid temperatures.
Preserves insertion order and integer-versus-floating-point JSON semantics.
Use UTF-8 conversion for manifest component filenames
src/models/component_session.cpp:90
Manifest filenames are JSON UTF-8 strings, but this narrow std::filesystem::path construction uses the platform-native narrow encoding on Windows. A valid non-ASCII component filename can therefore fail validation even though the later fs::path(entry.filename) conversion is UTF-8-aware; use an explicit UTF-8 filesystem conversion for this safety check.
Convert UTF-8 package paths before filesystem operations
src/models/non_generative_session.cpp:36
package_path is the UTF-8 path accepted by the public API, but constructing std::filesystem::path directly from its narrow string is not Unicode-safe on Windows and can make session creation fail for non-ASCII package directories. The repository’s established conversion uses the platform-correct representation (src/models/model_package.cpp:19-23); convert from UTF-8 explicitly before canonicalizing.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for simplifying this. I reviewed this revision with two independent reviewers. The API is much smaller now, and the main layering concern is addressed: the new Python binding calls the public C++ wrapper, which calls the C API. It does not call private ranking, decision, or component classes. The older private ORT header include in python.cpp was already present before this PR.
Reusing Config, Tokenizer, Tensor, NamedTensors, and the existing error and string ownership rules is the right direction. We did not find a new ownership problem at the binding boundary. I do not think another broad redesign is needed.
I suggest fixing two things before merging: component sessions should honor the existing configuration rules, and CLM should honor its configured context limit. The inline comments explain both and suggest small fixes. The other comments cover API clarity, documentation/tests, and a smaller internal cleanup; those are not equivalent runtime blockers.
Header, adapter, and public-only binding-fragment compilation checks passed across the reviews. We did not run fresh native model inference for this revision, and CI was still pending. This review does not establish model accuracy, CUDA correctness, or performance.
## Summary
Optimize private CLM/KEV request tokenization without expanding the
public non-generative API.
## Changes
- Add an internal `Tokenizer::EncodeBatchRows` adapter over ORT
Extensions batch tokenization.
- Preserve ragged token rows so CLM masks, positions, and context-limit
validation use each original sequence length.
- Reuse the same batch primitive in existing padded `EncodeBatch`
overloads.
- Batch CLM structured text tokenization instead of invoking the
tokenizer once per row.
- Preserve literal-tokenizer behavior and reject null batch entries
explicitly.
## API surface
No new public C, C++, or Python APIs are added. The runtime continues to
expose:
- `OgaCreateNonGenerativeSession`
- `OgaDestroyNonGenerativeSession`
- `OgaNonGenerativeSessionRunJson`
- C++ and Python `NonGenerativeSession`
Graph capture, cache controls, action sidecars, component tensor
handles, and public tokenizer APIs remain outside this change.
## Validation
- ORT GenAI native library, Python extension, and unit-test targets
build.
- Focused native non-generative tests pass.
- Python non-generative tests pass.
- Ruff and diff checks pass.
- Real CLM and KEV package E2E passes with ONNX Runtime 1.31.
## Dependency
Stacked on #2649.
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
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
Add production-oriented non-generative inference for multi-component CLM ranking and KEV decision packages without routing them through the autoregressive
GeneratorAPI.The public surface is intentionally small: one package-selected session, configured through the existing
OgaConfig, with a JSON request/response boundary.Public API
The C ABI adds three exports:
The C++ API provides one move-only RAII wrapper:
NonGenerativeSession session{config}; std::string response = session.Run(request_json);Python follows the same model:
OgaConfigremains the source of truth for the package path, providers, provider options, hardware selection, overlays, session options, tokenizer settings, pad token, and context length. The session copies the effective configuration during construction.Supported workflows
CLM free ranking
Request:
{ "state": {}, "instructions": "Choose the best candidate", "temperature": 1.0, "candidates": { "candidate-a": {}, "candidate-b": {} } }Result:
{ "model": "clm", "ranked": [ {"rank": 1, "key": "candidate-a", "probability": 0.75}, {"rank": 2, "key": "candidate-b", "probability": 0.25} ] }KEV typed decisions
Request:
{ "state": {}, "questions": { "question-id": { "type": "noul", "instructions": "Should this action be taken?", "criteria": {} } } }Result:
{ "model": "kev", "answers": { "question-id": { "type": "noul", "noul": 0.75, "confidence": 0.5 } } }The package contents select the private ranking or decision implementation. No public component-session, recursive-value, cache-control, prefix-control, benchmark, or model-specific handle families are introduced.
Runtime architecture
Config,Tokenizer,Tensor,NamedTensors, provider, and session-option infrastructure.Reliability and portability
com.microsoft::LinearAttentionGate.Validation
Notes
genai_config.json.component_manifest.jsonis authoritative when present; exact released CLM/KEV layouts remain supported for compatibility.