Skip to content

Fix training stop lifecycle with bounded process cleanup - #1320

Open
lzy-edu wants to merge 3 commits into
flagos-ai:mainfrom
lzy-edu:fix/bounded-training-stop
Open

lzy-edu wants to merge 3 commits into
flagos-ai:mainfrom
lzy-edu:fix/bounded-training-stop

Conversation

@lzy-edu

@lzy-edu lzy-edu commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

PR Category

Train

PR Types

Bug Fixes

PR Description

This PR fixes delayed training shutdown when a launcher remains alive after its workers have exited.

Problem

During two-node fault testing on both NVIDIA A100 and Hygon DCU, one node could finish its worker processes while its torchrun agent remained in PyTorch's exit barrier, waiting for other nodes.

The previous stop script sent termination signals without waiting for the training launcher to exit or escalating cleanup after a deadline. As a result, the stop command could return successfully while torchrun and the outer wrapper remained alive for approximately 300 seconds, delaying exit-code recording and final cleanup.

This complements #1271: the diagnostic monitor shutdown was handled there, while this PR addresses residual training launchers and workers.

Changes

  • Track each training launch using a unique inherited ownership token, PID start identities, hostname, and host boot ID.
  • Send SIGTERM to processes belonging to the current training launch and wait up to 30 seconds by default.
  • If processes remain, send SIGKILL to the owned launcher and workers, allowing the supervisor and outer wrapper a separate cleanup window to reap children and record exit codes.
  • Escalate cleanup of remaining owned wrapper/supervisor processes if necessary, and verify whether any processes remain.
  • Use PID identity checks and pidfds when signalling processes to protect against stale PID files and PID reuse.
  • Remove the global pkill -f torchrun fallback. Missing ownership state is reported as ownership_missing.
  • Record the training exit code separately from the stop outcome, distinguishing graceful termination, forced cleanup, and stop failure.
  • Wait for all SSH nodes to finish their stop scripts and propagate failures before clearing the active diagnostics run ID.
  • Apply the shared lifecycle handling to both Megatron and Native training backends.

The grace period and cleanup waits are configurable through experiment.runner.stop_timeout_s and stop_kill_timeout_s.

Track each training launch with a unique ownership token and PID start identities.
Wait for graceful termination, then clean only residual processes from that run.
Preserve launcher exit codes and require every SSH node to confirm shutdown before
clearing active diagnostic state. Make the 30-second grace period configurable.

Validate normal Qwen3 training, abnormal rank exit, manual stop and the torchrun
exit-barrier boundary through the formal two-node CLI on A100 and DCU. Run all
212 runner tests on each platform and the repository pre-commit checks.

Signed-off-by: liuzeyu <958354467@qq.com>

This branch has not been deployed

No deployments
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.

1 participant