8000 Elastic training crashes on killed agent · Issue #150916 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

Elastic training crashes on killed agent #150916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andreacarrara-polimi opened this issue Apr 9, 2025 · 7 comments
Closed

Elastic training crashes on killed agent #150916

andreacarrara-polimi opened this issue Apr 9, 2025 · 7 comments
Labels
oncall: distributed Add this issue/PR to distributed oncall triage queue triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@andreacarrara-polimi
Copy link
andreacarrara-polimi commented Apr 9, 2025

🐛 Describe the bug

I'm trying to use Elastic to handle nodes joining or leaving during training. My setup runs two EC2 instances (Ubuntu 24.04, g4dn.xlarge, NVIDIA Tesla T4, driver 550, PyTorch in a venv). My script is minimal, reproducible and attached here. It's a simplified version of this example. Each node runs:

torchrun \
  --nproc-per-node=1 \
  --max-restarts=3 \
  --node-rank=0|1 \
  --nnodes=1:2 \
  --rdzv-id=001 \
  --rdzv-backend=c10d \
  --rdzv-endpoint=<IP> \
  script.py 50 10 --batch_size 32

Each node launches one agent, which manages one worker. The node with --node-rank=0 acts as the rendezvous server. If I kill its process, the training crashes as expected since it's a single point of failure. However, the problem is with the other node. Killing its worker results in correct behavior as the agent restarts it up to the value of --max-restarts. But when I kill its agent, the training crashes instead of continuing with the rendezvous node only. The full traceback of the exception is included below.

On the rendezvous node:

[rank1]:[E409 07:28:50.917104566 ProcessGroupNCCL.cpp:552] [Rank 1] Collective WorkNCCL(SeqNum=632, OpType=ALLREDUCE, NumelIn=1, NumelOut=1, Timeout(ms)=600000) raised the following async exception: NCCL error: remote process exited or there was a network error, NCCL version 2.21.5
ncclRemoteError: A call failed possibly due to a network error or a remote process exiting prematurely.
Last error:
socketProgress: Connection closed by remote peer ip-172-31-36-217.eu-north-1.compute.internal<59116>
Exception raised from checkForNCCLErrorsInternal at /pytorch/torch/csrc/distributed/c10d/ProcessGroupNCCL.cpp:2363 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::string) + 0x96 (0x7861000c31b6 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libc10.so)
frame #1: c10d::ProcessGroupNCCL::checkForNCCLErrorsInternal(std::shared_ptr<c10d::NCCLComm>&) + 0x220 (0x7860ad5f61c0 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #2: c10d::ProcessGroupNCCL::WorkNCCL::checkAndSetException() + 0x7b (0x7860ad5fe64b in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #3: c10d::ProcessGroupNCCL::watchdogHandler() + 0x650 (0x7860ad600590 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #4: c10d::ProcessGroupNCCL::ncclCommWatchdog() + 0x14d (0x7860ad6016ed in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #5: <unknown function> + 0x145c0 (0x78610022e5c0 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch.so)
frame #6: <unknown function> + 0x9caa4 (0x786100c9caa4 in /lib/x86_64-linux-gnu/libc.so.6)
frame #7: <unknown function> + 0x129c3c (0x786100d29c3c in /lib/x86_64-linux-gnu/libc.so.6)

