Fix compact state configuration and staging - #2502
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aligns the engine/model-builder “decoder state manifest” schema with the decoder-IO-owned binding-template design (state group entries are now primarily kind + layer membership + per-group state_update geometry), and updates fixed-state staging so compact state replay/capture can reuse preallocated buffers rather than allocating after scheduling.
Changes:
- Updates the state group schema: moves binding templates to
model.decoder.inputs/model.decoder.outputs, splits fixed state kinds intofixed_convandfixed_recurrent, and simplifiesstate_updatefields to capacity/key-head geometry. - Updates Python builders, synthetic model generators/configs, and C++/Python tests to match the revised schema.
- Preallocates compact state-update staging in
FixedStatePooland uses tensor views inReserve(), updating persistent memory accounting and address-reuse tests.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/python/test_onnxruntime_genai_hybrid_engine.py | Updates expected fixed state group kinds in the hybrid fixture config assertions. |
| test/python/create/create_synthetic_paged_model.py | Updates synthetic paged config to use decoder IO templates and removes per-group KV bindings. |
| test/python/create/create_synthetic_hybrid_model.py | Updates synthetic hybrid config to use decoder IO templates; renames fixed group kinds; adjusts state_update schema usage. |
| test/python/create/create_synthetic_composite_model.py | Updates composite synthetic config and decoder IO templates; removes per-group bindings; updates state_update control placement. |
| test/python/builder/test_decoder_state_groups.py | Updates builder expectations for state group kinds and removes assertions for deprecated per-group bindings. |
| test/models/engine/synthetic-paged/genai_config.json | Updates stored synthetic paged model config to decoder-IO template schema. |
| test/models/engine/synthetic-hybrid/genai_config.json | Updates stored synthetic hybrid model config to decoder-IO template schema and fixed kind split. |
| test/models/engine/synthetic-composite/genai_config.json | Updates stored synthetic composite config to decoder-IO template schema and fixed kind split. |
| test/cpp/engine/paged_key_value_cache_tests.cpp | Updates manifest tests to use FixedConv kind and removes state binding construction that no longer exists. |
| test/cpp/engine/model_state_manifest_tests.cpp | Updates manifest construction/validation tests to use decoder IO templates and fixed kind split. |
| test/cpp/engine/fixed_state_pool_tests.cpp | Extends tests to cover reuse of preallocated compact state-update staging across reservation batch sizes and updates byte accounting expectations. |
| test/cpp/engine/dynamic_batching_config_tests.cpp | Updates JSON parsing/overlay tests to the new schema and fixed kind split. |
| src/python/py/models/builders/qwen.py | Updates Qwen builder emitted state group kinds and state_update payload shape to the new schema. |
| src/python/py/models/builders/base.py | Updates common builder to emit state groups without per-group bindings and adjusts paged-kv helper signature. |
| src/models/model_state_manifest.h | Stores decoder inputs/outputs in the manifest for binding resolution at validation time. |
| src/models/model_state_manifest.cpp | Resolves bindings from decoder IO templates, splits fixed kinds, derives state_update kind from group kind, and updates config/session validation accordingly. |
| src/engine/paged_key_value_cache.cpp | Resolves paged KV tensor names from decoder IO templates instead of per-group bindings. |
| src/engine/fixed_state_pool.cpp | Uses decoder IO templates for fixed state bindings; preallocates state_update staging and creates per-reservation tensor views over it. |
| src/config.h | Updates config schema types: removes per-group StateBinding, replaces Fixed with FixedConv/FixedRecurrent, simplifies StateUpdate payload. |
| src/config.cpp | Updates JSON parsing for new kinds/state_update fields and removes parsing for deprecated binding/state_update fields. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Tianlei Wu (tianleiwu)
enabled auto-merge (squash)
August 30, 2026 17:52
Baiju Meswani (baijumeswani)
approved these changes
Aug 30, 2026
Baiju Meswani (baijumeswani)
left a comment
Collaborator
There was a problem hiding this comment.
Looks good.
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.
Description
This follow-up addresses the two deferred review comments from #2454. It reapplies the decoder-I/O-owned state binding schema from #2463 and preallocates compact state-update staging so speculative fixed-state replay does not allocate device buffers after scheduling.
Summary of Changes
State Manifest Configuration
Fixed-State Staging
FixedStatePoolis constructed.Reserve()and retain their backing storage for the reservation lifetime.Testing
lintrunner -acmake --build build/cu130/Release --target engine_unit_tests -j $(nproc)build/cu130/Release/engine_unit_tests --gtest_color=no --gtest_filter='FixedStatePoolTest.*:CudaFixedStatePoolTest.*:DecoderStateGroupsConfigTest.*:ModelStateManifestTest.*:PagedKeyValueCacheTest.*'(65 passed)python3 -m pytest test/python/builder/test_decoder_state_groups.py -q --tb=short(25 passed)git diff --check origin/main...HEADChecklist