pytorch / audio

Data manipulation and transformation for audio signal processing, powered by PyTorch
https://pytorch.org/audio
BSD 2-Clause "Simplified" License
2.43k stars 636 forks source link

Training Hangs During HuBERT Pretraining with DDP When Loss Becomes Invalid #3749

Closed jojonki closed 4 months ago

jojonki commented 4 months ago

🐛 Describe the bug

During pretraining HuBERT with custom data, I encountered a problem where the training would hang after progressing to a certain extent. It took considerable time to identify the issue, as no logs were generated until I received an NCCL 30-minute timeout error.

The problem arises in the following section: while training with LibriSpeech data didn't result in loss becoming NaN, it did happen with my custom data, leading to this issue. In the code below return None, it calls all_gather to aggregate num_frame. However, if NaN occurs in a specific GPU process, it never reaches this all_gather, causing the training to stall at this point. https://github.com/pytorch/audio/blob/b7b7b5d79a4630840ed32fef86f6d6e2d906f2b0/examples/hubert/lightning_modules.py#L252-L257

To reproduce the problem, by returning on any rank while using DDP (multiple GPUs). Enabling TORCH_DISTRIBUTED_DEBUG=DETAIL provides a stack trace, aiding in pinpointing the issue.

--- a/lightning_modules.py
+++ b/lightning_modules.py
@@ -251,7 +251,8 @@ class HuBERTPreTrainModule(LightningModule):
         opt.zero_grad()
         with torch.cuda.amp.autocast(enabled=True):
             loss, num_frame = self._step(batch, batch_idx, "train")
-        if torch.isinf(loss) or torch.isnan(loss):
+        if torch.isinf(loss) or torch.isnan(loss) or self.local_rank==0:
+            print("is none")
             opt.zero_grad()

To resolve this issue, we need to modify the code to ensure that all_gather is reached by all replicas. Otherwise, when encountering an invalid loss, sharing this information among processes via all_reduce and skipping the update for that step could be a viable solution.

Versions

python collect_env.py PyTorch version: 2.1.2+cu118 Is debug build: False

CUDA used to build PyTorch: 11.8 [0/168] ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.6 LTS (x86_64) GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0 Clang version: Could not collect CMake version: version 3.16.3 Libc version: glibc-2.31

Python version: 3.10.8 (main, Jun 8 2023, 10:18:35) [GCC 9.4.0] (64-bit runtime) Python platform: Linux-5.15.0-94-generic-x86_64-with-glibc2.31 Is CUDA available: True CUDA runtime version: Could not collect CUDA_MODULE_LOADING set to: LAZY GPU models and configuration: GPU 0: NVIDIA RTX A6000 GPU 1: NVIDIA RTX A6000 GPU 2: NVIDIA RTX A6000 GPU 3: NVIDIA RTX A6000

Nvidia driver version: 520.61.05 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 Byte Order: Little Endian Address sizes: 46 bits physical, 48 bits virtual CPU(s): 32 On-line CPU(s) list: 0-31 Thread(s) per core: 2 Core(s) per socket: 8 Socket(s): 2 NUMA node(s): 2 Vendor ID: GenuineIntel CPU family: 6 Model: 85 Model name: Intel(R) Xeon(R) Gold 6234 CPU @ 3.30GHz Stepping: 7 CPU MHz: 1200.000 CPU max MHz: 4000.0000 CPU min MHz: 1200.0000 BogoMIPS: 6600.00 Virtualization: VT-x L1d cache: 512 KiB L1i cache: 512 KiB L2 cache: 16 MiB L3 cache: 49.5 MiB NUMA node0 CPU(s): 0-7,16-23 NUMA node1 CPU(s): 8-15,24-31 Vulnerability Gather data sampling: Mitigation; Microcode Vulnerability Itlb multihit: KVM: Mitigation: VMX disabled Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable Vulnerability Retbleed: Mitigation; Enhanced IBRS Vulnerability Spec rstack overflow: Not affected Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Mitigation; TSX disabled Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulq dq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shad ow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pl n pts pku ospke avx512_vnni md_clear flush_l1d arch_capabilities

Versions of relevant libraries: [pip3] numpy==1.26.4 [pip3] pytorch-lightning==2.2.0 [pip3] torch==2.1.2+cu118 [pip3] torchaudio==2.1.2+cu118 [pip3] torchmetrics==1.3.1 [pip3] torchvision==0.16.0+cu118 [pip3] triton==2.1.0 [conda] Could not collect

nateanl commented 4 months ago

Hi @jojonki, thanks for reporting the bug. It is a known issue in pytorch_lightning (https://github.com/Lightning-AI/pytorch-lightning/issues/5243)

Would you like to open a PR for the fix? Thanks.

jojonki commented 4 months ago

Hi @nateanl Oh, I didn't know that. I will follow the issue. Thanks!