Skip to content

[TRTLLM-16316][feat] Generalize Runtime Sleep/Wakeup for LLM and trtllm-serve - #19016

Merged
Funatiq merged 29 commits into
NVIDIA:mainfrom
Funatiq:dev/release-resume
Oct 14, 2026
Merged

Funatiq merged 29 commits into
NVIDIA:mainfrom
Funatiq:dev/release-resume

Conversation

@Funatiq

@Funatiq Funatiq commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

Dev Engineer Review

  • Adds runtime-memory status, release, and resume APIs for synchronous LLM and asynchronous AsyncLLM.
  • Adds authenticated runtime-control routes and the trtllm-serve --enable_sleep_mode option.
  • Adds state and tag validation, transition handling, and V1 prefix-cache invalidation before destructive KV-cache sleep. KVCacheManagerV2 rejects KV-cache sleep pending a follow-up fix.
  • Verify authentication and replay protection, transition failure handling, and consistent behavior across sync, async, and Ray paths.
  • CI is unresolved: all eight helper jobs reported SUCCESS, but five corresponding L0 pipelines reported FAILURE and three reported UNSTABLE. The latest run reported UNSTABLE.

QA Engineer Review

  • Adds tests for runtime-control authentication and replay protection, runtime-memory APIs, sleep-mode CLI restrictions, Ray transition failures, prefix-cache invalidation, V2 rejection, request-queue snapshots, and collective RPC forwarding.
  • Adds CPU test-list entries for runtime-control, runtime-memory, and serve sleep-mode tests. Adds an H100 test-list entry for Ray sleep-state tests. No changed tests are shown in the manual-QA lists.
  • Coverage verdict: needs follow-up. CI reports failures and unstable runs; the latest run is unstable. Multi-GPU tests require the ci: full pre-merge approved label.

Per-File QA Perspective

  • docs/source/features/sleep-wakeup.md: Verify documented API defaults, restore modes, eligibility, and GMS exclusions against implementation behavior.
  • docs/source/index.rst: Verify the sleep/wakeup guide appears in the Features table of contents.
  • tensorrt_llm/_torch/async_llm.py: Verify async status reconciliation, tag normalization, and default release and resume behavior.
  • tensorrt_llm/_torch/pyexecutor/executor_request_queue.py: Verify status snapshots reflect admission state and parked tags atomically.
  • tensorrt_llm/_torch/pyexecutor/py_executor.py: Verify status reporting, V1 prefix-cache invalidation conditions, and V2 rejection.
  • tensorrt_llm/commands/serve.py: Verify sleep-mode backend and serving restrictions, API-key requirements, and default sleep configuration.
  • tensorrt_llm/executor/base_worker.py: Verify tag filtering, transition checks, retries, and prefix-cache invalidation before sleep.
  • tensorrt_llm/executor/proxy.py: Verify get_memory_status forwards correctly through multi-rank RPC.
  • tensorrt_llm/executor/ray/gpu_worker.py: Verify transition publication, abort behavior before mutation, and failed-state handling after mutation.
  • tensorrt_llm/llmapi/__init__.py: Verify the runtime-memory types are available through the public package exports.
  • tensorrt_llm/llmapi/llm.py: Verify synchronous API tag validation, status reconciliation, and default and explicit release/resume behavior.
  • tensorrt_llm/llmapi/llm_args.py: Verify allowed runtime-memory states and parked-tag ordering.
  • tensorrt_llm/serve/openai_protocol.py: Verify optional runtime-memory tag parsing and handling of omitted versus empty tags.
  • tensorrt_llm/serve/openai_server.py: Verify route enablement, authentication, sync/async dispatch, and HTTP error mapping.
  • tensorrt_llm/serve/runtime_control_auth.py: Verify request signing, timestamp checks, and replay-cache behavior.
  • tests/integration/test_lists/test-db/l0_cpu.yml: Adds CI entries for test_runtime_control.py, test_runtime_memory_api.py, and test_serve_sleep_mode.py.
  • tests/integration/test_lists/test-db/l0_h100.yml: Adds the Ray sleep-state test to the H100 CI list.
  • tests/unittest/_torch/executor/test_executor_request_queue.py: Covers parked-tag snapshots after partial restoration; listed in the CPU test list.
  • tests/unittest/_torch/multi_gpu/test_mpi_sleep_wakeup.py: Covers public release/resume and partial restoration; included in the multi-GPU test suite, whose CI requires the full pre-merge approval label.
  • tests/unittest/api_stability/references/llm.yaml: Adds API stability references for get_memory_status, release, and resume.
  • tests/unittest/api_stability/references/trtllm_serve_cli.yaml: Adds the --enable_sleep_mode CLI stability reference.
  • tests/unittest/executor/test_ray_sleep_state.py: Covers transition success and pre-/post-mutation failures; listed in the H100 test list.
  • tests/unittest/executor/test_sleep_collective_rpc_guards.py: Covers V2 rejection, V1 invalidation conditions, retry behavior, and collective RPC forwarding.
  • tests/unittest/llmapi/apps/test_anthropic_routes.py: Updates route-test setup for runtime-control endpoint state.
  • tests/unittest/llmapi/test_runtime_control.py: Covers authentication, replay and nonce handling, endpoint errors, and conflicting control configuration; listed in the CPU test list.
  • tests/unittest/llmapi/test_runtime_memory_api.py: Covers sync and async tag validation, status reconciliation, defaults, and no-op resume; listed in the CPU test list.
  • tests/unittest/llmapi/test_serve_sleep_mode.py: Covers sleep-mode restrictions, default configuration, and server authentication setup; listed in the CPU test list.
  • tests/unittest/llmapi/test_async_llm.py: Updates async release/resume coverage to exclude initialization-only memory types.

