Skip to content

fix(atom): read P/D cache counters from prefill and ingest CPU offload - #1533

Merged
cquil11 merged 1 commit into
masterfrom
cam/atom-pd-prefill-cache-counters
Oct 28, 2026
Merged

cquil11 merged 1 commit into
masterfrom
cam/atom-pd-prefill-cache-counters

Conversation

@cquil11

@cquil11 cquil11 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

ATOM P/D cache rates are wrong at ingest. Every counter needed is already in server_metrics_export.json, so no rerun is needed. This PR only changes how the app reads those counters.

What is wrong on main

ATOM endpoints in P/D runs have no role label (engine_role: "default" on both prefill and decode). The chart series sums every endpoint.

  • Decode re-reports every prompt in atom:prompt_tokens and atom:prefix_cache_full_tokens. That doubles the denominator.
  • On some images decode also counts KV received from prefill as atom:prefix_cache_cached_tokens.
  • atom:prefix_cache_offload_tokens is never read, so the CPU tier is null.

Trace ingest writes server_gpu_cache_hit_rate / server_cpu_cache_hit_rate from this chart series, so pricing inherits the error.

Fix

  • An endpoint counts as prefill if it ran prefill batches (atom:prefill_batch_tokens stats.count > 0). Decode endpoints report 0 there.
  • When both prefill and other endpoints export ATOM prompt counters, atom:prompt_tokens, atom:prefix_cache_{cached,full,offload}_tokens are read from prefill only.
  • For that P/D case, atom:prefix_cache_offload_tokens becomes cache hit (CPU offload) and is subtracted from compute. It is disjoint from cached_tokens per ATOM's metric description.
  • Aggregated ATOM and exports without the marker are unchanged.
  • backfill-chart-series now also rewrites the linked rows' cache-hit metrics for mooncake-atom / atom-disagg trace replays. The ingest SQL moves into a shared writeCacheHitMetrics.

Before / after on real artifacts

Run through computeChartSeries with the ATOM P/D context.

Run main GPU / CPU this PR GPU / CPU
GLM-5.2 1P1D c56, LMCache offload (39028510364) 82.97% / null 75.47% / 20.70%
DSv4 1P1D c64, no offload (40275551032) 47.49% / null 94.92% / null
DSv4 1P1D c128, LMCache offload (40275551032) 47.04% / null 94.12% / 0.54%

Per-endpoint counter totals for GLM c56 (profiling CSV):

Counter Prefill Decode
atom:prompt_tokens 1,023.9M 1,023.9M
atom:prefix_cache_full_tokens 1,041.9M 1,023.9M
atom:prefix_cache_cached_tokens 772.8M 924.4M
atom:prefix_cache_offload_tokens 212.0M 0
atom:prefill_batch_tokens count 10,205 0

DSv4 decode reports 0 cached tokens, so main roughly halves its hit rate.

Backfill

There are no ATOM P/D AgentX rows in the public availability API today. The ATOM P/D PRs will ingest correctly once they merge. For any existing trace replays:

bun run --cwd packages/db db:backfill-chart-series --force --run-id <github_run_id>

Out of scope

  • extractServerMetricSamples (agentic aggregate distributions) still sums all endpoints.
  • CHART_SERIES_VERSION is not bumped because the change is ATOM P/D only. Use --force --run-id.

Tests

atom-metrics.test.ts covers prefill-only scoping with offload as CPU, and the no-marker fallback. All packages/db tests pass (1183), along with typecheck, lint and format.


Note

Medium Risk
Changes how stored benchmark cache-hit rates are derived for ATOM P/D runs, which downstream pricing and UI consume; logic is scoped to those frameworks with tests and backfill support.

Overview
Fixes ATOM prefill/decode chart series and ingest so prompt and prefix-cache counters are not double-counted when decode endpoints re-export the same tokens without role labels.

Chart computation identifies prefill endpoints via atom:prefill_batch_tokens (stats.count > 0) and, when mixed with decode, scopes atom:prompt_tokens and atom:prefix_cache_* counters to those endpoints only. It now ingests atom:prefix_cache_offload_tokens as cache hit (CPU offload) and subtracts offload from compute (miss). Exports without the prefill marker still sum all endpoints.

Trace ingest and backfill share a new writeCacheHitMetrics helper (replacing duplicated SQL). backfill-chart-series also rewrites linked benchmark_results GPU/CPU cache-hit fields for mooncake-atom / atom-disagg after recomputing chart series, matching fresh ingest behavior.

Tests cover prefill-only scoping with offload and the no-marker fallback.

Reviewed by Cursor Bugbot for commit e979c8e. Bugbot is set up for automated code reviews on this repo. Configure here.

@cquil11
cquil11 requested a review from adibarra as a code owner October 28, 2026 04:12
@vercel

vercel Bot commented Oct 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
inferencemax-app Ready Ready Preview Oct 28, 2026 4:12am UTC

Request Review

Jasen2201 added a commit to SemiAnalysisAI/InferenceX that referenced this pull request Oct 28, 2026
#4397 was closed in favor of SemiAnalysisAI/InferenceX-app#1533, which
reads the ATOM P/D counters from server_metrics_export.json at ingest.
This PR now changes only the recipe, its master config entry, the
changelog and the srt-slurm patch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cquil11
cquil11 merged commit 1979879 into master Oct 28, 2026
33 checks passed
@cquil11
cquil11 deleted the cam/atom-pd-prefill-cache-counters branch October 28, 2026 17:09

This branch was successfully deployed

1 active deployment
Preview — e979c8e6 Deployed Oct 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant