aibrix icon indicating copy to clipboard operation
aibrix copied to clipboard

[Feat] Track remaining SGLang DP-attention metric aggregation and mapping gaps

Open MuonChaser opened this issue 1 month ago • 12 comments

Feature Description and Motivation

Track the remaining SGLang DP-attention metric aggregation work identified in the review of #3156.

#3156 addresses the four request/KV pool gauges reported in #3155: running requests, queued requests, KV capacity and capacity-weighted token utilization. It deliberately leaves other families unchanged. This follow-up is separate from that fix and is not intended to block it.

AIBrix also maps the following SGLang gauges in pkg/metrics/metrics.go:

AIBrix metric SGLang mapping Follow-up
AvgGenerationThroughputToksPerS sglang:gen_throughput Prioritize validating pod-level aggregation of independent DP throughput
NumRequestsSwapped sglang:num_retracted_reqs Verify the legacy gauge's update semantics and whether this mapping remains appropriate
NumPrefillPreallocQueueReqs sglang:num_prefill_prealloc_queue_reqs Verify name/version compatibility before defining aggregation
NumDecodePreallocQueueReqs sglang:num_decode_prealloc_queue_reqs Verify DP ownership and priority/total series before aggregation

Use Case and Current Evidence

When one endpoint exposes multiple independent DP pools, consuming one rank can understate pod-level throughput or queue pressure. Replicated TP/PP/EP observations must not be counted as additional pools.

The current follow-up evidence is code inspection and synthetic regression coverage, not a new live reproduction of all four metrics:

  • TestSGLangDPPriorityScopesAndLegacy in #3156 deliberately retains two sglang:gen_throughput series (10 and 20) unchanged. The typed-read selection paths still select one series per model rather than sum those DP pools. If the two values represent independent DP generation rates, the desired pod-level value is 30, not 10 or 20.
  • SGLang v0.5.21's collector defines gen_throughput as generation token/s. It also marks num_retracted_reqs as an old gauge with a newer counter available.
  • That collector defines num_prefill_bootstrap_queue_reqs and num_prefill_inflight_queue_reqs, rather than AIBrix's mapped num_prefill_prealloc_queue_reqs. The decode preallocation gauge is present. Compatibility needs investigation; simply extending the aggregation allowlist would not resolve a missing metric name.
  • The real GPU scrape/replay evidence attached to #3156 validates its four targeted request/KV gauges. It does not establish correct aggregation semantics for the additional metrics listed here.

Proposed Solution and Acceptance Criteria

  • [ ] Start with generation throughput: capture representative DP-attention scrapes and verify that the reported rank values describe independent generation work and compatible measurement windows.
  • [ ] Document each additional metric's supported SGLang versions, labels, update semantics, and aggregation policy. Identify deprecated or renamed mappings separately.
  • [ ] Aggregate only verified additive quantities across distinct DP pools, deduplicating replicated TP/PP/EP observations. Preserve model, engine-role, extra-label and priority scopes; never add a priority total to its breakdowns.
  • [ ] Add local HTTP fetcher regressions covering both FetchAllTypedMetrics and FetchTypedMetric, exposition-order independence, replicated ranks, separate scopes and legacy unranked input.
  • [ ] Validate prefill/decode queue behavior in the applicable PD configuration before claiming coverage. Leave unsupported or ambiguous metrics unchanged and document the limitation.

Related: #3155 and #3156 (targeted fix); #1614 (broader utilization/load reporting); #3056/#3057 (priority-series selection, a separate concern).

Environment

Scope reviewed against AIBrix PR #3156 head c31f4e07d5170003359387fa2cd46fe588803332 and SGLang v0.5.21. No Kubernetes end-to-end validation or measured routing/autoscaling improvement is claimed for this follow-up.

Area

Gateway

MuonChaser avatar Oct 19 '26 03:10 MuonChaser

Thanks for contributing to AIBrix! Please review the contribution guide and make sure this issue contains enough context for maintainers to reproduce or evaluate it.

