Skip to content

fix: add per-test-file timeout to prevent CI from hanging 12h#149

Merged
mkunredd merged 2 commits into
rocm_devfrom
fix/unit-test-timeout
Jul 15, 2026
Merged

fix: add per-test-file timeout to prevent CI from hanging 12h#149
mkunredd merged 2 commits into
rocm_devfrom
fix/unit-test-timeout

Conversation

@mkunredd

Copy link
Copy Markdown
Collaborator

Summary

  • Add a 30-minute timeout wrapper around each torchrun invocation in run_unit_tests.sh
  • Exit code 124 (timeout) is caught and reported as a test failure
  • TEST_TIMEOUT env var allows overriding the limit without changing the script

Root Cause

test_model_configs.py (684 tests × 8 torchrun processes) was hanging for the entire 12h CI job timeout after the MORI commit (26912eb), which added early MORI shmem bootstrap and a new mori_ep process group registration in pretrain_gpt.py and fused_a2a.py. This appears to cause a deadlock in distributed process group initialization when torchrun --nproc_per_node=8 spawns workers for this test file.

Without a per-file timeout, one hung torchrun blocks all subsequent test files and consumes the entire 12h CI budget:

  • Run 29034209991: last log entry at 22:13:36, hit 12h timeout
  • test_model_configs.py started at T+5h44m and hung for ~6h16m

What changes

# Before: torchrun can hang forever per test file
torchrun --standalone --nproc_per_node=$NUM_GPUS -m pytest ... $file

# After: killed after 30 min and reported as failure
timeout "$TEST_TIMEOUT" \
    torchrun --standalone --nproc_per_node=$NUM_GPUS -m pytest ... $file
rc=$?
if [[ $rc -eq 124 ]]; then
    echo "TIMEOUT: $file exceeded ${TEST_TIMEOUT}s — marking as failed."
fi

Note

The underlying deadlock in test_model_configs.py needs a separate investigation. This PR ensures CI fails fast and continues running remaining test files rather than hanging until the job-level timeout kills everything.

test_model_configs.py (684 tests x 8 torchrun processes) was causing
the CI job to hang for the full 12h timeout due to a deadlock in
distributed process group initialization introduced by the MORI commit.

Add a 30-minute timeout per test file via `timeout` so a hung test
file is killed and reported as failed rather than blocking all
subsequent tests and consuming the entire CI time budget.
Comment thread run_unit_tests.sh Outdated
Per review feedback: timeout sends SIGTERM first, but torchrun child
processes can ignore it. Add --kill-after=300 so any processes still
alive 5 minutes after SIGTERM are forcibly SIGKILLed.

Also handle exit code 137 (SIGKILL) alongside 124 (SIGTERM timeout).

@matthiasdiener matthiasdiener left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@mkunredd
mkunredd merged commit d7f6739 into rocm_dev Jul 15, 2026
1 check failed
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