Skip to content

【TI-Consisent】Added Metric logits_stats to the ZMQ branch#6979

Open
liuruyan wants to merge 6 commits intoPaddlePaddle:developfrom
liuruyan:logit_stat_dev
Open

【TI-Consisent】Added Metric logits_stats to the ZMQ branch#6979
liuruyan wants to merge 6 commits intoPaddlePaddle:developfrom
liuruyan:logit_stat_dev

Conversation

@liuruyan
Copy link

@liuruyan liuruyan commented Mar 23, 2026

Motivation

背景:出于对训推一致性丰富检测指标及长期CI/CE监控考量,对sample之后的logits添加logits_stats(min/max/mean/std),用来保证确定性及稳定性。

Modifications

数据结构及接口:由于logprob与logits_stat同样是输出的重要检测指标且均从logits计算而来,暂时实现先将logits_stat存入LogprobsTensors数据结构保存,并升级logprob传播链路上相关接口,支持同时透传logits_stats

class LogprobsTensors(NamedTuple):
    """ """

    # [num_reqs, max_num_logprobs + 1]
    logprob_token_ids: paddle.Tensor
    # [num_reqs, max_num_logprobs + 1]
    logprobs: paddle.Tensor
    # [num_reqs]
    selected_token_ranks: paddle.Tensor
    # Logits statistics for each sequence (optional)
    logits_min: Optional[paddle.Tensor] = None  # [num_reqs]
    logits_max: Optional[paddle.Tensor] = None  # [num_reqs]
    logits_mean: Optional[paddle.Tensor] = None  # [num_reqs]
    logits_std: Optional[paddle.Tensor] = None
    ...

FLAG:添加与enable_logprob同级别model_config:self.compute_logits_stats = False,且在server启动时支持配置--compute-logits-stats

注:由于改变了返回字段,导致有些单测无法通过,所以改动单测文件,返回值中提出新增字段(logits_stats )

Usage or Command

  • 本功能暂时只支持ZMQ,流式与非流式测试均可正常返回
  • 启动FD服务时需要同时开启--compute-logits-stats,--enable-logprob
export FD_USE_GET_SAVE_OUTPUT_V1=1 
python -m fastdeploy.entrypoints.openai.api_server \
       --enable-logprob \
       --compute-logits-stats \
       ...  # more setting
  • 发送请求时需要指定logprobs=True,top_logprobs=0
response = client.chat.completions.create(
    model="null",
    messages=[
        {"role": "system", "content": "I'm a helpful AI assistant."},
        {"role": "user", "content": "把李白的静夜思改写为现代诗"},
    ],
    stream=True,  # False
    max_tokens=100,
    logprobs=True,
    top_logprobs=0
)

Accuracy Tests

本PR不涉及精度修改

Checklist

  • Add at least a tag in the PR title.
    • Tag list: [[FDConfig],[APIServer],[Engine], [Scheduler], [PD Disaggregation], [Executor], [Graph Optimization], [Speculative Decoding], [RL], [Models], [Quantization], [Loader], [OP], [KVCache], [DataProcessor], [BugFix], [Docs], [CI], [Optimization], [Feature], [Benchmark], [Others], [XPU], [HPU], [GCU], [DCU], [Iluvatar], [Metax]]
    • You can add new tags based on the PR content, but the semantics must be clear.
  • 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

paddle-bot bot commented Mar 23, 2026

Thanks for your contribution!

@paddle-bot paddle-bot bot added the contributor External developers label Mar 23, 2026
@codecov-commenter
Copy link

codecov-commenter commented Mar 24, 2026

Codecov Report

❌ Patch coverage is 65.45455% with 19 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@6f5aa88). Learn more about missing BASE report.

Files with missing lines Patch % Lines
fastdeploy/entrypoints/openai/serving_chat.py 51.72% 11 Missing and 3 partials ⚠️
fastdeploy/output/token_processor.py 28.57% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #6979   +/-   ##
==========================================
  Coverage           ?   73.83%           
==========================================
  Files              ?      399           
  Lines              ?    56093           
  Branches           ?     8853           
==========================================
  Hits               ?    41415           
  Misses             ?    11707           
  Partials           ?     2971           
Flag Coverage Δ
GPU 73.83% <65.45%> (?)

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.

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

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants