Report cached token retention statistics when filtering datasets by max_length

Aperta
#10,704 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

enhancement
Checklist / 检查清单
  • I have searched existing issues, and this is a new feature request. / 我已经搜索过现有的 issues,确认这是一个新的 Feature Request。
Feature Request Description / Feature Request 描述

Background

When using cached datasets for large-scale SFT, ms-swift filters samples exceeding max_length under the delete truncation strategy.

Currently, _select_dataset() in swift/pipelines/utils.py reports the number of samples before and after filtering, but does not report how many cached tokens are retained.

For long-context SFT and multi-turn Agent training, a relatively small proportion of removed samples may account for a substantial proportion of the total tokens.

Example

Consider a synthetic cached dataset with the following sequence lengths:

Sample | Tokens | Retained -- | -- | -- Sample 1 | 100 | Yes Sample 2 | 100 | Yes Sample 3 | 1000 | No

With max_length=100:

  • Sample retention rate: 66.67%

  • Cached token retention rate: 16.67%

Reporting only sample counts may therefore underestimate the amount of discarded training data.

Proposed Solution

Add cached token retention statistics to the existing dataset filtering logs, for example:

Dataset filtered, origin length: 3, filtered dataset length: 2
Cached tokens retained: 200/1200 (16.67%)

The statistics can be calculated using the existing cached sequence lengths and filtering mask, without loading a model or performing additional tokenization.

For list-valued sequence lengths, sum the lengths within each row for token statistics while preserving the existing filtering criterion.

This feature does not change dataset filtering behavior or training semantics. The reported counts represent cached sequence lengths rather than loss-bearing training tokens.

Expected Benefits

  • Improve transparency in cached dataset filtering.

  • Help users select appropriate context lengths.

  • Identify excessive token loss in long-context and multi-turn Agent training.

Pull Request / Pull Request 信息

I have prepared an initial implementation and regression tests in the following branch:

https://github.com/hamster-oom/ms-swift/tree/feat/cached-token-retention

I plan to submit a pull request after reviewing the implementation, completing the relevant tests, and receiving feedback on the proposed feature.

The implementation preserves the existing filtering behavior and introduces no additional dependencies.

Lingua principale
Python
Stelle
16.2k
Fork
1.8k
Merge medio
1g 14h
PR unite (30g)
68

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di modelscope/ms-swift

Tutte le issue di modelscope/ms-swift

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.