Description

  • Add documentation for Sleep and Wakeup feature.
  • Generalize API from AsyncLLM to sync LLM and trtllm-serve.
  • Fix KV cache manager V1: invalidate prefix cache before destructive sleep
  • Reject KV cache sleep with manager V2 for now. Clean fix is a follow-up.

Test Coverage

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

@Funatiq

Funatiq commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@Funatiq Funatiq changed the title [None][feat] Generalize Runtime Sleep/Wakeup for LLM and trtllm-serve [TRTLLM-16316][feat] Generalize Runtime Sleep/Wakeup for LLM and trtllm-serve Sep 10, 2026
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72713 [ run ] triggered by Bot. Commit: bdb26de Link to invocation

@Funatiq Funatiq added the api-compatible Accepted LLM API contract change that is backwards-compatible label Sep 10, 2026
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72713 [ run ] completed with state SUCCESS. Commit: bdb26de
/LLM/main/L0_MergeRequest_PR pipeline #59702 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@Funatiq

Funatiq commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72747 [ run ] triggered by Bot. Commit: 07e5e71 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72747 [ run ] completed with state SUCCESS. Commit: 07e5e71
/LLM/main/L0_MergeRequest_PR pipeline #59735 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@Funatiq

Funatiq commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72919 [ run ] triggered by Bot. Commit: 3377097 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72919 [ run ] completed with state SUCCESS. Commit: 3377097
/LLM/main/L0_MergeRequest_PR pipeline #59886 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@Funatiq

Funatiq commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72955 [ run ] triggered by Bot. Commit: 9899af1 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72955 [ run ] completed with state SUCCESS. Commit: 9899af1
/LLM/main/L0_MergeRequest_PR pipeline #59918 completed with status: 'UNSTABLE'

CI Report

⚠️ Multi-GPU Label Required:
Multi-GPU tests require the ci: full pre-merge approved label on this PR. Ask a member of NVIDIA/trt-llm-ci-approvers to add the label, then re-trigger CI with the same bot command (no rebase needed).

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@Funatiq
Funatiq marked this pull request as ready for review September 14, 2026 06:54
@Funatiq
Funatiq requested review from a team as code owners September 14, 2026 06:54
Enforce a five-minute signed timestamp window and atomically claim each accepted nonce in a server-scoped, lock-protected replay cache. Retain nonces for their complete validity interval, prune only expired entries, and fail closed when the bounded cache reaches capacity.

Validate signatures before consuming cache state and claim the nonce before dispatching the control action. Cover missing and malformed headers, past and future expiry, boundary timestamps, exact and changed-request replays, cache capacity and expiry, invalid-signature ordering, and concurrent duplicate requests. Document retry and replay-cache behavior.

