Skip to content

test(fsdp): stop the ported threaded tests dying in teardown - #426

Open
Rockdu wants to merge 1 commit into
mainfrom
fix/ported-fsdp-threaded-world-comms
Open

Rockdu wants to merge 1 commit into
mainfrom
fix/ported-fsdp-threaded-world-comms

Conversation

@Rockdu

@Rockdu Rockdu commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

test_fully_shard_collective_ops fails intermittently in the nightly with exit code -11: run 45654740589 on 2026-11-25 and run 43735884533 on 2026-11-15, 2 of the last 12 nightlies, on the same image digest as the green runs between them. The three commits between the last green nightly and the 11-25 failure touch none of miles/backends/fsdp_utils, tests/fast-gpu and the image.

What

  • torch_ported/sitecustomize.py gives torch's ThreadLocalWorld a comms property when it has none.
  • _run_ported_test fails when the captured stderr holds Exception in thread.

Why

  • torch 2.11's destroy_process_group reads _world.comms (distributed_c10d.py:2310). ThreadLocalWorld, the world of the threaded test backend, has no such attribute in v2.11.0; pytorch main has added it.
  • Every thread of a threaded test therefore raises AttributeError: 'ThreadLocalWorld' object has no attribute 'comms' in the finally of run_test_with_threaded_pg, after the test body. That fails no test; torch only prints the tracebacks, and it also skips perThreadTearDown().
  • TestFullyShardCollectiveOps runs 128 threads. The failing subprocess died inside the traceback printer (_PyErr_Display → _PyTraceBack_Print_Indented → PyFrame_GetCode) while they printed. Why CPython crashes there was not investigated; the fix removes the exceptions that are being printed.
  • The threaded backend never uses torchcomms, so an empty list is what destroy_process_group should see. The property is added only when missing, so a torch that has it is left alone.
  • The new assertion makes the teardown failure visible on every run instead of on the runs that happen to crash. Without the shim, the minimal test below prints the traceback on every run.

Validation

Check Where Result
A minimal MultiThreadedTestCase (8 threads, one all_reduce) without the shim torch 2.11.0, Python 3.12, CPU, macOS exit 0 and OK, with the comms AttributeError tracebacks on stderr
The same test with this sitecustomize.py, minus its two Miles-patch lines (miles is not importable on that machine) same exit 0 and OK, stderr holds no Exception in thread
pre-commit on the two files local passes

Not executed: the three ported tests themselves, which need CUDA. Their first run with this change is this PR's CI (run-ci-torch). The new assertion also covers test_fully_shard_mixed_precision and test_fully_shard_frozen; whether either prints a thread traceback today is not known until that run.

Files

  • tests/fast-gpu/backends/fsdp_utils/torch_ported/sitecustomize.py: the comms property.
  • tests/fast-gpu/backends/fsdp_utils/torch_ported/test_upstream_fsdp.py: the stderr assertion.

Checklist

  • pre-commit passes on the changed files (--all-files not run)
  • Added/updated tests for new behaviour (the stderr assertion)
  • pytest -x is green: not run, the touched tests need CUDA; see Validation
  • No launch flag, public flag or example changed

🤖 Generated with Claude Code

torch 2.11's destroy_process_group reads _world.comms, and that release's
ThreadLocalWorld (the world of the threaded test backend) has no such
attribute. Every thread of a threaded test therefore raises AttributeError
in the finally of run_test_with_threaded_pg, after the test body. That fails
no test: torch only prints the tracebacks. With the 128 threads of
TestFullyShardCollectiveOps printing at once, the interpreter has segfaulted
inside the traceback printer, which is the intermittent failure of
test_fully_shard_collective_ops in the nightly (exit -11).

sitecustomize gives ThreadLocalWorld the attribute when it is missing, so a
torch that has it is left alone. The wrapper now also fails on a thread that
raised outside its test body, which until now showed up only as a traceback
in the captured stderr of a passing run.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@Rockdu Rockdu added the run-ci-torch Run ported PyTorch regression tests on this PR label Nov 25, 2026

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

run-ci-torch Run ported PyTorch regression tests on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant