From 7f0f0cfbdceb16cc7fd1f9b7a2293ac61e5894e9 Mon Sep 17 00:00:00 2001 From: rockdu Date: Wed, 25 Nov 2026 13:23:48 -0800 Subject: [PATCH] test(fsdp): stop the ported threaded tests dying in teardown 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 --- .../backends/fsdp_utils/torch_ported/sitecustomize.py | 6 ++++++ .../backends/fsdp_utils/torch_ported/test_upstream_fsdp.py | 2 ++ 2 files changed, 8 insertions(+) diff --git a/tests/fast-gpu/backends/fsdp_utils/torch_ported/sitecustomize.py b/tests/fast-gpu/backends/fsdp_utils/torch_ported/sitecustomize.py index aec6dc2b4..215246767 100644 --- a/tests/fast-gpu/backends/fsdp_utils/torch_ported/sitecustomize.py +++ b/tests/fast-gpu/backends/fsdp_utils/torch_ported/sitecustomize.py @@ -1,6 +1,12 @@ import torch +from torch.testing._internal.distributed.multi_threaded_pg import ThreadLocalWorld from miles.backends.fsdp_utils.monkey_patches.fsdp_param_dtype_patch import apply_param_dtype_map_patch apply_param_dtype_map_patch() torch.use_deterministic_algorithms(True) + +# torch 2.11's destroy_process_group reads _world.comms, which that release's threaded test world lacks: every thread +# of a threaded test raises in its teardown, and the interpreter has segfaulted while they printed their tracebacks. +if not hasattr(ThreadLocalWorld, "comms"): + ThreadLocalWorld.comms = property(lambda self: []) diff --git a/tests/fast-gpu/backends/fsdp_utils/torch_ported/test_upstream_fsdp.py b/tests/fast-gpu/backends/fsdp_utils/torch_ported/test_upstream_fsdp.py index fc5abed3e..5e4b39405 100644 --- a/tests/fast-gpu/backends/fsdp_utils/torch_ported/test_upstream_fsdp.py +++ b/tests/fast-gpu/backends/fsdp_utils/torch_ported/test_upstream_fsdp.py @@ -36,6 +36,8 @@ def _run_ported_test(filename, *selectors): assert result.returncode == 0, result.stdout + result.stderr # site.py swallows sitecustomize errors, which would run the ported tests unpatched assert "Error in sitecustomize" not in result.stderr, result.stderr + # a thread that raises outside its test body fails no test; only its traceback shows it + assert "Exception in thread" not in result.stderr, result.stderr def test_fully_shard_mixed_precision():