Skip to content

fix: skip cutoff length calculation for empty datasets - #233

Closed
xming521 wants to merge 1 commit into
masterfrom
fix/skip-empty-cutoff-len
Closed

xming521 wants to merge 1 commit into
masterfrom
fix/skip-empty-cutoff-len

Conversation

@xming521

@xming521 xming521 commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Skip cutoff_len calculation when preprocessing produces no valid QA pairs.
  • Emit a clear warning instead of invoking LLaMA-Factory with an empty dataset.

Why

When all messages are filtered or no QA pairs are matched, length_cdf.py is still invoked. LLaMA-Factory then fails with Instruction "train" corresponds to no data!, as seen in #92. There is no useful length statistic to compute for an empty dataset.

Scope

  • 1 file changed, +4 / -1
  • Non-empty datasets keep the existing behavior unchanged.
  • The empty result file is still saved as before.

This addresses the follow-on error shown in #92 without changing the filtering/matching logic that produced zero samples.

Sourcery 总结

错误修复:

  • 当预处理未生成有效的 QA 对时,跳过截断长度计算并发出警告,避免下游训练因数据集为空而失败。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Skip cutoff length calculation and warn when preprocessing produces no valid QA pairs, preventing downstream training failures on empty datasets.

Copilot AI lite review requested due to automatic review settings September 25, 2026 07:20
@sourcery-ai

sourcery-ai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
审阅者指南(小型 PR 中默认折叠)

审阅者指南

该 PR 在截止长度计算周围添加了空结果保护:对于非空数据集保留现有行为;当预处理未生成有效 QA 对时发出警告,而不是调用下游处理。

空 QA 结果处理流程图

flowchart TD
    A[Preprocess chat records] --> B[save_result qa_res]
    B --> C{qa_res is non-empty}
    C -->|Yes| D["_execute_length_cdf_script()"]
    C -->|No| E[logger.warning]
    D --> F[Log processing success]
    E --> F
Loading

文件级变更

变更 详情 文件
防止在预处理结果为空时计算截止长度。
  • 像之前一样保存生成的 QA 结果。
  • 仅当至少存在一个有效 QA 对时运行长度 CDF 脚本。
  • 当未生成有效 QA 对时记录警告,从而避免下游 LLaMA-Factory 出现空数据集故障。
weclone/data/qa_generator.py

可能相关的问题


提示和命令

与 Sourcery 交互

  • 触发新的审阅: 在拉取请求中评论 @sourcery-ai review。
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 根据审阅评论生成 GitHub issue: 回复审阅评论,请 Sourcery 根据该评论创建 issue。你也可以使用 @sourcery-ai issue 回复审阅评论,以根据该评论创建 issue。
  • 生成拉取请求标题: 在拉取请求标题中的任意位置写入 @sourcery-ai,即可随时生成标题。你也可以在拉取请求中评论 @sourcery-ai title,以随时(重新)生成标题。
  • 生成拉取请求摘要: 在拉取请求正文中的任意位置写入 @sourcery-ai summary,即可在指定位置随时生成 PR 摘要。你也可以在拉取请求中评论 @sourcery-ai summary,以随时(重新)生成摘要。
  • 生成审阅者指南: 在拉取请求中评论 @sourcery-ai guide,即可随时(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,这一功能会很有用。
  • 忽略所有 Sourcery 审阅: 在拉取请求中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 审阅。如果你想通过新的审阅重新开始,这一功能尤其有用——别忘了评论 @sourcery-ai review 以触发新的审阅!

自定义使用体验

访问你的控制面板以:

  • 启用或禁用审阅功能,例如 Sourcery 生成的拉取请求摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、删除或编辑自定义审阅说明。
  • 调整其他审阅设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR adds an empty-result guard around cutoff length calculation, preserving existing behavior for non-empty datasets while warning instead of invoking downstream processing when preprocessing produces no valid QA pairs.

Flow diagram for empty QA result handling

flowchart TD
    A[Preprocess chat records] --> B[save_result qa_res]
    B --> C{qa_res is non-empty}
    C -->|Yes| D["_execute_length_cdf_script()"]
    C -->|No| E[logger.warning]
    D --> F[Log processing success]
    E --> F
Loading

File-Level Changes

Change Details Files
Guard cutoff length calculation against empty preprocessing results.
  • Save the generated QA results as before.
  • Run the length CDF script only when at least one valid QA pair exists.
  • Log a warning when no valid QA pairs are generated, avoiding the downstream LLaMA-Factory empty-dataset failure.
weclone/data/qa_generator.py

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

嗨——我已经审阅了你的更改,整体看起来很棒!


Sourcery 对开源项目免费——如果你喜欢我们的审查结果,请考虑分享它们 ✨
Original comment in English

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Empty-result cleaning can still trigger model inference before the new guard.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes empty-dataset handling by skipping cutoff-length calculation and warning instead.

Changes:

  • Preserves saving empty results.
  • Skips length calculation for empty QA results.
  • Reviewed cleaning path may still invoke inference before the guard.
File Summary
weclone/​data/​qa_generator.py Adds empty-result handling, but enabled cleaning can still process empty inputs before the guard.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +150 to +153
if qa_res:
self._execute_length_cdf_script()
else:
logger.warning("No valid QA pairs generated; skipping cutoff_len calculation.")
@xming521 xming521 closed this Sep 25, 2026
@xming521
xming521 deleted the fix/skip-empty-cutoff-len branch September 25, 2026 09:12
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.

2 participants