github-actions[bot] avatar Oct 19 '26 03:10 github-actions[bot]

Reproduced row 1 on main (a89b94a5): 4 DP ranks at 100/120/80/90 tok/s → AvgGenerationThroughputToksPerS reads 90 per-model (last rank) and 100 pod-scoped (first rank), not 390. PD decode scoring reads it (pd/router/router.go:1043).

Fix: add sglang:gen_throughput to the summed gauges in mergeSGLangDPSeries (TP/PP/EP replicas already deduped), plus a test. Other rows untouched.

Could I take this one?

RupertMaiti2005 avatar Nov 08 '26 02:11 RupertMaiti2005

Thanks for reproducing this, @RupertMaiti2005. Please go ahead and take the generation-throughput part. Please link your PR here so we can keep it coordinated with the remaining metric work.

MuonChaser avatar Nov 09 '26 07:11 MuonChaser

Thanks! I'll link the PR here. @varungup90 could this get triage/accepted so I can open it?

RupertMaiti2005 avatar Nov 09 '26 20:11 RupertMaiti2005

PR for the generation-throughput row: #3446. @MuonChaser could you take a look?

RupertMaiti2005 avatar Nov 11 '26 03:11 RupertMaiti2005

I've investigated row 3 from source inspection; no live scrape run yet.

AIBrix maps NumPrefillPreallocQueueReqs only to sglang:num_prefill_prealloc_queue_reqs. The PD queue-drain score reads this metric, with missing cached values treated as 0. In the checked SGLang tags, v0.5.11 has the old name, while v0.5.12, v0.5.21 and v0.5.23 have sglang:num_prefill_bootstrap_queue_reqs instead. The queue-metric rename in sgl-project/sglang#24341 preserves the underlying queue source.

I'd like to take row 3 if nobody has started it. Would you prefer compatibility with both metric names or migrating the mapping outright? Also, should the PD score count bootstrap alone or include inflight?

I'd cover priority-total versus per-priority selection with fetcher regression tests, keeping DP-rank summation separate until queue ownership is verified.

DsThakurRawat avatar Nov 14 '26 06:11 DsThakurRawat

Following the acceptance criteria here, one item can be settled from upstream source without any GPU scrape, so I am proposing it as a small first step before touching aggregation.

Verified against upstream

I checked the SGLang collector at v0.5.21 and v0.5.22:

AIBrix mapping (pkg/metrics/metrics.go on main) SGLang v0.5.21 SGLang v0.5.22
sglang:num_prefill_prealloc_queue_reqs (line 223) absent absent
sglang:num_decode_prealloc_queue_reqs (line 234) present present
sglang:num_retracted_reqs (line 154) present, deprecated Gauge with a num_retracted_reqs_total Counter beside it same
sglang:gen_throughput (line 741) present present

Both versions define num_prefill_bootstrap_queue_reqs and num_prefill_inflight_queue_reqs instead of a prealloc gauge. So the prefill prealloc mapping cannot resolve against either version, which matches the note in this issue, and the two queue gauges that do exist are not yet mapped.

I only checked those two tags, not every supported version, so the version matrix is a starting point rather than a complete answer.

Proposed first PR

Scope: mapping correctness and documentation only. No aggregation change, no routing or autoscaling behavior change.

  1. Add a version matrix under the gateway metric docs: for each mapped SGLang gauge, the versions where it exists, its type, its labels, and whether it is deprecated. Fill it from the collector source at each supported tag.
  2. Mark the prefill prealloc mapping as unresolved rather than deleting it, so the series it currently cannot resolve stays visible.
  3. Add fetcher regressions that pin what each mapping resolves to on a synthetic scrape, so a later name change shows up as a test change rather than silent absence.

Left out on purpose, because they are semantic decisions rather than corrections:

  • Which of num_prefill_bootstrap_queue_reqs or num_prefill_inflight_queue_reqs the prefill prealloc metric should read, if either.
  • Whether num_retracted_reqs should move to the _total counter.
  • DP-pool aggregation of gen_throughput, which needs the GPU scrape in the first acceptance criterion.