Signed-off-by: Robin Kobus <[email protected]>
KV-cache allocations restored with NONE or MEMSET no longer contain the original cache data. V1 nevertheless retained its prefix-reuse metadata across sleep, allowing a later request to match blocks whose physical contents had been discarded or zeroed.

Clear the V1 prefix cache after the executor is quiesced and immediately before releasing tagged KV memory. Limit invalidation to enabled V1 block reuse, KV-cache releases, and destructive restore modes so CPU/PINNED preservation and V2 behavior remain unchanged.

Apply the hook to single-rank, MPI rank-zero and peer, and Ray sleep paths. Add CPU-only coverage for the mode/manager/reuse decision matrix and assertions that local and Ray sleep dispatch the invalidation hook.

Signed-off-by: Robin Kobus <[email protected]>
KVCacheManagerV2 owns its main pools through an allocator outside the tagged virtual-memory release path. Accepting a KV_CACHE sleep request therefore reported the cache as parked even though those pools remained resident.

Validate requested sleep tags at the worker boundary before beginning the admission transition or dispatching collective work. Reject KV_CACHE whenever manager V2 is active while preserving model-only V2 sleep and existing V1 behavior. Apply the validation consistently to local, MPI, and Ray workers.

Add coverage for V1 and V2 tag combinations, mixed model/KV requests, pre-transition rejection, and Ray validation dispatch.

Signed-off-by: Robin Kobus <[email protected]>
Add synchronous and asynchronous resume tests that pass a mix of string and enum memory tags, including a duplicate. Verify that each API queries runtime memory status before issuing wakeup and that wakeup receives the exact normalized, deduplicated tag list. This retains coverage of the required status RPC while exercising the explicit-tag path.

Signed-off-by: Robin Kobus <[email protected]>
Document in the KV_CACHE memory-tag entry that sleep requests are rejected when KV-cache manager V2 is enabled. This exposes the existing runtime limitation where users choose sleep tags.

Signed-off-by: Robin Kobus <[email protected]>
Replace the sleep control-action decorator with an explicit context entered after begin_sleep_transition. Concurrent submission threads must observe PARKING before the control sentinel is queued, so they cannot leave requests behind the sentinel that run after GPU memory is released.

Keep control-action entry and exit within the transition failure handler, restoring admission on pre-mutation failures and failing closed after memory mutation. Add regressions using the real admission queue and an independent submission thread, plus a drain-entry failure test.

Validation: 30 Ray sleep-state and request-queue tests pass using the repository Ray stub because Ray is unavailable locally. All applicable pre-commit checks pass.
Signed-off-by: Robin Kobus <[email protected]>
Add blocking collective_rpc dispatch to GenerationExecutorWorker so LLM release, get_memory_status, and resume work when the default orchestrator selects an in-process worker, including TP1 generation-logits gathering.

Reuse the MPI proxy guards for multi-rank methods and rank selection. Reject nonblocking dispatch explicitly and propagate worker errors. Add CPU regression coverage for the LLM call path, arguments, results, and dispatch guards.

Validation: 85 tests passed in test_sleep_collective_rpc_guards.py; pre-commit checks passed after formatting.
Signed-off-by: Robin Kobus <[email protected]>
Runtime-control nonces are retained in a frontend-local replay cache. A signed release consumed by one frontend can therefore be accepted by a sibling after a legitimate resume while the signature remains valid, parking the shared executor again.

Require a single frontend when runtime-control endpoints are enabled, both before server launch and when constructing OpenAIServer directly. Cover CLI, YAML, and --set frontend counts, synchronous and asynchronous generators, and replay rejection across a legitimate resume.

Validation: 42 focused tests passed; pre-commit checks passed. The existing autodeploy rejection test fails because the removed backend is rejected by Click before sleep-mode validation and was excluded from the passing run.
Signed-off-by: Robin Kobus <[email protected]>
AutoDeploy has been removed from the serving CLI. Remove the obsolete sleep-mode backend rejection test and its documentation reference while retaining the gRPC restriction.

Validation: all 8 sleep-mode tests passed.
Signed-off-by: Robin Kobus <[email protected]>
A release failure after memory mutation can leave admission failed before parked tags are published. Default resume previously treated the empty tag list as success and bypassed the worker state guard.

