Skip to content

[megatron] Make FileSystemReader patch idempotent - #10034

Merged
tastelikefeet merged 1 commit into
modelscope:mainfrom
taking-lying-flat:fix/megatron-reader-patch-idempotent
Sep 4, 2026
Merged

[megatron] Make FileSystemReader patch idempotent#10034
tastelikefeet merged 1 commit into
modelscope:mainfrom
taking-lying-flat:fix/megatron-reader-patch-idempotent

Conversation

@taking-lying-flat

Copy link
Copy Markdown
Contributor

What this PR does

  • Skip _patch_torch_FileSystemReader() when the Swift reader wrapper is already installed.
  • Prevent repeated init_megatron_env() calls from nesting reader thread pools.

Why

Importing swift.megatron already calls init_megatron_env(), while the initializer is public and is also called explicitly in the NPU setup documentation. Before this change, every call captured the previously patched FileSystemReader.read_data and wrapped it again. With the default 16 workers, a second initialization could therefore fan out into 16 × 16 reader tasks.

Validation

  • All repository pre-commit hooks pass for swift/megatron/init.py.
  • A focused regression check with MCORE_READER_MAX_WORKERS=2 verifies that two patch attempts retain the same wrapper and invoke the underlying reader twice rather than four times.

@tastelikefeet
tastelikefeet merged commit 1fc4556 into modelscope:main Sep 4, 2026
2 of 3 checks passed
@taking-lying-flat
taking-lying-flat deleted the fix/megatron-reader-patch-idempotent branch September 5, 2026 04:39
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