[rank1]:[E409 07:28:50.919638087 ProcessGroupNCCL.cpp:2168] [PG ID 0 PG GUID 0(default_pg) Rank 1]  failure detected by watchdog at work sequence id: 632 PG status: last enqueued work: 632, last completed work: 631
[rank1]:[E409 07:28:50.919656087 ProcessGroupNCCL.cpp:667] Stack trace of the failed collective not found, potentially because FlightRecorder is disabled. You can enable it by setting TORCH_NCCL_TRACE_BUFFER_SIZE to a non-zero value.
Started epoch 19
[rank1]:[E409 07:28:50.740369821 ProcessGroupNCCL.cpp:681] [Rank 1] Some NCCL operations have failed or timed out. Due to the asynchronous nature of CUDA kernels, subsequent GPU operations might run on corrupted/incomplete data.
[rank1]:[E409 07:28:50.740390368 ProcessGroupNCCL.cpp:695] [Rank 1] To avoid data inconsistency, we are taking the entire process down.
[rank1]:[E409 07:28:50.740431045 ProcessGroupNCCL.cpp:1895] [PG ID 0 PG GUID 0(default_pg) Rank 1] Process group watchdog thread terminated with exception: NCCL error: remote process exited or there was a network error, NCCL version 2.21.5
ncclRemoteError: A call failed possibly due to a network error or a remote process exiting prematurely.
Last error:
socketProgress: Connection closed by remote peer ip-172-31-36-217.eu-north-1.compute.internal<59116>
Exception raised from checkForNCCLErrorsInternal at /pytorch/torch/csrc/distributed/c10d/ProcessGroupNCCL.cpp:2363 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::string) + 0x96 (0x7861000c31b6 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libc10.so)
frame #1: c10d::ProcessGroupNCCL::checkForNCCLErrorsInternal(std::shared_ptr<c10d::NCCLComm>&) + 0x220 (0x7860ad5f61c0 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #2: c10d::ProcessGroupNCCL::WorkNCCL::checkAndSetException() + 0x7b (0x7860ad5fe64b in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #3: c10d::ProcessGroupNCCL::watchdogHandler() + 0x650 (0x7860ad600590 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #4: c10d::ProcessGroupNCCL::ncclCommWatchdog() + 0x14d (0x7860ad6016ed in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #5: <unknown function> + 0x145c0 (0x78610022e5c0 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch.so)
frame #6: <unknown function> + 0x9caa4 (0x786100c9caa4 in /lib/x86_64-linux-gnu/libc.so.6)
frame #7: <unknown function> + 0x129c3c (0x786100d29c3c in /lib/x86_64-linux-gnu/libc.so.6)

terminate called after throwing an instance of 'c10::DistBackendError'
  what():  [PG ID 0 PG GUID 0(default_pg) Rank 1] Process group watchdog thread terminated with exception: NCCL error: remote process exited or there was a network error, NCCL version 2.21.5
ncclRemoteError: A call failed possibly due to a network error or a remote process exiting prematurely.
Last error:
socketProgress: Connection closed by remote peer ip-172-31-36-217.eu-north-1.compute.internal<59116>
Exception raised from checkForNCCLErrorsInternal at /pytorch/torch/csrc/distributed/c10d/ProcessGroupNCCL.cpp:2363 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::string) + 0x96 (0x7861000c31b6 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libc10.so)
frame #1: c10d::ProcessGroupNCCL::checkForNCCLErrorsInternal(std::shared_ptr<c10d::NCCLComm>&) + 0x220 (0x7860ad5f61c0 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #2: c10d::ProcessGroupNCCL::WorkNCCL::checkAndSetException() + 0x7b (0x7860ad5fe64b in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #3: c10d::ProcessGroupNCCL::watchdogHandler() + 0x650 (0x7860ad600590 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #4: c10d::ProcessGroupNCCL::ncclCommWatchdog() + 0x14d (0x7860ad6016ed in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #5: <unknown function> + 0x145c0 (0x78610022e5c0 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch.so)
frame #6: <unknown function> + 0x9caa4 (0x786100c9caa4 in /lib/x86_64-linux-gnu/libc.so.6)
frame #7: <unknown function> + 0x129c3c (0x786100d29c3c in /lib/x86_64-linux-gnu/libc.so.6)

Exception raised from ncclCommWatchdog at /pytorch/torch/csrc/distributed/c10d/ProcessGroupNCCL.cpp:1901 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::string) + 0x96 (0x7861000c31b6 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libc10.so)
frame #1: <unknown function> + 0xe5c6fc (0x7860ad25c6fc in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #2: <unknown function> + 0x145c0 (0x78610022e5c0 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch.so)
frame #3: <unknown function> + 0x9caa4 (0x786100c9caa4 in /lib/x86_64-linux-gnu/libc.so.6)
frame #4: <unknown function> + 0x129c3c (0x786100d29c3c in /lib/x86_64-linux-gnu/libc.so.6)

