Skip to content

【Feature】 Adapt util/worker config typing and defaults for custom cfg - #239

Merged
SJTUyh merged 1 commit into
AISBench:masterfrom
GaoHuaZhang:swebench_part1
Apr 10, 2026
Merged

SJTUyh merged 1 commit into
AISBench:masterfrom
GaoHuaZhang:swebench_part1

Conversation

@GaoHuaZhang

@GaoHuaZhang GaoHuaZhang commented Apr 10, 2026 •

Copy link
Copy Markdown
Collaborator

PR Type / PR类型

  • Feature(功能新增)
  • Bugfix(Bug 修复)
  • Docs(文档更新)
  • CI/CD(持续集成/持续部署)
  • Refactor(代码重构)
  • Perf(性能优化)
  • Dependency(依赖项更新)
  • Test-Cases(测试用例更新)
  • Other(其他)

Related Issue | 关联 Issue
Relates to #N/A

🔍 Motivation / 变更动机

本次改动主要解决自定义配置与运行时配置适配不稳定的问题:

  1. 自定义数据集配置在缺少 reader_cfg/infer_cfg/eval_cfg 时容易报错,不利于快速接入。
  2. infer/eval worker 在覆盖运行参数时会重建配置,可能丢失用户已有配置字段。
  3. 配置中的 type 在运行态使用类对象更方便,但导出到配置文件时需要统一转换为字符串。

📝 Modification / 修改内容

  • 在 CustomConfigChecker 中放宽 datasets 必填项,仅要求 type 和 abbr。
  • 在 try_fill_in_custom_cfgs 中为缺失的 reader_cfg/infer_cfg/eval_cfg 自动补齐默认配置。
  • Infer/Eval worker 改为优先复用已有 infer/eval 配置,仅更新运行参数(并发、debug、dump 相关开关等),避免覆盖用户配置。
  • 运行阶段 task/runner/partitioner 等 type 使用类对象,新增 recur_convert_config_type,在导出配置前递归转换成字符串类型,保证落盘配置可读且兼容。
  • extract_non_reasoning_content 改为原生支持 str | list 输入,减少对装饰器依赖;同步更新 deprecated 模块相关单测。
  • 更新 UT 用例与覆盖率配置(排除 swebench 相关文件覆盖统计)。

📐 Associated Test Results / 关联测试结果

  • 已更新单元测试:
    • tests/UT/cli/test_config_manager.py
    • tests/UT/cli/test_workers.py
    • tests/UT/utils/test_model_postprocessors.py
  • 本地测试结果:未在本 PR 描述中附带完整执行日志(建议在 CI 中进一步验证)。

⚠️ BC-breaking (Optional) / 向后不兼容变更(可选)

无预期向后不兼容变更。
主要行为变化是自定义配置校验更宽松,并在缺省字段时自动补全默认值,属于兼容性增强。

⚠️ Performance degradation (Optional) / 性能下降(可选)

无明显性能退化。新增的递归类型转换只在配置导出前执行一次,开销较小。

🌟 Use cases (Optional) / 使用案例(可选)

  • 用户仅提供最小 datasets 配置(type + abbr)即可完成运行,缺失字段自动补齐。
  • 用户在配置文件中自定义了 infer/eval 详细参数,CLI 运行时仅更新必要运行参数,不再覆盖其个性化配置。

✅ Checklist / 检查列表

Before PR:

  • Pre-commit or other linting tools are used to fix the potential lint issues. / 使用预提交或其他 linting 工具来修复潜在的 lint 问题。
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests. / 修复的 Bug 已完全由单元测试覆盖,导致 Bug 的情况应在单元测试中添加。
  • The modification is covered by complete unit tests. If not, please add more unit tests to ensure the correctness. / 此拉取请求中的修改已完全由单元测试覆盖。如果不是,请添加更多单元测试以确保正确性。
  • All relevant documentation (API docs, docstrings, example tutorials) has been updated to reflect these changes. / 所有相关文档(API 文档、文档字符串、示例教程)已更新以反映这些更改。

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects. / 如果此拉取请求对下游或其他相关项目有潜在影响,应在那些项目中测试此 PR。
  • CLA has been signed and all committers have signed the CLA in this PR. / CLA 已签署,且本 PR 中的所有提交者均已签署 CLA。

👥 Collaboration Info / 协作信息

  • Suggested Reviewers / 建议审核人: @xxx
  • Relevant Module Owners / 相关模块负责人: @xxx
  • Other Collaboration Notes / 其他协作说明:建议重点关注 worker.update_cfg 的兼容性行为与 config dump 类型转换逻辑。

@GaoHuaZhang
GaoHuaZhang temporarily deployed to smoke-test-approval April 10, 2026 11:49 — with GitHub Actions Inactive

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors configuration management and worker initialization, introducing recursive type conversion for configurations and automating default values for missing dataset fields. The Infer and Eval workers were updated to handle existing configurations more robustly. Additionally, the extract_non_reasoning_content postprocessor was refactored to support list inputs natively, and new error codes for SWEBENCH were added. Review feedback highlights a redundant variable assignment in workers.py, suggests updating return type hints to reflect list support in postprocessors, and recommends hoisting regex compilation out of internal functions to improve performance when processing lists.

runner_cfg = new_cfg['eval']['runner']
runner_cfg['max_num_workers'] = self.args.max_num_workers
runner_cfg['max_workers_per_gpu'] = self.args.max_workers_per_gpu
runner_cfg['debug'] = runner_cfg['debug'] = self.args.debug or cfg.cli_args.debug

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is a redundant double assignment to runner_cfg['debug'].