Validate the reconciled status in synchronous and asynchronous resume before normalizing tags. Reject parking, waking, and failed states using the worker error wording while preserving the running no-op and parked restore behavior.

Add CPU CI regression coverage for default and explicit tags with empty and populated parked tags. Validation: 86 memory API and serving tests passed.

Signed-off-by: Robin Kobus <[email protected]>
Validate the embedding server role in OpenAIServer before initializing the server or registering runtime-control routes. Embedding servers do not support the runtime-control endpoint lifecycle.

Add a CPU regression test with an encode-only LLM and otherwise valid runtime-control settings, asserting that construction raises ValueError before runtime-control route registration.

Validation: all 9 serve sleep-mode tests and pre-commit checks pass.
Signed-off-by: Robin Kobus <[email protected]>
TinyLlama selects KV cache manager V2 under the automatic default, but KV-cache sleep is unsupported by V2. Explicitly select V1 for the TP=2 KV-cache-only test so it exercises the supported release and resume path.

Validation: Python syntax parsing and git diff --check passed. GPU test was not run.
Signed-off-by: Robin Kobus <[email protected]>
Add a single-GPU TinyLlama test using KV cache manager V1 and block reuse. Tokenize a prompt longer than the configured KV block size and verify that warming the prompt reuses cached blocks without changing generated tokens.

Release and resume only the KV cache with restore mode NONE, then verify that the next request reuses no stale blocks and produces the same tokens as before release.

Validation: ruff lint and formatting, Python syntax parsing, and git diff --check passed. GPU execution is blocked by local bindings missing StreamingBlockRemovedData during TensorRT-LLM import.
Signed-off-by: Robin Kobus <[email protected]>
The MNNVL engine checkpoint coordination test constructs a PyExecutor with object.__new__, bypassing its constructor. The sleep listener calls invalidate_v1_prefix_cache_for_sleep, which reads _is_kv_manager_v2 and enable_kv_cache_reuse. The synthetic executor omitted both attributes, causing AttributeError on peer ranks during checkpoint coordination.

Initialize both flags to False in the test worker setup. The executor shell has no KV-cache reuse resources, so invalidation can safely return while the test continues to exercise the production coordinator, listener, and native MNNVL checkpoint hooks.

Validation: nine focused tests covering V1 prefix-cache invalidation and MNNVL sleep/wakeup coordination passed. Ruff lint, formatting, and git diff --check passed.

Signed-off-by: Robin Kobus <[email protected]>
@Funatiq
Funatiq force-pushed the dev/release-resume branch from 5f50224 to df782fd Compare October 12, 2026 14:58
@Funatiq

Funatiq commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #77297 [ run ] triggered by Bot. Commit: df782fd Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #77297 [ run ] completed with state SUCCESS. Commit: df782fd
/LLM/main/L0_MergeRequest_PR pipeline #63720 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@Barry-Delaney Barry-Delaney left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed df782fd after the rebase. Range-diff against the previously reviewed 92c93ca retains the 29-commit series; the differing patches adapt the serving imports/CLI signature, single-frontend launch wiring and MPI test context to main. The runtime control frontend guard and argument forwarding remain intact, and the prefix invalidation behavior is unchanged. No new blocking code finding. All 25 changed Python files parse and diff --check passes; GPU tests were not rerun locally.

@Funatiq

Funatiq commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #77505 [ run ] triggered by Bot. Commit: df782fd Link to invocation

@Funatiq

Funatiq commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #77670 [ run ] triggered by Bot. Commit: df782fd Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #77505 [ run ] completed with state ABORTED. Commit: df782fd

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #77670 [ run ] completed with state SUCCESS. Commit: df782fd
/LLM/main/L0_MergeRequest_PR pipeline #64030 completed with status: 'SUCCESS'

CI Report

Link to invocation

@Funatiq
Funatiq merged commit 8d09d17 into NVIDIA:main Oct 14, 2026
@Funatiq
Funatiq deleted the dev/release-resume branch October 14, 2026 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-compatible Accepted LLM API contract change that is backwards-compatible ci: full pre-merge approved

Projects

None yet

Development

Successfully merging this pull request may close these issues.