Questions before I start

  1. Is mapping correctness plus documentation acceptable as the first PR here, separate from the DP aggregation work?
  2. For the prefill prealloc metric, do you already know the intended source, or should it stay documented as unresolved?
  3. Should the _total counter migration for num_retracted_reqs be part of the same PR or tracked separately?

I have not changed any code, and I will wait for your answer before opening a PR.

wynneyin avatar Nov 15 '26 08:11 wynneyin

Follow-up to the proposal above: the prefill queue mapping is stale rather than simply wrong, and the rename point is narrow.

Checked the collector at each tag that carries it, counting the gauge name in the source:

SGLang tag num_prefill_prealloc_queue_reqs num_prefill_bootstrap_queue_reqs
v0.5.10 present absent
v0.5.11 present absent
v0.5.12 absent present
v0.5.13, v0.5.14, v0.5.15, v0.5.20, v0.5.21, v0.5.22, v0.5.23 absent present

So the gauge AIBrix maps at pkg/metrics/metrics.go:223 existed up to v0.5.11 and was renamed in v0.5.12. num_prefill_inflight_queue_reqs is present across the whole range. I did not check tags at or below v0.5.9, where the file path may differ.

That changes my second question into something narrower: does AIBrix still intend to support SGLang earlier than v0.5.12 for gateway metrics?

  • If not, the mapping should point at num_prefill_bootstrap_queue_reqs, and the changelog entry should record the v0.5.12 rename as the reason.
  • If it does, the mapping needs to resolve both names, which means the metric registry has to carry a version-dependent source rather than one string. That is a bigger change than a mapping correction, so it is worth deciding before I write anything.

The rest of the earlier proposal is unchanged: version matrix plus fetcher regressions first, DP aggregation and routing untouched. Still no code changes on my side.

wynneyin avatar Nov 15 '26 08:11 wynneyin

Closing the loop on the question I asked above, because the evidence arrived after I wrote it.

I opened #3473 for the narrow path rather than leave the gap open: keep num_prefill_prealloc_queue_reqs as the primary mapping, add an ordered per-engine alias list beside it, and add both names to the priority-gauge set so the per-priority breakdown still resolves. Both engine versions then land on the same internal key NumPrefillPreallocQueueReqs, so the registry does not need a version-dependent source. It does not touch aggregation.

That leaves your question open rather than deciding it: if AIBrix intends to support SGLang earlier than v0.5.12 only, #3473 can be reshaped into a straight mapping change to the new name, and if the supported range should be declared instead, that belongs in the version matrix rather than in this mapping.

One detail that argues for fixing the mapping rather than only documenting it: the metric is not dashboard-only. pkg/plugins/gateway/algorithms/pd/router/request_rate.go:39 reads it into the PD request-rate score numerator, so on v0.5.12 and later the prefill term reads zero while the decode and waiting terms still resolve.

I also re-checked main today: the collector defines num_prefill_bootstrap_queue_reqs five times and no longer defines the old name at all, so the v0.5.12 boundary is not a transient state.

wynneyin avatar Nov 15 '26 13:11 wynneyin

Row 4 (decode prealloc queue) looks unclaimed; I'd like to take it.

Checked against SGLang v0.5.21 and the AIBrix code paths:

  • It is a per-scheduler gauge on the shared label set, so it carries dp_rank when DP is on, and it is logged through _log_gauge_queue_count like num_queue_reqs (priority="" total plus breakdowns).
  • AIBrix sums only num_running_reqs, num_queue_reqs, token_usage and max_total_num_tokens across ranks, so a DP pod keeps one series per rank; both reads take one instead of summing.
  • pd/router/request_rate.go:40 adds it to the PD queue-drain numerator.

Fix, same shape as #3446: add it to the summed set, plus a test where two ranks report 3 and 7 and both reads must be 10 (TP counted once, priority="" total kept).