E0409 07:28:52.647000 1312 torch/distributed/elastic/multiprocessing/api.py:869] failed (exitcode: -6) local_rank: 0 (pid: 1318) of binary: /home/ubuntu/prototype-venv/bin/python3
Traceback (most recent call last):
  File "/home/ubuntu/prototype-venv/bin/torchrun", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/multiprocessing/errors/__init__.py", line 355, in wrapper
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/run.py", line 918, in main
    run(args)
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/run.py", line 909, in run
    elastic_launch(
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/launcher/api.py", line 138, in __call__
    return launch_agent(self._config, self._entrypoint, list(args))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/launcher/api.py", line 260, in launch_agent
    result = agent.run()
             ^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/metrics/api.py", line 137, in wrapper
    result = f(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/agent/server/api.py", line 711, in run
    result = self._invoke_run(role)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/agent/server/api.py", line 899, in _invoke_run
    self._restart_workers(self._worker_group)
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/metrics/api.py", line 137, in wrapper
    result = f(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/agent/server/api.py", line 702, in _restart_workers
    self._initialize_workers(worker_group)
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/metrics/api.py", line 137, in wrapper
    result = f(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/agent/server/api.py", line 683, in _initialize_workers
    self._rendezvous(worker_group)
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch
8000
/distributed/elastic/metrics/api.py", line 137, in wrapper
    result = f(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/agent/server/api.py", line 500, in _rendezvous
    rdzv_info = spec.rdzv_handler.next_rendezvous()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/rendezvous/dynamic_rendezvous.py", line 1162, in next_rendezvous
    self._op_executor.run(join_op, deadline, self._get_deadline)
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/rendezvous/dynamic_rendezvous.py", line 676, in run
    raise RendezvousClosedError
torch.distributed.elastic.rendezvous.api.RendezvousClosedError

On the other node:

W0409 07:28:49.530000 1359 torch/distributed/elastic/agent/server/api.py:719] Received 15 death signal, shutting down workers
W0409 07:28:49.531000 1359 torch/distributed/elastic/multiprocessing/api.py:897] Sending process 1365 closing signal SIGTERM
Traceback (most recent call last):
  File "/home/ubuntu/prototype-venv/bin/torchrun", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/multiprocessing/errors/__init__.py", line 355, in wrapper
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/run.py", line 918, in main
    run(args)
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/run.py", line 909, in run
    elastic_launch(
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/launcher/api.py", line 138, in __call__
    return launch_agent(self._config, self._entrypoint, list(args))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/launcher/api.py", line 260, in launch_agent
    result = agent.run()
             ^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/metrics/api.py", line 137, in wrapper
    result = f(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/agent/server/api.py", line 711, in run
    result = self._invoke_run(role)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/agent/server/api.py", line 870, in _invoke_run
    time.sleep(monitor_interval)
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/multiprocessing/api.py", line 84, in _terminate_process_handler
    raise SignalException(f"Process {os.getpid()} got signal: {sigval}", sigval=sigval)
torch.distributed.elastic.multiprocessing.api.SignalException: Process 1359 got signal: 15

This happens regardless of whether I use CTRL-C or kill <PID>. I’ve reviewed several related issues and discussions, like 67616, 67742, 147064 and this post. None of them address this scenario. Let me know if this behavior is expected or if I’m missing something. I’m happy to provide more details if needed.

Versions

PyTorch version: 2.6.0+cu124
Is debug build: False
CUDA used to build PyTorch: 12.4
ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.2 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.39

Python version: 3.12.3 (main, Feb  4 2025, 14:48:35) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-6.8.0-1026-aws-x86_64-with-glibc2.39
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: Tesla T4
Nvidia driver version: 550.144.03
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                         x86_64
CPU op-mode(s):                       32-bit, 64-bit
Address sizes:                        46 bits physical, 48 bits virtual
Byte Order:                           Little Endian
CPU(s):                               4
On-line CPU(s) list:                  0-3
Vendor ID:                            GenuineIntel
Model name:                           Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
CPU family:                           6
Model:                                85
Thread(s) per core:                   2
Core(s) per socket:                   2
Socket(s):                            1
Stepping:                             7
BogoMIPS:                             4999.99
Flags:                                fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch pti fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves ida arat pku ospke avx512_vnni
Hypervisor vendor:                    KVM
Virtualization type:                  full
L1d cache:                            64 KiB (2 instances)
L1i cache:                            64 KiB (2 instances)
L2 cache:                             2 MiB (2 instances)
L3 cache:                             35.8 MiB (1 instance)
NUMA node(s):                         1
NUMA node0 CPU(s):                    0-3
Vulnerability Gather data sampling:   Unknown: Dependent on hypervisor status
Vulnerability Itlb multihit:          KVM: Mitigation: VMX unsupported
Vulnerability L1tf:                   Mitigation; PTE Inversion
Vulnerability Mds:                    Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown
Vulnerability Meltdown:               Mitigation; PTI
Vulnerability Mmio stale data:        Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed:               Vulnerable
Vulnerability Spec rstack overflow:   Not affected
Vulnerability Spec store bypass:      Vulnerable
Vulnerability Spectre v1:             Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:             Mitigation; Retpolines; STIBP disabled; RSB filling; PBRSB-eIBRS Not affected; BHI Retpoline
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

Versions of relevant libraries:
[pip3] numpy==2.2.4
[pip3] nvidia-cublas-cu12==12.4.5.8
[pip3] nvidia-cuda-cupti-cu12==12.4.127
[pip3] nvidia-cuda-nvrtc-cu12==12.4.127
[pip3] nvidia-cuda-runtime-cu12==12.4.127
[pip3] nvidia-cudnn-cu12==9.1.0.70
[pip3] nvidia-cufft-cu12==11.2.1.3
[pip3] nvidia-curand-cu12==10.3.5.147
[pip3] nvidia-cusolver-cu12==11.6.1.9
[pip3] nvidia-cusparse-cu12==12.3.1.170
[pip3] nvidia-cusparselt-cu12==0.6.2
[pip3] nvidia-nccl-cu12==2.21.5
[pip3] nvidia-nvjitlink-cu12==12.4.127
[pip3] nvidia-nvtx-cu12==12.4.127
[pip3] torch==2.6.0
[pip3] torchaudio==2.6.0
[pip3] torchvision==0.21.0
[pip3] triton==3.2.0
[conda] Could not collect

cc @H-Huang @awgu @wanchaol @fegin @fduwjj @wz337 @wconstab @d4l3k

@andreacarrara-polimi andreacarrara-polimi changed the title Elastic training crashes when agent is killed Elastic training crashes on killed agent Apr 9, 2025
@colesbury colesbury added the oncall: distributed Add this issue/PR to distributed oncall triage queue label Apr 9, 2025
@weifengpy
Copy link
Contributor

@d4l3k for elastic issue. "handle nodes joining or leaving during training" seem to be similar to torchft

8000
Copy link
Member
d4l3k commented Apr 14, 2025

@andreacarrara-polimi calling kill -9 should avoid this behavior as we won't shutdown the rendezvous.

except SignalException as e:
logger.warning("Received %s death signal, shutting down workers", e.sigval)
self._shutdown(e.sigval)

@kiukchung is this intended behavior? Is there a better way to cleanly scale down a cluster?

@kiukchung
Copy link
Collaborator

@andreacarrara-polimi calling kill -9 should avoid this behavior as we won't shutdown the rendezvous.

pytorch/torch/distributed/elastic/agent/server/api.py

Lines 718 to 720 in f76b7ef

except SignalException as e:
logger.warning("Received %s death signal, shutting down workers", e.sigval)
self._shutdown(e.sigval)
@kiukchung is this intended behavior? Is there a better way to cleanly scale down a cluster?

Seems related to: #147064

@andreacarrara-polimi
Copy link
Author

@d4l3k for elastic issue. "handle nodes joining or leaving during training" seem to be similar to torchft

I wasn't aware of torchft before. From the documentation, it seems to automate checkpointing by saving and restoring from the last training step, rather than relying on manual checkpoints. Since it's still in an early stage, the documentation is quite sparse, so let me know if I've misunderstood anything.

Instead, I care about the elasticity of the underlying infrastructure. I’ve implemented checkpointing manually, which is standard practice. This kind of elasticity is exactly what Elastic focuses on, as outlined on the first page of its documentation.

@andreacarrara-polimi
Copy link
Author
andreacarrara-polimi commented Apr 15, 2025

@andreacarrara-polimi calling kill -9 should avoid this behavior as we won't shutdown the rendezvous.

pytorch/torch/distributed/elastic/agent/server/api.py

Lines 718 to 720 in f76b7ef

except SignalException as e:
logger.warning("Received %s death sig 8000 nal, shutting down workers", e.sigval)
self._shutdown(e.sigval)
@kiukchung is this intended behavior? Is there a better way to cleanly scale down a cluster?

I tested killing the agent on the other node using kill -9. Terminating just the agent doesn't clean up the worker, which keeps running. Therefore, the test is invalid. I also tried killing both the agent and worker at the same time with kill -9. The training still crashes, but the exception traceback changes:

[rank1]:[E415 21:17:08.996319560 ProcessGroupNCCL.cpp:552] [Rank 1] Collective WorkNCCL(SeqNum=335, OpType=ALLREDUCE, NumelIn=1, NumelOut=1, Timeout(ms)=600000) raised the following async exception: NCCL error: remote process exited or there was a network error, NCCL version 2.21.5
ncclRemoteError: A call failed possibly due to a network error or a remote process exiting prematurely.
Last error:
socketProgress: Connection closed by remote peer ip-172-31-45-209.eu-north-1.compute.internal<32926>
Exception raised from checkForNCCLErrorsInternal at /pytorch/torch/csrc/distributed/c10d/ProcessGroupNCCL.cpp:2363 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::string) + 0x96 (0x754ee7c6c1b6 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libc10.so)
frame #1: c10d::ProcessGroupNCCL::checkForNCCLErrorsInternal(std::shared_ptr<c10d::NCCLComm>&) + 0x220 (0x754e951f61c0 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #2: c10d::ProcessGroupNCCL::WorkNCCL::checkAndSetException() + 0x7b (0x754e951fe64b in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #3: c10d::ProcessGroupNCCL::watchdogHandler() + 0x650 (0x754e95200590 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #4: c10d::ProcessGroupNCCL::ncclCommWatchdog() + 0x14d (0x754e952016ed in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #5: <unknown function> + 0x145c0 (0x754ee7dd75c0 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch.so)
frame #6: <unknown function> + 0x9caa4 (0x754ee889caa4 in /lib/x86_64-linux-gnu/libc.so.6)
frame #7: <unknown function> + 0x129c3c (0x754ee8929c3c in /lib/x86_64-linux-gnu/libc.so.6)

[rank1]:[E415 21:17:08.998796906 ProcessGroupNCCL.cpp:2168] [PG ID 0 PG GUID 0(default_pg) Rank 1]  failure detected by watchdog at work sequence id: 335 PG status: last enqueued work: 335, last completed work: 334
[rank1]:[E415 21:17:08.998811843 ProcessGroupNCCL.cpp:667] Stack trace of the failed collective not found, potentially because FlightRecorder is disabled. You can enable it by setting TORCH_NCCL_TRACE_BUFFER_SIZE to a non-zero value.
Started epoch 49
[rank1]:[E415 21:17:09.777705594 ProcessGroupNCCL.cpp:681] [Rank 1] Some NCCL operations have failed or timed out. Due to the asynchronous nature of CUDA kernels, subsequent GPU operations might run on corrupted/incomplete data.
[rank1]:[E415 21:17:09.777727656 ProcessGroupNCCL.cpp:695] [Rank 1] To avoid data inconsistency, we are taking the entire process down.
[rank1]:[E415 21:17:09.777772692 ProcessGroupNCCL.cpp:1895] [PG ID 0 PG GUID 0(default_pg) Rank 1] Process group watchdog thread terminated with exception: NCCL error: remote process exited or there was a network error, NCCL version 2.21.5
ncclRemoteError: A call failed possibly due to a network error or a remote process exiting prematurely.
Last error:
socketProgress: Connection closed by remote peer ip-172-31-45-209.eu-north-1.compute.internal<32926>
Exception raised from checkForNCCLErrorsInternal at /pytorch/torch/csrc/distributed/c10d/ProcessGroupNCCL.cpp:2363 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::string) + 0x96 (0x754ee7c6c1b6 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libc10.so)
frame #1: c10d::ProcessGroupNCCL::checkForNCCLErrorsInternal(std::shared_ptr<c10d::NCCLComm>&) + 0x220 (0x754e951f61c0 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #2: c10d::ProcessGroupNCCL::WorkNCCL::checkAndSetException() + 0x7b (0x754e951fe64b in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #3: c10d::ProcessGroupNCCL::watchdogHandler() + 0x650 (0x754e95200590 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #4: c10d::ProcessGroupNCCL::ncclCommWatchdog() + 0x14d (0x754e952016ed in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #5: <unknown function> + 0x145c0 (0x754ee7dd75c0 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch.so)
frame #6: <unknown function> + 0x9caa4 (0x754ee889caa4 in /lib/x86_64-linux-gnu/libc.so.6)
frame #7: <unknown function> + 0x129c3c (0x754ee8929c3c in /lib/x86_64-linux-gnu/libc.so.6)

terminate called after throwing an instance of 'c10::DistBackendError'
  what():  [PG ID 0 PG GUID 0(default_pg) Rank 1] Process group watchdog thread terminated with exception: NCCL error: remote process exited or there was a network error, NCCL version 2.21.5
ncclRemoteError: A call failed possibly due to a network error or a remote process exiting prematurely.
Last error:
socketProgress: Connection closed by remote peer ip-172-31-45-209.eu-north-1.compute.internal<32926>
Exception raised from checkForNCCLErrorsInternal at /pytorch/torch/csrc/distributed/c10d/ProcessGroupNCCL.cpp:2363 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::string) + 0x96 (0x754ee7c6c1b6 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libc10.so)
frame #1: c10d::ProcessGroupNCCL::checkForNCCLErrorsInternal(std::shared_ptr<c10d::NCCLComm>&) + 0x220 (0x754e951f61c0 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #2: c10d::ProcessGroupNCCL::WorkNCCL::checkAndSetException() + 0x7b (0x754e951fe64b in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #3: c10d::ProcessGroupNCCL::watchdogHandler() + 0x650 (0x754e95200590 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #4: c10d::ProcessGroupNCCL::ncclCommWatchdog() + 0x14d (0x754e952016ed in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #5: <unknown function> + 0x145c0 (0x754ee7dd75c0 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch.so)
frame #6: <unknown function> + 0x9caa4 (0x754ee889caa4 in /lib/x86_64-linux-gnu/libc.so.6)
frame #7: <unknown function> + 0x129c3c (0x754ee8929c3c in /lib/x86_64-linux-gnu/libc.so.6)

Exception raised from ncclCommWatchdog at /pytorch/torch/csrc/distributed/c10d/ProcessGroupNCCL.cpp:1901 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::string) + 0x96 (0x754ee7c6c1b6 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libc10.so)
frame #1: <unknown function> + 0xe5c6fc (0x754e94e5c6fc in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch_cuda.so)
frame #2: <unknown function> + 0x145c0 (0x754ee7dd75c0 in /home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/lib/libtorch.so)
frame #3: <unknown function> + 0x9caa4 (0x754ee889caa4 in /lib/x86_64-linux-gnu/libc.so.6)
frame #4: <unknown function> + 0x129c3c (0x754ee8929c3c in /lib/x86_64-linux-gnu/libc.so.6)

E0415 21:17:11.418000 2840 torch/distributed/elastic/multiprocessing/api.py:869] failed (exitcode: -6) local_rank: 0 (pid: 2846) of binary: /home/ubuntu/prototype-venv/bin/python3
Traceback (most recent call last):
  File "/home/ubuntu/prototype-venv/bin/torchrun", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/multiprocessing/errors/__init__.py", line 355, in wrapper
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/run.py", line 918, in main
    run(args)
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/run.py", line 909, in run
    elastic_launch(
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/launcher/api.py", line 138, in __call__
    return launch_agent(self._config, self._entrypoint, list(args))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/launcher/api.py", line 260, in launch_agent
    result = agent.run()
             ^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/metrics/api.py", line 137, in wrapper
    result = f(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/agent/server/api.py", line 711, in run
    result = self._invoke_run(role)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/agent/server/api.py", line 899, in _invoke_run
    self._restart_workers(self._worker_group)
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/metrics/api.py", line 137, in wrapper
    result = f(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/agent/server/api.py", line 702, in _restart_workers
    self._initialize_workers(worker_group)
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/metrics/api.py", line 137, in wrapper
    result = f(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/agent/server/api.py", line 683, in _initialize_workers
    self._rendezvous(worker_group)
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/metrics/api.py", line 137, in wrapper
    result = f(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/agent/server/api.py", line 500, in _rendezvous
    rdzv_info = spec.rdzv_handler.next_rendezvous()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/prototype-venv/lib/python3.12/site-packages/torch/distributed/elastic/rendezvous/dynamic_rendezvous.py", line 1215, in next_rendezvous
    assert self._shared_tcp_store_server is not None
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

In an additional test, I stopped the other machine entirely. This caused the rendezvous node to crash with the same error as the original issue. In further tests, even killing the worker alone gives inconsistent results. Sometimes, the agent restarts it successfully up to --max_restarts times. Other times, it enters a loop of failed attempts until the training crashes:

Initialized process group
W0415 21:39:34.431000 1047 torch/distributed/elastic/multiprocessing/api.py:897] Sending process 1055 closing signal SIGTERM
Initialized process group
W0415 21:39:42.072000 1047 torch/distributed/elastic/multiprocessing/api.py:897] Sending process 1142 closing signal SIGTERM
Initialized process group
W0415 21:39:49.713000 1047 torch/distributed/elastic/multiprocessing/api.py:897] Sending process 1164 closing signal SIGTERM
...

Please try to reproduce this or share a working example if it behaves differently on your setup.

@andreacarrara-polimi
Copy link
Author

@andreacarrara-polimi calling kill -9 should avoid this behavior as we won't shutdown the rendezvous.
pytorch/torch/distributed/elastic/agent/server/api.py
Lines 718 to 720 in f76b7ef
except SignalException as e:
logger.warning("Received %s death signal, shutting down workers", e.sigval)
self._shutdown(e.sigval)
@kiukchung is this intended behavior? Is there a better way to cleanly scale down a cluster?

Seems related to: #147064

I agree. That's why I mentioned it in my post. While related, my issue presents a different case of buggy behavior in Elastic. That said, have you made any progress on #147064?

@fduwjj fduwjj added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Apr 23, 2025
@NikitaShalagin
Copy link
NikitaShalagin commented Apr 27, 2025

@kiukchung Are there any known cheap to implement temporary workarounds for this? I tried to wrap torchrun in a simple she'll script, that catches SIGTERM and then kill -9 workers and kill -9 agent (the idea was that workers won't call shutdown()), but it still results in rdvz closed error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
oncall: distributed Add this issue/PR to distributed oncall triage queue triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants
0