Skip to content

Fix: Makes worker shutdown timeout configurable in torchrun#172596

Closed
efazal wants to merge 2 commits into
pytorch:mainfrom
efazal:fix-torchrun-timeout
Closed

Fix: Makes worker shutdown timeout configurable in torchrun#172596
efazal wants to merge 2 commits into
pytorch:mainfrom
efazal:fix-torchrun-timeout

Conversation

@efazal

@efazal efazal commented Jan 15, 2026

Copy link
Copy Markdown
Contributor

Fixes #119856

Previously, torchrun had a hardcoded 30s timeout between SIGTERM and SIGKILL. This was an issue for large model training where checkpoint saving exceeds 30s, k8s env's with longer terminationGracePeriodSeconds, and in SLURM preemption scenarios. The hardcoded timeout caused torchrun to send SIGKILL before workers completed graceful shutdown, even when the orchestrator allowed more time.

The fix adds a new configurable param "--shutdown-timeout", that takes timeout value via CLI args or falls back to TORCH_ELASTIC_SHUTDOWN_TIMEOUT env variable. Defaults to 30s otherwise, as it is currently.

Flows through: CLI → LaunchConfig → LocalElasticAgent → SimpleElasticAgent → PContext.close()

Added unit tests.

Please review and add anyone else who might be relevant @aivanou @Unturned3 @SandishKumarHN

@pytorch-bot

pytorch-bot Bot commented Jan 15, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/172596

Note: Links to docs will display an error until the docs builds have been completed.

❌ 3 New Failures, 1 Unrelated Failure

As of commit 6981ecb with merge base 3688cec (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jan 15, 2026

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

@jcaip jcaip requested review from aorenste, cyyever and d4l3k January 20, 2026 13:16
@zou3519 zou3519 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jan 20, 2026
Comment thread torch/distributed/launcher/api.py Outdated
@efazal efazal force-pushed the fix-torchrun-timeout branch 2 times, most recently from dd64b36 to 8b3ec62 Compare January 22, 2026 14:59
@efazal

efazal commented Jan 27, 2026

Copy link
Copy Markdown
Contributor Author

Hi @cyyever and @d4l3k would really appreciate your review on this PR. Thank you!

@efazal

efazal commented Feb 9, 2026

Copy link
Copy Markdown
Contributor Author

Hi @jcaip @aorenste, would it be possible to merge this fix please?

@efazal efazal requested a review from aorenste February 12, 2026 11:35

@aorenste aorenste 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.

Sorry - I was out last week. LGTM.

@efazal

efazal commented Feb 23, 2026

Copy link
Copy Markdown
Contributor Author

@jcaip @d4l3k @cyyever gentle reminder to review this PR please. It's been open for over 4 weeks now. Would really appreciate it. Thank you! 🙏

@jcaip

jcaip commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

I think this has been approved already, do you just need help landing?

@jcaip

jcaip commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Feb 23, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: trunk / macos-py3-arm64 / build

Details for Dev Infra team Raised by workflow job

@jcaip

jcaip commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

cc @efazal would you mind rebasing the PR? I think that should make the lintfailure go away (pkg_resources not found) The other faillures look unrelated to me.

@efazal efazal force-pushed the fix-torchrun-timeout branch from 8b3ec62 to 317ecdc Compare February 26, 2026 10:15
@pytorch-bot pytorch-bot Bot removed the ciflow/trunk Trigger trunk jobs on your pull request label Feb 26, 2026
@efazal

efazal commented Feb 26, 2026

Copy link
Copy Markdown
Contributor Author

Hi @jcaip, yes, I just need help in merging this PR. Thanks for your response. I've just rebased the PR. I hope this fixes the lint issue. Please let me know if anything is required from my end. Thanks.

@jcaip

jcaip commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Feb 27, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: Not merging any PRs at the moment because there is a merge blocking https://github.com/pytorch/pytorch/labels/ci:%20sev issue open at:
#176005

Details for Dev Infra team Raised by workflow job

@efazal efazal force-pushed the fix-torchrun-timeout branch from 317ecdc to 6981ecb Compare March 3, 2026 08:02
@pytorch-bot pytorch-bot Bot removed the ciflow/trunk Trigger trunk jobs on your pull request label Mar 3, 2026
@jcaip

jcaip commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

@pytorchbot merge

CI failure looks unrelated

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Mar 3, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@efazal

efazal commented Mar 5, 2026

Copy link
Copy Markdown
Contributor Author

Hi @jcaip, I'm not sure why the pre-merge CI checks keeps failing for this PR. They all seem unrelated to this. I wonder what can be done to resolve this? Please let me know if there is something I can do to resolve. Thank you.

@jcaip

jcaip commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

@efazal I don't think it's anything broken in your PR, it looks like a flaky test. Let me try force merging. Sorry about the delay!

@jcaip

jcaip commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

@pytorchbot merge -f CI failure looks unrelated, merge was reverted a couple times.

@pytorch-bot

pytorch-bot Bot commented Mar 5, 2026

Copy link
Copy Markdown

❌ 🤖 pytorchbot command failed:

@pytorchbot: error: unrecognized arguments: failure looks unrelated, merge was reverted a couple times.

usage: @pytorchbot [-h] {merge,revert,rebase,label,drci,cherry-pick} ...

Try @pytorchbot --help for more info.

@jcaip

jcaip commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

@pytorchbot merge -f "CI failure looks unrelated, merge was reverted a couple times"

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

EmanueleCoradin pushed a commit to EmanueleCoradin/pytorch that referenced this pull request Mar 30, 2026
…172596)

Fixes [pytorch#119856](pytorch#119856)

Previously, torchrun had a hardcoded 30s timeout between SIGTERM and SIGKILL. This was an issue for large model training where checkpoint saving exceeds 30s, k8s env's with longer `terminationGracePeriodSeconds`, and in SLURM preemption scenarios. The hardcoded timeout caused torchrun to send SIGKILL before workers completed graceful shutdown, even when the orchestrator allowed more time.

The fix adds a new configurable param "--shutdown-timeout", that takes timeout value via CLI args or falls back to `TORCH_ELASTIC_SHUTDOWN_TIMEOUT` env variable. Defaults to 30s otherwise, as it is currently.

Flows through: CLI → LaunchConfig → LocalElasticAgent → SimpleElasticAgent → PContext.close()

Added unit tests.

Please review and add anyone else who might be relevant @aivanou @Unturned3 @SandishKumarHN
Pull Request resolved: pytorch#172596
Approved by: https://github.com/aorenste
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged open source release notes: distributed (torchelastic) triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Timeout for process termination upon receiving sigterm should be a user configurable parameter

6 participants