Repository navigation
[Feature]AISBench支持大模型响应异常检测 - #468
Conversation
|
🚫 PR 合入质量检查未通过,PR 已被禁止合入。 未通过项:
请按上述提示整改后,重新推送(push)或评论本 PR 即可触发再次检查。 |
There was a problem hiding this comment.
Pull request overview
This PR adds an optional “response anomaly detection” pipeline to AISBench that captures token ids + top-k logprobs from service-model responses, stages payloads into compressed shards, and runs msProbe’s detector in a background thread after inference to produce per-case anomaly results and live task-board status.
Changes:
- Add response-anomaly payload capture (API response parsing + request kwarg injection), staging (zstd jsonl shards), and background detection coordinator with resumable archives.
- Extend CLI/config/runner/task-board support to enable/monitor/cleanup the auxiliary ResponseAnomaly task across supported modes.
- Add packaging extras, documentation, and extensive unit tests for config generation, payload extraction, staging, and detection/resume flows.
Reviewed changes
Copilot reviewed 39 out of 39 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/UT/utils/test_response_anomaly.py | End-to-end and edge-case tests for detection coordinator (status/logging, resume, retention modes). |
| tests/UT/utils/test_response_anomaly_jsonl.py | Tests for zstd JSONL writer/staging + manifest generation. |
| tests/UT/tools/response_anomaly/test_gen_model_config.py | Tests for msProbe model-config wrapper tool (merge/copy/failure modes). |
| tests/UT/runners/test_base.py | Update TasksMonitor tmp cleanup and auxiliary-status handling tests. |
| tests/UT/openicl/icl_inferencer/output_handler/test_base_handler.py | Validate prediction writing stages payload separately. |
| tests/UT/models/api_models/test_vllm_custom_api_chat.py | Ensure vLLM chat requests ask for token ids when anomaly detection enabled. |
| tests/UT/models/api_models/test_response_anomaly_payload.py | Unit tests for payload extraction/accumulation from service responses (streaming + OpenAI-style logprobs). |
| tests/UT/cli/test_config_manager.py | Tests for response anomaly config normalization/validation and CLI overrides. |
| tests/UT/cli/test_argument_parser.py | Tests for new CLI arguments parsing. |
| setup.py | Add response_anomaly extra + CLI entrypoint for config generator. |
| requirements/response_anomaly.txt | New optional deps for msProbe (pinned) + zstandard. |
| docs/source_zh_cn/get_started/install.md | Installation docs for response anomaly optional deps. |
| docs/source_zh_cn/design/AISBench推理响应异常检测模块设计.md | Full design doc for response anomaly module. |
| docs/source_zh_cn/base_tutorials/all_params/models.md | Document model-level response_anomaly config fields. |
| docs/source_zh_cn/base_tutorials/all_params/mode.md | Document supported/unsupported modes for anomaly detection. |
| docs/source_zh_cn/base_tutorials/all_params/cli_args.md | Document new CLI flags and response anomaly config block. |
| docs/source_en/get_started/install.md | English installation docs for response anomaly optional deps. |
| docs/source_en/base_tutorials/all_params/models.md | English docs for model-level response_anomaly config fields. |
| docs/source_en/base_tutorials/all_params/mode.md | English docs for supported/unsupported modes. |
| docs/source_en/base_tutorials/all_params/cli_args.md | English docs for new CLI flags and response anomaly config block. |
| ais_bench/tools/response_anomaly/gen_model_config.py | New wrapper to run msProbe generator safely and merge outputs. |
| ais_bench/tools/response_anomaly/init.py | Package init for response anomaly tools. |
| ais_bench/benchmark/utils/response_anomaly.py | New background coordinator: detect, resume, archive payloads, write status/logs. |
| ais_bench/benchmark/utils/response_anomaly_jsonl.py | New zstd JSONL shard writer/reader + manifest builder. |
| ais_bench/benchmark/utils/config/build.py | Strip response_anomaly from model cfg before building model. |
| ais_bench/benchmark/runners/local.py | Preserve response anomaly status file during tmp cleanup. |
| ais_bench/benchmark/runners/base.py | Task-board: read ResponseAnomaly status without clearing; handle auxiliary tasks. |
| ais_bench/benchmark/openicl/icl_inferencer/output_handler/gen_inferencer_output_handler.py | Add response_anomaly_payload into prediction records when available. |
| ais_bench/benchmark/openicl/icl_inferencer/output_handler/base_handler.py | Stage payload to compressed shards and remove from predictions. |
| ais_bench/benchmark/openicl/icl_inferencer/icl_multiturn_inferencer.py | Pass response-anomaly staging runtime into output handler. |
| ais_bench/benchmark/openicl/icl_inferencer/icl_lmm_gen_inferencer.py | Pass response-anomaly staging runtime into output handler. |
| ais_bench/benchmark/openicl/icl_inferencer/icl_gen_inferencer.py | Pass response-anomaly staging runtime into output handler. |
| ais_bench/benchmark/openicl/icl_inferencer/icl_base_inferencer.py | Deepcopy model cfg; plumb staging runtime through inferencer. |
| ais_bench/benchmark/models/api_models/vllm_custom_api_chat.py | Request token ids when anomaly detection enabled. |
| ais_bench/benchmark/models/api_models/base_api.py | Extract/record/accumulate anomaly payload from text/stream responses. |
| ais_bench/benchmark/configs/models/vllm_api/vllm_api_general_chat.py | Document example response_anomaly model config block. |
| ais_bench/benchmark/cli/workers.py | Start coordinator post-infer; add ResponseAnomalyWait worker + dedicated monitor. |
| ais_bench/benchmark/cli/config_manager.py | Normalize/validate response anomaly config; inject request kwargs; reject unsupported modes. |
| ais_bench/benchmark/cli/argument_parser.py | Add new CLI flags: --response-anomaly and --response-anomaly-payload-retention. |
Suppressed comments (1)
ais_bench/benchmark/openicl/icl_inferencer/output_handler/base_handler.py:512
_stage_response_anomaly_payload()re-raises staging failures, which can prevent predictions from being persisted and turn an auxiliary feature into a hard failure. If staging fails (e.g., missing zstandard / filesystem issues), consider disabling staging and leavingresponse_anomaly_payloadinline in the prediction record so the main workflow can still complete.
try:
self._response_anomaly_staging_writer.write(json_data)
except Exception as exc:
self._response_anomaly_staging_error = exc
raise
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Move model-specific msProbe settings into model-level response_anomaly config - Use ILLDetector with configurable config.yaml/mtype_config.json/token2category paths - Add ais_bench-gen-response-anomaly-config tool wrapping the official msProbe generator - Auto-generate model configs from model_path when custom paths are absent - Make status board, resume inheritance and unsupported-mode gating robust
- Replace same-length non-prefix snapshots instead of dropping them - Reuse ResponseAnomalyCoordinator.STATUS_FILE_NAME in all call sites - Keep gen_model_config tools dir on failure and add tests - Remove redundant model_name fallback and simplify status file read
- Force logprobs/top_logprobs when response anomaly is enabled and validate - Extend monitor progress total for auxiliary tasks - Handle mixed full-token/current-topk stream chunks and ignore misaligned ones
…match id+uuid on resume - Run the official msProbe generator inside an isolated temp directory so a partial failure never clobbers the target mtype_config.json; merge generated files into the target only on success - Overwrite None-valued msprobe_config_path (set by ConfigManager) with the auto-generated path so user-tuned config.yaml thresholds take effect - Match inherited results on id+uuid instead of id alone so a re-inferred response is not assigned a stale anomaly result - Add tests for all three fixes
- Change the full-snapshot branch from >= to > so that a single-token chunk equal to the current state (two consecutive identical tokens in an incremental stream) falls through to the incremental-append branch instead of being silently dropped as a no-op snapshot - Cache the per-model anomaly config and ILLDetector so that a model with multiple datasets only generates its msProbe config and loads token2category once instead of once per dataset - Add test_stream_consecutive_identical_tokens_are_not_dropped
- Log a debug message when a misaligned streaming response chunk is dropped so payload misalignment is not silently ignored - Warn per model/dataset group when predictions are missing, and warn once when no service model/dataset groups are configured at all, instead of silently finishing with zero analyzed cases - Hoist the result directory mkdir out of the per-prediction loop - Add end-to-end tests for the _detect loop, the empty-prediction warning, and misaligned chunk logging
The normalized model name is written by AISBench and looked up by msProbe using the same split+join algorithm, so consecutive separators produce double dashes on both sides (foo__bar -> foo--bar). Lock this behavior with tests so a future cleanup cannot silently break the msProbe sync.
This reverts commit 0855249.
|
🚫 PR 合入质量检查未通过,PR 已被禁止合入。 未通过项:
请按上述提示整改后,重新推送(push)或评论本 PR 即可触发再次检查。 |
|
🚫 PR 合入质量检查未通过,PR 已被禁止合入。 未通过项:
请按上述提示整改后,重新推送(push)或评论本 PR 即可触发再次检查。 |
|
🚫 PR 合入质量检查未通过,PR 已被禁止合入。 未通过项:
请按上述提示整改后,重新推送(push)或评论本 PR 即可触发再次检查。 |
|
🚫 PR 合入质量检查未通过,PR 已被禁止合入。 未通过项:
请按上述提示整改后,重新推送(push)或评论本 PR 即可触发再次检查。 |
|
/pr_check |
|
🚫 PR 合入质量检查未通过,PR 已被禁止合入。 未通过项:
请按上述提示整改后,重新推送(push)或评论本 PR 即可触发再次检查。 |
|
/pr_check |
|
🚫 PR 合入质量检查未通过,PR 已被禁止合入。 未通过项:
请按上述提示整改后,重新推送(push)或评论本 PR 即可触发再次检查。 |
Thanks for your contribution; we appreciate it a lot. The following instructions will make your pull request healthier and help you get feedback more easily. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.
感谢您的贡献,我们非常重视。以下说明将使您的拉取请求更健康,更易于获得反馈。如果您不理解某些项目,请不要担心,只需提交拉取请求并从维护人员那里寻求帮助即可。
PR Type / PR类型
Related Issue | 关联 Issue
Fixes #(issue ID / issue 编号) / Relates to #(issue ID / issue 编号)
Relates to #467
🔍 Motivation / 变更动机
大模型服务推理过程中可能出现生僻字、乱码、重复输出、
NaN/Inflogprob 等响应异常。当前 AISBench 能够完成推理与评测,但缺少对服务返回内容的独立异常检测与审计能力。本 PR 集成 msProbe 的 Response Anomaly 能力,在不改变原有评测指标和主流程行为的前提下,为服务化模型推理增加 Case 级响应异常检测、结果落盘、进度展示以及断点续跑支持。
📝 Modification / 修改内容
1. 新增响应异常检测开关与配置
--response-anomaly/--no-response-anomaly:开启或关闭响应异常检测。--response-anomaly-payload-retention {all,anomalies,none}:配置 payload 保留策略。response_anomaly配置,并支持模型级response_anomaly配置覆盖。logprobs=Truetop_logprobs=20all、infer、infer_judge普通生成链路。perf/perf_viz、Agent、函数调用及自定义 Agent 类评测链路。2. 接入 msProbe 响应异常检测流程
ResponseAnomalyCoordinator:ILLDetector检测。skipped。unavailable/failed状态,不影响原有推理与评测主流程。3. 服务响应采集与 payload 存储
all:保留全部 payload。anomalies:仅保留异常、检测失败或检测不可用的 Case。none:不保留 payload。response_anomaly/<model_abbr>/<dataset_abbr>.jsonlid + uuid继承已完成检测结果,避免--reuse场景重复检测。4. 状态面板、日志与配置生成工具
ais_bench-gen-response-anomaly-config工具:mtype_config.json,避免多模型配置互相覆盖。response_anomaly,包含mindstudio-probe与zstandard。📐 Associated Test Results / 关联测试结果
生僻字、乱码、重复输出、

NaN/Inflogprob 等响应异常测试:中断续推

无
默认情况下
response_anomaly.enabled=False,未启用该功能时不改变现有推理、评测和结果文件行为。启用该功能后,服务端需要支持返回 token id 和 top-k logprobs;对于不支持的服务响应,AISBench 会将对应 Case 标记为
skipped,不会中断原有评测流程。启用响应异常检测后:
logprobs=True和固定top_logprobs=20,可能增加服务端返回数据量与推理开销。🌟 Use cases (Optional) / 使用案例(可选)
适用于以下场景:
NaN类异常响应。payload_retention='anomalies',仅保留异常样本及检测失败样本,方便后续问题定位。--reuse继续中断任务时复用已完成的异常检测结果,避免重复检测。✅ Checklist / 检查列表
Before PR:
After PR:
👥 Collaboration Info / 协作信息
🌟 Useful CI Command / 实用的CI命令
/gemini review/gemini summary/gemini help/readthedocs build/pr_check