Skip to content

[Feature]: 收敛 model_postprocessors 重复实现,废弃模块改为再导出 #704

Open

Description

@SJTUyh

💻 需求背景、当前现状、期望实现的功能内容、具体的设计方案、以及测试方案

需求背景

ais_bench/benchmark/utils/model_postprocessors.py 已在文件头提示废弃,并指向新路径 ais_bench/benchmark/utils/postprocess/model_postprocessors.py,但实现没有真正收敛:两个模块各自完整复制了一份 extract_non_reasoning_content(旧模块第 12-76 行,新模块第 34-98 行),并且都用同一个 key extract-non-reasoning-content 注册到 TEXT_POSTPROCESSORS。

当前现状

  1. 重复实现:两份 65 行实现(含 docstring)完全一致,任一逻辑修正都必须同步改两处。
  2. 重复注册:ais_bench/benchmark/registry.py:68-73 的 register_module 默认 force=True,同名 key 由后导入者覆盖先导入者。旧路径仍被 plugin_examples/config_example/perf_example.py:7、plugin_examples/README.md:77、smoke_tests/test-case/run_other_commands/common_commands/custom_py_config_dir/ais_bench_configs/models/vllm_api/custom_py_config_dir.py:2 以及 tests/UT/utils/test_model_postprocessors.py:23 引用,因此最终生效的函数对象取决于导入顺序。
  3. 当前两份实现一致,问题不会立刻暴露;一旦只修改其中一份(例如调整 token 匹配或日志),通过旧路径配置的任务会静默使用另一份实现。

期望实现的功能内容

  • 废弃模块保持公开 API 不变,仍可 from ais_bench.benchmark.utils.model_postprocessors import extract_non_reasoning_content,并保留废弃警告。
  • 删除旧模块中的函数副本与重复注册,改为从新模块再导出同一函数对象,使 extract-non-reasoning-content 在注册表中只有一个来源。
  • 不改变函数行为、参数、默认值、docstring、日志内容与注册 key。

具体的设计方案

文件:ais_bench/benchmark/utils/model_postprocessors.py(当前 76 行),改为薄兼容层,例如:

"""Deprecated compatibility shim; use ais_bench.benchmark.utils.postprocess.model_postprocessors."""

from ais_bench.benchmark.utils.logging import AISLogger
from ais_bench.benchmark.utils.postprocess.model_postprocessors import (  # noqa: F401
    extract_non_reasoning_content,
)

logger = AISLogger()
logger.warning(
    "ais_bench.benchmark.utils.model_postprocessors is deprecated, "
    "please use ais_bench.benchmark.utils.postprocess.model_postprocessors instead."
)
  • 新模块 ais_bench/benchmark/utils/postprocess/model_postprocessors.py 不做修改。
  • 副作用说明:导入旧模块会连带导入新模块,因此 keep-reasoning-content 与 extract-non-reasoning-content-raw 也会被注册;两者本来就由官方路径提供,不改变 extract-non-reasoning-content 的解析结果。
  • 旧模块不再需要 import re 与 TEXT_POSTPROCESSORS 导入。

测试方案

  1. 复用现有单测:python -m pytest tests/UT/utils/test_model_postprocessors.py -q,其中 test_deprecated_module_exports_current_api 与注册断言可直接覆盖兼容层的导出与注册。
  2. 新增断言:旧路径与新路径导出的函数是同一对象,即 mp.extract_non_reasoning_content is postprocess_extract_non_reasoning_content。
  3. 新增顺序无关性用例:先导入新模块再导入旧模块,断言 TEXT_POSTPROCESSORS.get('extract-non-reasoning-content') 仍指向新模块函数。
  4. 编译检查:python -m compileall ais_bench/benchmark/utils/model_postprocessors.py。
  5. 手工核对引用方无需改动即可导入:plugin_examples/config_example/perf_example.py 与 smoke 用例中的 custom_py_config_dir.py。

替代方案

  • 保留两份实现仅加注释提醒同步:无法阻止导入顺序覆盖注册表,问题依旧存在。
  • 直接删除旧模块:会破坏 plugin_examples、smoke 用例与现有单测中的导入,属于不兼容变更。
  • 将实现下沉到中性模块后两边各自导入:仍会在两个模块各注册一次同名 key,除非废弃模块只做再导出;与首选方案相比多一个文件,收益不变。

补充说明

  • 核对基线:仓库 commit da7ece4430e723e390b46b915a6122c886b06929(与知识库索引 sha 一致)。
  • 结构核对:对两个函数的 decorator 与 body 做 AST 对比,结果完全一致(含 docstring),参数与默认值一致。
  • 该改动为纯重构,不涉及评测流程、数据集或结果格式,不新增依赖。

本 Issue 由 Agent「trae-local」生成,经 @SJTUyh 审核后以本人身份创建。

Activity

  1. github-actions commented on Nov 23, 2026

    @github-actions

    🌟欢迎给AISBench benchmark测评工具提issue,我们会尽快处理您的诉求~

  2. github-actions commented on Nov 23, 2026

    @github-actions

    🤖 基于AI机器人的issue内容完整性检查结果:

    问题内容检查结果

    检查状态

    FAIL

    详细检查

    • 问题/痛点描述: COMPLETE
    • 建议方案: COMPLETE
    • 预期价值: INCOMPLETE

    👉 如果想重新检查,在评论区@issue_checker即可。

    【强烈推荐❤️‍🔥】确保issue描述完整后,可以试着将issue交给Ask DeepWiki回答,deepwiki包含了和工具相关的所有知识库

  3. added
    content_check_failed
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    content_check_failedfeaturerefactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions