Repository navigation
[None][refactor] Unify performance collection and exposure - #21688
Conversation
eacddca to
68b305d
Compare
f472e8c to
8597dce
Compare
cb068cb to
07077c0
Compare
|
PR_Github #85088 [ run ] triggered by Bot. Commit: |
|
PR_Github #85076 [ run ] completed with state |
|
PR_Github #85088 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #85147 [ run ] triggered by Bot. Commit: |
Signed-off-by: reasonsolo <[email protected]>
|
PR_Github #85147 [ run ] completed with state
|
…lization Signed-off-by: reasonsolo <[email protected]>
Signed-off-by: reasonsolo <[email protected]>
|
/bot run |
|
PR_Github #85188 [ run ] triggered by Bot. Commit: |
|
PR_Github #85188 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
…servations Signed-off-by: reasonsolo <[email protected]>
|
/bot run --disable-fail-fast |
|
/bot run |
|
PR_Github #85315 [ run ] triggered by Bot. Commit: |
|
PR_Github #85318 [ run ] triggered by Bot. Commit: |
|
PR_Github #85315 [ run ] completed with state |
Signed-off-by: reasonsolo <[email protected]>
|
/bot run --disable-fail-fast |
|
PR_Github #85366 [ run ] triggered by Bot. Commit: |
|
PR_Github #85318 [ run ] completed with state |
|
PR_Github #85366 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #85485 [ run ] triggered by Bot. Commit: |
|
PR_Github #85485 [ run ] completed with state |
Description
Unify performance collection and its logging/Prometheus adapters without adding metric families or KV-cache/transfer business behavior. Production and offline execution share immutable observations categorized as
per_req,per_iter, andper_rank.All new observability metric definitions, KV-transfer measurements/outcomes, transfer cleanup fixes, native KV-cache instrumentation, operator reference, and feature tests are in #22083. Merge this refactor first so that PR can use the shared loop producer and transport serializer.
PerfMetricsCollector/PerfMetricsRecordand executor-ownedLoggerExposure. Reuse captured rank/KV snapshots rather than reading the source again for each exposure.PrometheusExposurearound the existing exporter implementation. PreserveMetricsCollector, its legacy logging methods, existing metric names/labels, dictionary-only producer paths, and flat JSON shape. The Prometheus metric definitions are structurally identical tomain.candidate_metrics/metrics_dictcompatibility attributes and independently snapshot speculative-decoding arrays.IterationStatsRecord(NamedTuple)and keyword construction. A single compatibility conversion reads historical tuple shapes and ignores future trailing fields. Optional timing and loop fields carry existing observations. KV-transfer outcome parameters, record fields, wire serialization and category classification are deferred to [None][feat] Add KV-cache transfer and executor observability metrics #22083.executorLoopenvelope; new metric families consuming that envelope belong to [None][feat] Add KV-cache transfer and executor observability metrics #22083.The shared collector/exposure refactor exists only here. #22083 must reconcile its outcome-extended transport record after this refactor lands; the outcome extension is intentionally absent from this PR.
Validation
main.f72ff0c77e; the follow-up must rebase after this refactor lands to reconcile its extended transport record.Shared iteration serialization
IterationStatsRecord.to_dict()now owns the native-stats conversion and optional-field JSON aliases. Both worker serialization and the ADP all-ranks gather path use it. The existing camelCase keys, omitted optional values, legacy tuple layouts, and path-specific rank fields are preserved. Added compatibility coverage for both row shapes, zero timing values, request statistics, and historical tuple widths.Validation: Python syntax checks and applicable pre-commit hooks passed. The new runtime regression tests have not been run; a target TensorRT-LLM container is still needed.
Dashboard preview
Runnable Grafana dashboard example
Includes
examples/serve/grafana/dashboard.py,example.config.json, metrics/log templates and a setup README. Linked fromexamples/serve/README.mdand the performance-metrics documentation. Supports offline rendering, deployment dry-run and explicit publication. The default configuration renders one metrics dashboard with 80 panel templates; optional Loki logs have their own dashboard.The example belongs to this PR. New KV-cache metric implementation remains in #22083; its optional panels need that instrumentation. Missing observations do not become measured zeros.
Validation: 25 standalone dashboard utility tests passed with mocked publication/Kubernetes operations, and the example configuration rendered offline. This does not validate live Grafana publication, PromQL execution or the native metrics instrumentation.
Overview
This change unifies performance metric collection and exposure.
PerfMetricsCollectorbuilds immutableper_req,per_iter, andper_rankrecords. Logger and Prometheus adapters expose those records. The change also addsIterationStatsRecordfor iteration stats. It adds a standalone Grafana dashboard renderer and publisher underexamples/serve/grafana/. The diff covers 29 files, with 15,099 lines added and 158 removed. The change does not add KV-transfer outcome metrics, native KV-cache instrumentation, or new metric definitions. Those belong to the follow-up in#22083.Validation status:
Dev Engineer Review
BaseWorker._stats_serializernow routes per-rank dictionaries throughPerfMetricsCollector. It parses other inputs withIterationStatsRecord.from_tupleand replaces the old tuple-field mapping throughiteration_stats_row. The objectives state that the flat JSON shape is preserved. Confirm this against the serializer tests before merge. Confirm that theattentionDpRankkey (default0) and therankkey match their consumers.IterationStatsRecord.from_tupletruncates tuples to the record's field count. Tuples wider than the known layout drop trailing values without an error. Confirm that no producer depends on those values.kv_cache_utilizationuses used blocks when present and capacity is positive. Otherwise it uses capacity minus free blocks. It returnsNonefor nonnumeric or nonpositive capacity, or when both used and free counts are absent. Callers that divided used blocks by maximum blocks directly must handleNone.PerfMetricsCollectorpolls the KV-cache reader on the first loop. It polls again when the loop-sequence gap reacheskv_refresh_interval(default 16). Between polls it reuses the last rank snapshot, so reported KV metrics can lag by up to 16 loops. Confirm that this lag is acceptable for dashboards.MetricsCollectoris renamed toPrometheusExposure. AMetricsCollectorcompatibility subclass keeps the old name. Legacy request and iteration methods are renamed. Check external callers that use the old method names.result.py.GenerationResultBasenow stores a list ofPerfMetricsRecordobjects. Speculative-decoding per-position data is copied into lists before recording. Check memory growth for long-running or high-candidate requests.profile_stepnow derives the rank filter fromTLLM_PROFILE_LOG_RANKS. It requests KV-cache stats only when logging is on, iteration perf stats are disabled, the rank is selected, and a KV-cache manager exists. The prior inline log formatting, fetched-request delta tracking, and cached KV-utilization refresh logic are removed. Confirm that log output is unchanged for existing users.deploypath writes Grafana dashboards and Kubernetes ConfigMaps. Inconfigmap-v2mode, it preserves unrelated ConfigMap data and selected metadata. It checks dashboard and ConfigMap revisions before mutation. A--dry-runmode exists. Review the default publication mode and the--finalize-onlycheckpoint logic.py_executor.py,profiling.py,base_worker.py,result.py,openai_server.py,grpc/openengine/metrics.py, andmetrics/.QA Engineer Review
Test files and test-list files changed:
tests/unittest/metrics/test_grafana_dashboard.py(+651 lines). Covers offline rendering, configuration validation, dry-run and verified publication, ConfigMap preservation, concurrent-change detection, and error redaction.tests/unittest/metrics/test_perf.py(+312 lines). CoversPerfMetricsRecord,PerfMetricsCollector, KV-cache refresh, loop sequencing, Prometheus output, andIterationStatsRecord.from_tuplecompatibility for widths 1–10 and wider historical tuples.tests/unittest/metrics/test_collector.py(+78 lines). AddsTestCollectedRequestRecords, parameterized for HTTP and OpenEngine exposure.tests/unittest/executor/test_stats_serializer.py(+89 lines). Covers named and tuple forms, legacy prefix lengths, tagged per-rank dictionaries, and the executor-loop field.tests/unittest/_torch/pyexecutor/test_iter_stats_interval.py(+13/-3). Covers fetched-delta identity and reused-block metrics.tests/unittest/_torch/pyexecutor/test_iter_stats_populate.py(+6 lines). Initializes_perf_metricsand rank fields. Adds a regression check that the capture iteration (999) differs from the batch iteration (17).tests/unittest/_torch/pyexecutor/test_profile_endpoints.py(+88 lines). Initializes_perf_metricsin the bare executor fixture. Adds resource-rebinding andprofile_stepmetric tests.tests/unittest/_torch/pyexecutor/test_executor_resource_rebind.py(+2 lines). Initializesex._perf_metricsin the fixture.tests/unittest/grpc/openengine/test_metrics.py(+21 lines). Addstest_collect_once_exposes_iteration_and_rank.tests/integration/test_lists/test-db/l0_cpu.yml(+2 lines). Addsunittest/metrics/test_grafana_dashboard.pyandunittest/metrics/test_perf.py. The existingunittest/metrics/test_collector.pyentry remains.Not established:
_torch/pyexecutor,executor, andgrpctest files are covered by existing CI lists. The available evidence does not show their list entries.Coverage verdict: needs follow-up. The unit tests cover the new collector, serializer, and dashboard logic. Runtime tests have not run. Live dashboard publication and native metric instrumentation are not covered.
Per-File QA Perspective
docs/source/commands/trtllm-serve/index.rst: Adds theperformance-metrics-collectiontoctree entry. No QA action needed.docs/source/commands/trtllm-serve/performance-metrics-collection.md: Documents the collection model, cadence, and dashboard steps. Verify the documented controls against the implementation.examples/serve/README.md: Adds the Grafana section and link. No QA action needed.examples/serve/grafana/README.md: Documents offline and live workflows. Confirm that offline steps run as written.examples/serve/grafana/dashboard.py: Renders dashboards and deploys ConfigMaps. Verify dry-run,--finalize-only, and redaction behavior against a live cluster.examples/serve/grafana/example.config.json: Example config with scraping and logs disabled. Verify that the default render succeeds.examples/serve/grafana/templates/logs.json: Logs dashboard template. Verify its LogQL queries against real Loki data.tensorrt_llm/_torch/pyexecutor/iteration_stats.py: New record type with legacy tuple handling. Verify theattentionDpRankandrankoutput keys.tensorrt_llm/_torch/pyexecutor/profiling.py: Changes profile logging and KV-cache collection gating. VerifyTLLM_PROFILE_LOG_RANKSfiltering and log output.tensorrt_llm/_torch/pyexecutor/py_executor.py: Owns aPerfMetricsCollectorand buffersIterationStatsRecordobjects. Verify iteration stats output in Attention-DP runs.tensorrt_llm/executor/base_worker.py: Replaces the stats serializer path. Verify JSON output for request, KV-cache, and timing fields.tensorrt_llm/executor/result.py: Records performance records per result. Verify finish-reason labels and speculative-decoding metrics.tensorrt_llm/grpc/openengine/metrics.py: Emits candidate records when present. Verify OpenEngine metric output.tensorrt_llm/metrics/__init__.py: Adds exports. No QA action needed.tensorrt_llm/metrics/collector.py: Renames the collector and adds a compatibility subclass. Verify that Prometheus metric names and labels are unchanged.tensorrt_llm/metrics/logging.py: AddsLoggerExposure. Verify compact JSON and text log formats.tensorrt_llm/metrics/perf.py: Adds the collector, record, and utilization helper. Verify the KV-cache utilization fallback and refresh cadence.tensorrt_llm/serve/openai_server.py: Emits records through the collector. Verify the HTTP metrics path.tests/integration/test_lists/test-db/l0_cpu.yml: Adds two CPU unit test entries. Verify that the entries run in CI.tests/unittest/_torch/pyexecutor/test_iter_stats_interval.py: Updated fixtures and assertions. Run to confirm the fetched-delta identity checks.tests/unittest/_torch/pyexecutor/test_iter_stats_populate.py: Adds a regression check. Run to confirm the capture and batch iteration values.tests/unittest/_torch/pyexecutor/test_profile_endpoints.py: Fixture update and new profiling tests. Run to confirm the bare executor setup.tests/unittest/executor/test_stats_serializer.py: Serializer and legacy-tuple tests. Run to confirm wire-field expectations.tests/unittest/metrics/test_collector.py: Adds request-record tests. Run to confirm HTTP and OpenEngine exposure.tests/unittest/metrics/test_grafana_dashboard.py: Dashboard unit tests with mocked publication. Mocks do not validate live Grafana or Kubernetes behavior.tests/unittest/metrics/test_perf.py: Collector and record tests. Run to confirm KV-cache refresh and Prometheus output.Review follow-up
Removed unused KV-transfer outcome plumbing from this PR, including the executor parameter, named-record field, JSON serialization, rank-category key and transport-specific assertions. The producer, transport extension, classification and their feature coverage belong to #22083.
Documented the added partition/freeze/mapping work and the pending benchmark dimensions; the existing JSON encoding/decoding passes are not new. Added explicit KV-utilization edge coverage for used-count precedence, free-only snapshots, unknown/zero capacity, logger
N/A, and the unchanged Prometheus explicit-used-count guard. The inspected baseline already logsN/Afor zero capacity, rather than0%. Kept the materialization method names: they do not collide with domain types or shadow imported symbols.Validation: initial syntax/lint and applicable commit hooks passed. Current runtime and serialization measurements are recorded below.
CodeRabbit review fixes
include_logsdefault false throughout rendering; bypass environment proxies for loopback Grafana URLs while retaining redirect refusal.Validation: 32 standalone dashboard tests passed; the neutral example renders offline; applicable commit hooks passed. Subsequent executor, collector and RPC runtime validation is recorded below.
CI regression fix and validation (2026-11-16)
The November 16 regression follow-up was validated at
af72c4b6c0045183a5ea51d303677e2cf11d4828(runtime fixf32cc674e219be25dc755b1a28f8879aa15afdf8).iter_perf_stats_intervalin the bare profiling fixture.IterationStatsJSON encoded during worker transport and append the Python-owned fields directly. This removes the full native-JSON decode, immutable partition/freeze and re-encode from every buffered record. Request/exposure collection contracts and RPC deadlines are unchanged. Serializer regressions preserve all wire fields and reject native JSON decoding on the fast transport path.The raw Jenkins parameters and checkout log for pipeline #70482 show
df2eb906ef, predating the existing_num_prompt_tokensfixture fixf36d1464a1. The generated analysis incorrectly labels that run asf36d1464a1. A fresh standard CI run was requested after verifying the new GitHub head. Blossom-CI authorization and Start ci job succeeded.Validation on
umbriel-b200-027, containertrtllm-test, with the exact checksum-verified native wheel produced by pipeline #70426 (the native build reused by #70482):TestGPTOSS::test_dflashwith the normal CI conftest enabled: passed, all 1,319 GSM8K examples, accuracy 87.945%, acceptance length 3.396. Stats retrieval completed withoutRPCTimeout; test setup and teardown also passed. This is fresh B200 execution, not H100 execution.Main integration — 2026-11-17
Merged
mainate80e20de35fd2709547b0dd7942e8eaef64b690aas signed merge commit48fc18c976592156bced7a3538992de38fd40c99. Retained upstream multimodal encoder observations, input-processing observers and metric recording alongside the collected loop records. The upstream ninth tuple slot remains encoder stats, and the loop envelope follows it; both named records and historical tuples preserve both observations through the worker and rank-gather serializers. Native JSON forwarding stays on the fast transport path. Collector test teardown now unregisters its metrics so later serving tests can use the process registry without collisions.Fresh validation on
umbriel-b200-027/trtllm-test: 298 CPU tests and 3 subtests passed across metrics, serializer, profiling, ADP iteration population, encoder timing, resource rebind and middleware; 525 schema CPU tests passed; both official generated manifest/schema freshness checks and applicable commit hooks passed. Existing container native artifacts containing current-main APIs were reused; the older CI70426 wheel lacked those APIs. No fresh native build or full-model inference run is claimed for this merge; the November 16 DFlash result above is historical. Pyrefly was unavailable.Fresh standard CI requested for this head. GitHub confirmed the pushed head is mergeable.