[Bug] `get_seed` consumes a draw from the shared RandomState even when decision augmentation is disabled, changing the train/val split and dataset shuffle
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
Research direction
Start in swift/dataset/loader.py around lines 350 and 384, then read get_seed in swift/utils/np_utils.py and check how the shared RandomState is used by post_process, interleave, and shuffle_dataset. Done when disabled decision augmentation no longer consumes a draw and the downstream train/validation split and shuffle match the prior behavior; verify with a regression test for the disabled path.
Written by the indexing model from the issue text.
Description
Checklist / 检查清单
- I have searched existing issues, and this is a new bug report. / 我已经搜索过现有的 issues,确认这是一个新的 bug report。
Bug Description / Bug 描述
In swift/dataset/loader.py:384, get_seed(seed) is passed as an argument to init_decision_augment:
init_decision_augment(dataset_meta, decision_augment_config, get_seed(seed))
seed here is a stateful np.random.RandomState (converted once at loader.py:350), shared with post_process(..., random_state=seed) below and with the interleave / shuffle_dataset calls further down. get_seed consumes one draw from it (swift/utils/np_utils.py:24):
seed = random_state.randint(0, seed_max)
init_decision_augment returns immediately when augmentation is off:
if dataset_meta is None or augment_config is None:
return
But Python evaluates arguments eagerly, so the draw is consumed even on that early return. Every downstream consumer of the shared stream is shifted by one position.
Decision augmentation is disabled by default — DataArguments._decision_augment_enabled is False unless one of decision_drop_instructions / decision_subsample_options / decision_state_as_text / decision_shuffle_fields is set, and get_dataset_kwargs() then does not even pass decision_augment_config. So the code clearly intends this path to be inert, yet it silently changes the data pipeline for every user.
Effect: upgrading 4.5.x → 4.6 silently changes (a) which samples land in train vs val, and (b) the dataset shuffle order. No error, no warning.
How to Reproduce / 如何复现
Versions: 4.5.3 → 4.6.0
Minimal reproduction of the mechanism:
import numpy as np
M = np.iinfo(np.int32).max
def get_seed(rs):
return rs.randint(0, M)
def init_decision_augment(meta, cfg=None, augment_seed=42):
if meta is None or cfg is None:
return # early return, but get_seed() already ran
# v4.5.3: post_process is the first consumer
rs = np.random.RandomState(42)
split_453 = rs.permutation(10)
# v4.6: the extra draw shifts the stream
rs = np.random.RandomState(42)
init_decision_augment('meta', None, get_seed(rs))
split_460 = rs.permutation(10)
print(split_453) # [8 1 5 0 7 2 9 4 3 6]
print(split_460) # [5 0 9 6 2 1 8 4 7 3]
print(np.array_equal(split_453, split_460)) # False
Additional Information / 补充信息
No response
- Dominant language
- Python
- Stars
- 16.1k
- Forks
- 1.8k
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 70
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
-
🚨 Transformers v5.23.0 removes `ProcessingKwargs._defaults` which is used by Qwen-Omni / Gemma3Openquestion
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
modelscope/ms-swift#10538 · 1 comment ·
Maintainers usually reply within 1 day
-
[Bug] `swift --help` raises KeyError instead of showing CLI helpPossibly taken @haahy claimed this 38 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
modelscope/ms-swift#10287 ·
Maintainers usually reply within 1 day
-
[Bug] find_free_port() reports the last busy port as free when its scan window is exhaustedPossibly taken @Lesereingrape claimed this 42 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
modelscope/ms-swift#10263 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
modelscope/ms-swift#10095 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 42/100
modelscope/ms-swift#10543 ·
Maintainers usually reply within 1 day
All issues in modelscope/ms-swift
Similar issues
-
area: providers/aws priority: p2 size: S type: bug type: testing
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
finos/open-resource-broker#851 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
sandialabs/atlas-ui-3#1196 ·
Maintainers usually reply within 1 day
-
enhancement triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ShaftHQ/SHAFT_ENGINE#7902 ·
Maintainers usually reply within 1 day
-
[Bug]: GraphML export writes invalid XML when a value contains a control character (e.g. form feed)Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
topoteretes/cognee#6646 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
DOI-USGS/pywatershed#428 ·