bolubo avatar Nov 20 '26 14:11 bolubo

Row 2 (NumRequestsSwapped ← sglang:num_retracted_reqs) looks unclaimed. I checked it against SGLang's source, and I think the mapping is in the wrong slot rather than just stale.

What the SGLang gauge measures. At v0.5.23 the scheduler sets num_retracted_reqs = len(retracted_reqs) after each retract_decode (scheduler.py#L4502). The metrics reporter copies it into the stats and resets it to 0 on every stats tick (metrics_reporter.py#L873-L876). So it is the size of the latest retraction, reported once, not the number of requests currently swapped out. Retracted requests go back to the waiting queue, so they already show up in num_queue_reqs. SGLang marks the gauge TODO maybe remove this old gauge in favor of the new counter (metrics_collector.py#L551).

The counter. It is named sglang:num_retracted_requests_total, not num_retracted_reqs_total (SGLang renamed it to avoid a clash with the gauge, L557-L562). It first appears in v0.5.7 and is present through v0.5.23. It counts requests evicted from the running batch to free KV cache, which is the same event vLLM V1 counts as a preemption.

The vLLM side of the same slot is gone. vllm:num_requests_swapped belonged to V0's swap preemption mode. vLLM's metrics design doc lists it as a legacy metric that V1 does not emit (docs/design/metrics.md).

AIBrix already has the matching slot. NumPreemptionsTotal is a counter mapped to vllm:num_preemptions_total, with no SGLang entry (metrics.go#L215-L225).

Impact today. Neither metric has a reader on main (270e37b7). NumRequestsSwapped is scraped (cache_metrics.go#L75), but no routing algorithm, autoscaler or exporter reads it. NumPreemptionsTotal is not scraped. The fix is about mapping correctness, so a future consumer doesn't read a sampled event size as a queue level.

Proposed PR (mapping and docs only)

  1. Move the SGLang entry: remove sglang:num_retracted_reqs from NumRequestsSwapped, and add sglang:num_retracted_requests_total to NumPreemptionsTotal.
  2. Update the two rows in docs/source/features/model-serving/multi-engine.rst.
  3. Add a fetcher test showing that an SGLang scrape carrying the counter resolves to NumPreemptionsTotal, and that NumRequestsSwapped no longer resolves for SGLang.

Out of scope: the scrape list, and DP-rank aggregation. The counter carries dp_rank like the other per-scheduler series, so summing it would follow #3446 once something reads it.

Questions

  1. Move the mapping, or keep the old gauge on NumRequestsSwapped and only add the counter?
  2. The counter needs SGLang ≥ v0.5.7, and the repo's samples pin v0.5.5.post3. Nothing reads either metric, so nothing regresses, but is ≥ v0.5.7 acceptable here?

This comes from reading the source at the linked tags, not from a live scrape. @MuonChaser, could I take row 2?

ManiBAJPAI22 avatar Nov 20 '26 23:11 ManiBAJPAI22

Thanks for following up, everyone. I checked the linked PRs: #3446 is merged and covers the generation-throughput row; #3473 is still open for the prefill metric rename/alias handling.

@DsThakurRawat @wynneyin please coordinate the prefill mapping work through #3473 to avoid parallel implementations. Keeping the legacy name available looks consistent with the older SGLang versions still used by the samples; the supported-version policy and whether to include inflight work remain maintainer decisions.

@bolubo @ManiBAJPAI22 I am not implementing rows 4 or 2, so there is no competing work from my side. Please proceed with your proposed investigations, subject to the repository's acceptance process. Keep decode-queue aggregation separate from the legacy retraction/preemption mapping, and leave the SGLang minimum-version and mapping-policy questions for maintainers before changing those contracts.

The broader checklist is still open: the merged throughput fix alone does not establish live PD queue behavior or complete the version/semantics coverage for every remaining metric.

MuonChaser avatar Nov 30 '26 08:11 MuonChaser