Skip to content

Convert train loops and RayTrainGroup to async - #849

Merged
fzyzcjy merged 73 commits into
mainfrom
feat/refactor_dp/7
Apr 3, 2026
Merged

Convert train loops and RayTrainGroup to async#849
fzyzcjy merged 73 commits into
mainfrom
feat/refactor_dp/7

Conversation

@fzyzcjy

@fzyzcjy fzyzcjy commented Apr 1, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

fzyzcjy added 6 commits March 30, 2026 14:13
The field uses mpu.get_data_parallel_src_rank(with_context_parallel=True)
and is used with dp_cp_group_gloo, so it belongs in the dp_cp namespace.
…rlier

- Add set_parallel_state()/get_parallel_state() global accessors
- create_megatron_parallel_state no longer requires model; VPP fields
  derived from args (defaults to pipeline_model_parallel_size)
- verify_megatron_parallel_state checks against model config post-creation
- set_parallel_state called in initialize.init() right after
  _initialize_distributed, so ParallelState is available everywhere
- Both Megatron and FSDP actors updated
@fzyzcjy fzyzcjy changed the title refactor: convert RayTrainGroup and train loops to async Convert train loops and RayTrainGroup to async Apr 1, 2026
@fzyzcjy
fzyzcjy requested a review from yushengsu-thu as a code owner April 1, 2026 00:25

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request refactors the training pipeline to utilize Python's asyncio framework, replacing synchronous ray.get calls with async/await semantics. Key changes include converting RayTrainGroup methods to asynchronous functions, implementing a _broadcast helper for concurrent actor communication via asyncio.gather, and updating the training loops in train.py and train_async.py to support asynchronous execution and task-based parallelism. I have no feedback to provide as the implementation correctly transitions the logic to an asynchronous model.

@fzyzcjy
fzyzcjy requested a review from guapisolo as a code owner April 1, 2026 00:32
@fzyzcjy fzyzcjy changed the title Convert train loops and RayTrainGroup to async [DO NOT MERGE BEFORE #850] Convert train loops and RayTrainGroup to async Apr 1, 2026
fzyzcjy added 13 commits April 1, 2026 13:59
…an hook

Migrate all scattered mpu.get_data_parallel_* calls to use
get_parallel_state() accessors. Add pygrep pre-commit hook to
prevent future direct mpu.get_data_parallel_* usage.

Allowed exceptions: parallel.py (constructs ParallelState),
tools/convert_to_hf.py (standalone script without actor init).
…an hook

Migrate all scattered mpu.get_data_parallel_* calls to use
get_parallel_state() accessors. Add pygrep pre-commit hook to
prevent future direct mpu.get_data_parallel_* usage.

Allowed exceptions: parallel.py (constructs ParallelState),
tools/convert_to_hf.py (standalone script without actor init).
Prefix all data-parallel fields with intra_ to distinguish from
independent DP (cross-cell) fields that will be added later.
Prefix all data-parallel fields with intra_ to distinguish from
independent DP (cross-cell) fields that will be added later.
Extract repeating (rank, size, group) pattern into GroupInfo dataclass.
ParallelState fields become:
- intra_dp: GroupInfo
- intra_dp_cp: GroupInfo (with gloo_group and src_rank)
- cp: GroupInfo
- tp: GroupInfo

Access pattern changes: e.g. parallel_state.intra_dp_rank -> parallel_state.intra_dp.rank
fzyzcjy added 18 commits April 1, 2026 18:28
…ix lint warnings

- Use create_mode string param with inline if/else instead of async
  wrapper functions that could spuriously yield
- Add stacklevel=2 to warnings.warn calls (B028)
…h on unawaited coroutine

warnings.filterwarnings("error") alone doesn't crash: the warning fires
inside __del__, so the exception is swallowed by sys.unraisablehook.

Also: remove destroyed-pending-task logic (asyncio.run cancels pending
tasks on shutdown, so the warning is never triggered in practice).
Use shared _FATAL_ASYNC_PATTERN string to avoid regex duplication.
- Add pytest-asyncio install to CI workflow (both j2 template and generated yml)
- Configure asyncio_mode = "auto" in pyproject.toml
- Register asyncio marker to avoid strict-markers warning
- Replace deprecated asyncio.get_event_loop() with asyncio.run()
- Restore sys.unraisablehook in test fixture for proper test isolation
Revert the test extras approach — add pytest-asyncio directly to
requirements.txt so it is installed by default with pip install -e .
@fzyzcjy
fzyzcjy force-pushed the feat/refactor_dp/7 branch from 68799b4 to 35eb213 Compare April 1, 2026 10:28
@fzyzcjy

fzyzcjy commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator Author

ci status

image image

@fzyzcjy fzyzcjy changed the title [DO NOT MERGE BEFORE #850] Convert train loops and RayTrainGroup to async Convert train loops and RayTrainGroup to async Apr 3, 2026
Base automatically changed from feat/refactor_dp/6 to main April 3, 2026 06:10
fzyzcjy added 2 commits April 3, 2026 14:15
Resolve conflicts:
- actor_group.py: keep async _broadcast version (HEAD)
- placement_group.py: keep both imports (eager_create_task + compute_ray_pin_head_options)
- async_utils.py: keep HEAD + add main's logger and AsyncioGatherUtils
- pyproject.toml: keep asyncio_mode=auto, drop removed markers per main
- update_weight_from_distributed.py: accept deletion
Resolve conflicts combining async conversion (HEAD) with #839's
role/with_ref-at-init pattern (main):
- actor_group.py: init() now async + uses self.args/self.role/self.with_ref
- placement_group.py: call sites use parameterless init()
@fzyzcjy
fzyzcjy merged commit 3645cdf into main Apr 3, 2026
30 of 35 checks passed
@fzyzcjy
fzyzcjy deleted the feat/refactor_dp/7 branch April 3, 2026 06:21
GuanxingLu pushed a commit to GuanxingLu/miles that referenced this pull request Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants