Skip to content

[Cherry-Pick] [BugFix] fix speculative gauge metrics in multi api server (#7082)#7100

Merged
Jiang-Jia-Jun merged 2 commits intoPaddlePaddle:release/2.5from
liyonghua0910:release/2.5+20260330_fix_metrics
Mar 31, 2026
Merged

[Cherry-Pick] [BugFix] fix speculative gauge metrics in multi api server (#7082)#7100
Jiang-Jia-Jun merged 2 commits intoPaddlePaddle:release/2.5from
liyonghua0910:release/2.5+20260330_fix_metrics

Conversation

@liyonghua0910
Copy link
Copy Markdown
Collaborator

@liyonghua0910 liyonghua0910 commented Mar 31, 2026

Motivation

This PR fixes duplicated/incorrect speculative gauge metrics export under MultiAPIServer in multi-DP scenarios.

There are two issues:

  1. speculative gauge metrics were not fully filtered and re-registered during multiprocess metrics export, which could expose duplicated values or stale values from the multiprocess collector.
  2. MultiAPIServer did not isolate PROMETHEUS_MULTIPROC_DIR across DP instances, which could cause metric file collisions between different DP processes.

Modifications

  1. Fix the speculative metrics export logic in multiprocess mode:

    • correctly filter speculative gauge metrics from the multiprocess collector output
    • re-register speculative gauge metrics from in-memory main_process_metrics
    • cover both scalar speculative gauges and single-head speculative gauge metrics
  2. Isolate PROMETHEUS_MULTIPROC_DIR for each DP instance under MultiAPIServer:

    • ensure each DP process uses an independent multiprocess metrics directory
    • avoid cross-DP metric pollution and duplicated gauge samples
  3. Add unit tests for multiprocess gauge export:

    • regular gauge returns a single value without pid
    • speculative gauge returns a single value without pid
    • speculative single-head gauge returns a single value without pid

Usage or Command

Run unit tests:

pytest -q tests/metrics/test_metrics.py

Accuracy Tests

N/A. This PR does not change model computation or model outputs. It only fixes metrics export behavior.

Checklist

  • Add at least a tag in the PR title.
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests.
  • Provide accuracy results.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.

@paddle-bot
Copy link
Copy Markdown

paddle-bot bot commented Mar 31, 2026

Thanks for your contribution!

@liyonghua0910 liyonghua0910 changed the title [BugFix] fix speculative gauge metrics in multi api server [Cherry-Pick] [BugFix] fix speculative gauge metrics in multi api server (#7082) Mar 31, 2026
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.57576% with 14 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release/2.5@054add2). Learn more about missing BASE report.

Files with missing lines Patch % Lines
fastdeploy/metrics/metrics.py 50.00% 9 Missing and 4 partials ⚠️
fastdeploy/entrypoints/openai/multi_api_server.py 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff               @@
##             release/2.5    #7100   +/-   ##
==============================================
  Coverage               ?   69.07%           
==============================================
  Files                  ?      390           
  Lines                  ?    54109           
  Branches               ?     8525           
==============================================
  Hits                   ?    37377           
  Misses                 ?    14022           
  Partials               ?     2710           
Flag Coverage Δ
GPU 69.07% <57.57%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Jiang-Jia-Jun Jiang-Jia-Jun merged commit 5307838 into PaddlePaddle:release/2.5 Mar 31, 2026
34 of 37 checks passed
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.

3 participants