Skip to content

[#20407][perf] Annotate native KV cache offload and restore submissions - #20862

Open
rikundu wants to merge 119 commits into
NVIDIA:mainfrom
rikundu:chakra/pr-9
Open

rikundu wants to merge 119 commits into
NVIDIA:mainfrom
rikundu:chakra/pr-9

Conversation

@rikundu

@rikundu rikundu commented Oct 23, 2026 •

Copy link
Copy Markdown

Description

Add native kv_cache_offload and kv_cache_onboard CPU scopes at actual V1 pool-copy and V2 batched host/device submission boundaries. Select kv in TLLM_PROFILE_CUSTOM_REGIONS; PyTorch builds support these scopes independently of the NCCL/nanobind options.

Metadata records direction, manager version, copy count and payload bytes. V2 counts only GPU-backed hot pools; encoded page size remains separate. V1 distinguishes copied payload from allocation pitch and handles partial/full-copy paths. Optional numeric CUDA stream IDs are queried lazily without consuming a pending CUDA error; unrepresentable integer fields are omitted. Disk staging, device reuse and host-only copies are excluded. Scopes measure enqueue work, not asynchronous completion, and add no synchronization.

Issue #20407 · Stack 9/9, cumulative against main (27b44ebb). Depends on PR8 and earlier layers; merge those first, then rebase onto updated main before merging. This layer’s diff.

Test Coverage

Rebase verification on final stacked head c11366d8: profiler contracts, affected upstream CPU regressions, and all 36 CUDA graph cases passed with ON/OFF source overlays. Native/build inputs are unchanged from the fresh ON/OFF Release FAST_BUILD SM86 wheels built at 6443dc65 on A6000s; those binaries were reused. These are final-stack checks, not separate builds of intermediate heads. Fresh current-head Jenkins builds remain pending.

PR Checklist

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

Pending before merge: current-head Jenkins, reviewer approval, and dependency checks where applicable.

Dev Engineer Review

  • The change adds a shared Python/C++ profiler contract, cached region selection, metadata serialization, and fail-open scope handling.
  • C++ and Python implement parallel selector and metadata logic. Their defaults, validation, and failure behavior must remain consistent.
  • Native KV scopes cover V1 pool copies and V2 host migrations. The implementation excludes reuse, host-only pools, disk staging, and asynchronous completion. Stream-ID probing and representability limits require CUDA-path validation.
  • Profiling options are independent, but nanobind profiling requires BUILD_PYT and the patched nanobind runtime. NCCL profiling also requires ENABLE_MULTI_DEVICE.
  • The patch changes MPI, NCCL, nanobind, MoE, workflow, disaggregation, packaging, and CI behavior. This broad scope increases regression risk.
  • Jenkins now builds a dedicated RelWithDebInfo profiling artifact without cache reuse and checks 13 native profiler cases. The configuration is present, but execution success is not established.
  • Current-head build, test, and CI results are not available.

QA Engineer Review

  • Added native C++ tests for profiler contracts and V1/V2 KV-cache transfers.
  • Added Python tests for selector handling, workflow metadata, MPI, NCCL, MoE, nanobind, disaggregation profiling, profile filenames, route capture, and failure preservation.
  • Added test_mpi_profiler to l0_cpu.yml.
  • Added test_nccl_profiler_build_contract[off] to l0_dgx_h100.yml.
  • Added test_graph_capture_skips_only_profiler_serialization to l0_h100.yml.
  • Added test_nccl_profiler_build_contract[on] to l0_nccl_profiler.yml.
  • l0_cpu.yml also lists unittest/_torch/executor/test_workflow_profiler.py; direct list entries for every new unit-test module are not evidenced.
  • Coverage includes disabled regions, malformed metadata, callback failures, exception preservation, cancellation, uncertain ownership, CUDA graphs, stream metadata, sparse pools, and no-device paths.
  • Coverage verdict: needs follow-up. Current-head execution results are unavailable, and release builds, all architectures, Windows, inter-node transport, fresh Torch-disabled builds, and model-serving performance remain unvalidated.

Per-File QA Perspective

Source, configuration, and documentation

  • 3rdparty/fetch_content.json — Applies the nanobind profiler patch. Verify dependency fetching and reproducible builds.
  • 3rdparty/patches/nanobind_pytorch_profiler.patch — Adds tensor metadata and nanobind profiler records. Verify PyTorch 2.14+, limited-API, free-threaded, property, and failure paths.
  • cpp/CMakeLists.txt — Adds independent nanobind and NCCL profiling options and dependency checks. Verify all ON/OFF combinations.
  • cpp/include/tensorrt_llm/common/profiler.h — Adds public profiler-region, metadata, and scope APIs. Verify ownership, ABI, and no-op behavior.
  • cpp/tensorrt_llm/batch_manager/CMakeLists.txt — Links KV-cache targets to tllm::common_profiler under BUILD_PYT. Verify non-PyTorch builds.
  • cpp/tensorrt_llm/batch_manager/kvCacheTransferManager.cpp — Changes partial-copy and transfer-byte calculations. Verify data types, scales, layer-first pools, zero tokens, and partial blocks.
  • cpp/tensorrt_llm/batch_manager/kvCacheTransferProfiler.h — Adds V1/V2 KV-transfer scopes and metadata. Verify direction inference, stream-ID omission, reuse exclusion, and non-Torch builds.
  • cpp/tensorrt_llm/batch_manager/kv_cache_manager_v2/storageManager.cpp — Adds V2 migration scopes and GPU-pool byte accounting. Verify sparse host pools, disk pools, page counts, and stream metadata.
  • cpp/tensorrt_llm/common/CMakeLists.txt — Builds and exports the common profiler library. Verify public linkage and non-PyTorch configuration.
  • cpp/tensorrt_llm/common/profiler.cpp — Implements selector parsing, metadata serialization, and fail-open scopes. Verify defaults, none, duplicates, malformed input, and cleanup failures.
  • cpp/tensorrt_llm/nanobind/CMakeLists.txt — Builds and substitutes a profiled nanobind runtime. Verify patched-header detection and target linkage.
  • cpp/tensorrt_llm/nanobind/bindings.cpp — Initializes selector diagnostics and exposes build flags. Verify startup warnings and GPU-less extension loading.
  • cpp/tensorrt_llm/thop/ncclCommunicatorOp.cpp — Adds NCCL send/receive metadata. Verify eager, capture, unknown-capture, rank, shape, dtype, and replay paths.
  • cpp/tensorrt_llm/thop/ncclCommunicatorOp.h — Updates communicator documentation and conditional state. Verify documentation matches runtime behavior.
  • cpp/tests/unit_tests/batch_manager/CMakeLists.txt — Registers the KV profiler GPU test. Verify exclusion when BUILD_PYT is disabled.
  • cpp/tests/unit_tests/common/CMakeLists.txt — Registers profilerTest and selector-case data. Verify the target is built in the intended configuration.
  • docs/source/developer-guide/kv-transfer-profiler.md — Documents correlated and native KV profiling. Verify lifecycle and exclusion statements.
  • docs/source/developer-guide/kv-transfer.md — Adds the KV profiling link. Verify navigation.
  • docs/source/developer-guide/moe-perf-guide.md — Adds the MoE profiler link. Verify synchronization-limit statements.
  • docs/source/developer-guide/moe-routing-profiler.md — Documents MoE shape and expert-ID profiling. Verify restrictions match implementation.
  • docs/source/developer-guide/nccl-profiler-metadata.md — Documents NCCL, MPI, and execution-trace metadata. Verify build-option and replay statements.
  • docs/source/developer-guide/perf-analysis.md — Documents selectors and profile filenames. Verify examples match runtime paths.
  • docs/source/developer-guide/profiler-metadata.md — Documents the shared selector and metadata contract. Verify Python/C++ consistency.
  • docs/source/developer-guide/workflow-profiler-regions.md — Documents workflow boundaries and metadata. Verify capture-time and replay claims.
  • docs/source/index.rst — Adds five profiler pages to the guide. Verify links resolve.
  • jenkins/Build.groovy — Adds the profiling artifact and 13-case native test gate. Verify archive creation and result parsing.
  • jenkins/L0_MergeRequest.groovy — Expands multi-GPU path triggers. Verify profiler changes select the intended stages.
  • jenkins/L0_Test.groovy — Maps profiling stages to the profiling artifact. Verify stage and artifact selection.
  • tensorrt_llm/__init__.py — Initializes native profiler regions during import. Verify import ordering and GPU-less behavior.
  • tensorrt_llm/_profiler.py — Adds Python selectors, metadata, workflow scopes, and MoE helpers. Verify fail-open behavior, cycles, CUDA capture, and no-copy routing-ID collection.
  • tensorrt_llm/_torch/disaggregation/base/transfer.py — Centralizes wire request-ID precedence. Verify disaggregated, context, and local IDs.
  • tensorrt_llm/_torch/disaggregation/kv_cache_transceiver.py — Adds profiling hooks and transceiver defaults. Verify compatibility with existing implementations.
  • tensorrt_llm/_torch/disaggregation/native/transfer.py — Reuses centralized wire-ID selection. Verify native session IDs.
  • tensorrt_llm/_torch/disaggregation/profiler.py — Correlates request-scoped submit and terminal observations. Verify ownership, cancellation, shutdown, weak references, and exceptions.
  • tensorrt_llm/_torch/disaggregation/transceiver.py — Tracks terminal send outcomes. Verify retirement and shutdown cleanup.
  • tensorrt_llm/_torch/distributed/communicator.py — Adds MPI scopes and type annotations. Verify unchanged collective arguments, results, and exceptions.
  • tensorrt_llm/_torch/models/modeling_step3p7.py — Warns for unsupported Python MoE routing. Verify routed-expert LoRA behavior.
  • tensorrt_llm/_torch/moe/fused_moe/create_moe.py — Warns for Triton and vanilla routing backends. Verify backend construction is unchanged.
  • tensorrt_llm/_torch/moe/fused_moe/moe_scheduler.py — Records routed and prerouted expert IDs. Verify empty-token, chunked, replay, and graph paths.
  • tensorrt_llm/_torch/pyexecutor/cuda_graph_runner.py — Adds graph capture and replay metadata. Verify heterogeneous encoder inputs.
  • tensorrt_llm/_torch/pyexecutor/engine/runners/decoder/inputs.py — Adds the prepare_inputs scope. Verify results and exceptions.
  • tensorrt_llm/_torch/pyexecutor/engine/runners/decoder/runner.py — Adds model-forward metadata. Verify warmup and padded-row values.
  • tensorrt_llm/_torch/pyexecutor/profiling.py — Changes multi-range and early-exit trace filenames. Verify collisions and runtime captures.
  • tensorrt_llm/_torch/pyexecutor/py_executor.py — Adds executor scopes and phase metadata. Verify phase classification, encoder rows, dummy requests, and microbatch IDs.
  • tensorrt_llm/_torch/route_capture.py — Adds delayed route-copy callbacks. Verify original-step metadata and no synchronization.

Test files and test lists

  • cpp/tests/unit_tests/batch_manager/kvOffloadProfilerTest.cpp — Covers V1/V2 round trips, directions, payload bytes, streams, cold tiers, sparse pools, disabled profiling, and reuse. Registered through CMake; no separate test-db entry is shown.
  • cpp/tests/unit_tests/common/profilerTest.cpp — Covers native selector caching, lazy factories, callback requirements, scope counts, and exception preservation. NCCL cases depend on the profiling option.
  • tests/integration/defs/test_unittests.py — Adds MPI and NCCL profiler integration functions. Verify rank-report validation and build-flag checks.
  • tests/integration/test_lists/test-db/l0_cpu.yml — Adds test_mpi_profiler and CPU profiler coverage, including the workflow-profiler module.
  • tests/integration/test_lists/test-db/l0_dgx_h100.yml — Adds test_nccl_profiler_build_contract[off] for the disabled-probe contract.
  • tests/integration/test_lists/test-db/l0_h100.yml — Adds the MoE graph-capture regression test.
  • tests/integration/test_lists/test-db/l0_nccl_profiler.yml — Adds the enabled NCCL build-contract test for two H100 GPUs with PyTorch and MPI.
  • tests/unittest/_torch/disaggregation/fake_kv_cache_transceiver.py — Adds fake status-ID behavior for profiling tests. Verify production ID precedence.
  • tests/unittest/_torch/disaggregation/test_disagg_idle_cancellation.py — Initializes send-outcome state in the fixture. Verify idle cancellation terminal paths.
  • tests/unittest/_torch/disaggregation/test_kv_transfer_profiler.py — Covers submit/terminal correlation, cancellation, ownership uncertainty, failures, cleanup, delegation, and wire IDs. No direct test-list entry is shown.
  • tests/unittest/_torch/distributed/test_communicator_profiler.py — Covers MPI metadata, payloads, subgroup caching, exceptions, and two-rank behavior. No direct test-list entry is shown.
  • tests/unittest/_torch/distributed/test_nccl_profiler.py — Covers NCCL eager/capture metadata, replay, build flags, selectors, and dispatcher boundaries. Related integration coverage is listed.
  • tests/unittest/_torch/executor/test_profile_window_filenames.py — Covers profile ranges, runtime captures, early exits, execution traces, and missing Chrome paths. No direct test-list entry is shown.
  • tests/unittest/_torch/executor/test_workflow_profiler.py — Covers workflow metadata, phases, graphs, failures, ordering, counts, and microbatch slots. The module is listed in l0_cpu.yml.
  • tests/unittest/_torch/moe/test_moe_profiler.py — Covers routing shapes, completed IDs, scheduler paths, warnings, graph capture, and failure preservation. Its graph-capture regression is listed in l0_h100.yml.
  • tests/unittest/_torch/pyexecutor/test_cuda_graph_capture_replay.py — Covers decoder and encoder capture/replay events and latest-input behavior. Related coverage is listed in l0_h100.yml.
  • tests/unittest/_torch/test_route_capture.py — Covers delayed and out-of-order route copies, callback metadata, inactive profiling, and no synchronization. No direct test-list entry is shown.
  • tests/unittest/bindings/test_nanobind_profiler.py — Covers binding tensor metadata, selectors, warnings, stubs, and GPU-less extension initialization. No direct test-list entry is shown.
  • tests/unittest/disaggregated/test_cache_reuse_adapter.py — Initializes profiling state in cache-reuse fixtures. Verify fixture behavior remains representative.
  • tests/unittest/disaggregated/test_chunked_transfer.py — Updates failed-send and outcome-observation fixtures. No direct test-list entry is shown.
  • tests/unittest/disaggregated/test_disagg_transfer_diagnostics_wiring.py — Initializes profiler state in diagnostic fixtures. Verify native diagnostic paths.
  • tests/unittest/disaggregated/test_kv_transfer_fail_stop.py — Initializes profiler state in fail-stop fixtures. Verify pending-observation shutdown.
  • tests/unittest/disaggregated/test_transceiver_bounded_polling.py — Updates bare-transceiver and request-ID fixtures. Verify bounded polling behavior.
  • tests/unittest/disaggregated/test_transfer_ownership_regressions.py — Initializes profiler state in ownership fixtures. Verify constructor-independent coverage.
  • tests/unittest/profiler_selector_cases.json — Defines valid and invalid selector cases. Verify packaging and runtime availability.
  • tests/unittest/profiler_test_utils.py — Adds shared selector, observer, filtering, and metadata-decoding helpers. Verify malformed and unsupported metadata handling.
  • tests/unittest/test_profiler.py — Covers selector contracts, metadata, scopes, decorators, traces, lazy factories, and failure preservation. Related profiler coverage is added to l0_cpu.yml.
  • tests/unittest/tools/test_unittest_culprits.py — Covers MPI per-rank JUnit success, skip, failure, missing, stale, and empty reports. No direct test-list entry is shown.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants