Report cached token retention statistics when filtering datasets by max_length
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
This issue has not been assessed yet.
Description
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 | NoWith 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.
- Dominant language
- Python
- Stars
- 16.2k
- Forks
- 1.8k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 68
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from modelscope/ms-swift
-
get_multimodal_target_regex(..., exclude_router=True) does not exclude shared_expert_gatePossibly taken @KonnyakuMatcha claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
modelscope/ms-swift#10696 ·
Maintainers usually reply within 1 day
-
[BUG] GRPO REAL loss crashes with beta>0 and kl_in_reward=True (NoneType * Tensor)Possibly taken @newcloud123 claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
modelscope/ms-swift#10690 ·
Maintainers usually reply within 1 day
-
[BUG] GRPO REAL loss divides by all groups instead of valid groups, silently scaling gradientsPossibly taken @newcloud123 claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
modelscope/ms-swift#10688 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 Half a day Newbie friendliness 62/100
modelscope/ms-swift#10621 ·
Maintainers usually reply within 1 day
-
[Bug] `get_seed` consumes a draw from the shared RandomState even when decision augmentation is disabled, changing the train/val split and dataset shufflePossibly taken @ryznren claimed this 38 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
modelscope/ms-swift#10466 · 1 comment ·
Maintainers usually reply within 1 day
All issues in modelscope/ms-swift
Similar issues
-
Test: to_hijri() accepts datetime.datetime and uses only the date partPossibly taken A pull request linked to this issue is open or already merged. Opengood first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
omarelshamy25x/shamy-hijri#63 · 3 comments ·
Maintainers usually reply within 1 day
-
polish
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
521xueweihan/HelloGitHub#4729 ·
-
[Bug]: Score parser reads parts of scientific notation as valid scoresPossibly taken @AshutoshSingh840 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
UKGovernmentBEIS/control-arena#992 ·
Maintainers usually reply within 3 days
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
mvalentsev/awesome-free-ai-coding#70 ·
Maintainers usually reply within 1 day