Suggested change
runner_cfg['debug'] = runner_cfg['debug'] = self.args.debug or cfg.cli_args.debug
runner_cfg['debug'] = self.args.debug or cfg.cli_args.debug

text: str | list,
think_start_token: str = '<think>',
think_end_token: str = '</think>',
) -> str:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The return type hint should be updated to str | list since the function can now return a list of strings when the input text is a list.

Suggested change
) -> str:
) -> str | list:

Comment on lines +50 to +67
def _process_single(item: str):
# Keep historical behavior for non-string input.
if not isinstance(item, str):
return item
if think_start_token not in item and think_end_token in item:
result = item.split(think_end_token)[-1].strip()
logger.debug(
f"extract_non_reasoning_content: only end token present -> length={len(result)}"
)
return result

reasoning_regex = re.compile(rf'{think_start_token}(.*?){think_end_token}',
re.DOTALL)
non_reasoning_content = reasoning_regex.sub('', item).strip()
logger.debug(
f"extract_non_reasoning_content: removed reasoning sections -> length={len(non_reasoning_content)}"
)
return non_reasoning_content

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Compiling the regular expression inside _process_single is inefficient when processing a list of strings, as it will be recompiled for every item. It should be compiled once outside the inner function.

Suggested change
def _process_single(item: str):
# Keep historical behavior for non-string input.
if not isinstance(item, str):
return item
if think_start_token not in item and think_end_token in item:
result = item.split(think_end_token)[-1].strip()
logger.debug(
f"extract_non_reasoning_content: only end token present -> length={len(result)}"
)
return result
reasoning_regex = re.compile(rf'{think_start_token}(.*?){think_end_token}',
re.DOTALL)
non_reasoning_content = reasoning_regex.sub('', item).strip()
logger.debug(
f"extract_non_reasoning_content: removed reasoning sections -> length={len(non_reasoning_content)}"
)
return non_reasoning_content
reasoning_regex = re.compile(rf'{think_start_token}(.*?){think_end_token}',
re.DOTALL)
def _process_single(item: str):
# Keep historical behavior for non-string input.
if not isinstance(item, str):
return item
if think_start_token not in item and think_end_token in item:
result = item.split(think_end_token)[-1].strip()
logger.debug(
f"extract_non_reasoning_content: only end token present -> length={len(result)}"
)
return result
non_reasoning_content = reasoning_regex.sub('', item).strip()
logger.debug(
f"extract_non_reasoning_content: removed reasoning sections -> length={len(non_reasoning_content)}"
)
return non_reasoning_content

text: str | list,
think_start_token: str = '<think>',
think_end_token: str = '</think>',
) -> str:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The return type hint should be updated to str | list since the function can now return a list of strings when the input text is a list.

Suggested change
) -> str:
) -> str | list:

Comment on lines +47 to +64
def _process_single(item: str):
# Keep historical behavior for non-string input.
if not isinstance(item, str):
return item
if think_start_token not in item and think_end_token in item:
result = item.split(think_end_token)[-1].strip()
logger.debug(
f"extract_non_reasoning_content: only end token present -> length={len(result)}"
)
return result

reasoning_regex = re.compile(rf'{think_start_token}(.*?){think_end_token}',
re.DOTALL)
non_reasoning_content = reasoning_regex.sub('', item).strip()
logger.debug(
f"extract_non_reasoning_content: only end token present -> length={len(result)}"
f"extract_non_reasoning_content: removed reasoning sections -> length={len(non_reasoning_content)}"
)
return result
return non_reasoning_content

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Compiling the regular expression inside _process_single is inefficient when processing a list of strings. It should be compiled once outside the inner function.

Suggested change
def _process_single(item: str):
# Keep historical behavior for non-string input.
if not isinstance(item, str):
return item
if think_start_token not in item and think_end_token in item:
result = item.split(think_end_token)[-1].strip()
logger.debug(
f"extract_non_reasoning_content: only end token present -> length={len(result)}"
)
return result
reasoning_regex = re.compile(rf'{think_start_token}(.*?){think_end_token}',
re.DOTALL)
non_reasoning_content = reasoning_regex.sub('', item).strip()
logger.debug(
f"extract_non_reasoning_content: only end token present -> length={len(result)}"
f"extract_non_reasoning_content: removed reasoning sections -> length={len(non_reasoning_content)}"
)
return result
return non_reasoning_content
reasoning_regex = re.compile(rf'{think_start_token}(.*?){think_end_token}',
re.DOTALL)
def _process_single(item: str):
# Keep historical behavior for non-string input.
if not isinstance(item, str):
return item
if think_start_token not in item and think_end_token in item:
result = item.split(think_end_token)[-1].strip()
logger.debug(
f"extract_non_reasoning_content: only end token present -> length={len(result)}"
)
return result
non_reasoning_content = reasoning_regex.sub('', item).strip()
logger.debug(
f"extract_non_reasoning_content: removed reasoning sections -> length={len(non_reasoning_content)}"
)
return non_reasoning_content

@GaoHuaZhang GaoHuaZhang changed the title swebench part1 [Feature][Swebench] Adapt util/worker config typing and defaults for custom cfg Apr 10, 2026
@GaoHuaZhang GaoHuaZhang changed the title [Feature][Swebench] Adapt util/worker config typing and defaults for custom cfg 【Feature】 Adapt util/worker config typing and defaults for custom cfg Apr 10, 2026
@SJTUyh
SJTUyh merged commit 14c6e80 into AISBench:master Apr 10, 2026
7 of 8 checks passed

This branch was previously deployed

1 inactive deployment
smoke-test-approval — 249bbd17 Deployed Apr 10, 2026 by GaoHuaZhang via run_smoke_test_cases #118
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants