Deci-AI / super-gradients

Easily train or fine-tune SOTA computer vision models with one open source training library. The home of Yolo-NAS.
https://www.supergradients.com
Apache License 2.0
4.53k stars 490 forks source link

NAN loss while training locally on COCO type dataset #2049

Open anti79 opened 2 weeks ago

anti79 commented 2 weeks ago

💡 Your Question

Hi, I need some help with training a model. I've tried training with a custom script, but got NaN and 0 loss values during training, so I figured that the problem might be either with my dataset or with my code. So I decided to use a ready made notebook with a public Kaggle dataset to try to locate the issue. The notebook: https://colab.research.google.com/drive/1q0RmeVRzLwRXW-h9dPFSOchwJkThUy6d The dataset: https://www.kaggle.com/datasets/sharansmenon/aquarium-dataset Up to the point of training, all was going well, I got the model instantiated and loaded the labels. image

During training, the output was: `[2024-08-29 23:29:54] INFO - sg_trainer_utils.py - TRAINING PARAMETERS:

[2024-08-29 23:29:54] INFO - sg_trainer.py - Started training for 100 epochs (0/99)

Train epoch 0: 0%| | 0/111 [00:00<?, ?it/s]/home/daniel/.pyenv/versions/3.10.14/lib/python3.10/site-packages/super_gradients/training/sg_trainer/sg_trainer.py:502: FutureWarning: torch.cuda.amp.autocast(args...) is deprecated. Please use torch.amp.autocast('cuda', args...) instead. with autocast(enabled=self.training_params.mixed_precision): Train epoch 0: 10%|â–‰ | 11/111 [00:14<02:06, 1.26s/it, PPYoloELoss/loss=nan, PPYoloELoss/loss_cls=nan, PPYoloELoss/loss_dfl=nan, PPYoloELoss/loss_iou=nan, gpu_mem=1.75]`

Thought that maybe I need to wait for a couple epochs to pass to start getting loss values, but still the values remained NaN. I tried running the same code on a different machine, but got the same result. On Colab, however, the code finally worked, displaying the loss values.

My environment: `PyTorch version: 2.4.0+cu121 Is debug build: False CUDA used to build PyTorch: 12.1 ROCM used to build PyTorch: N/A

OS: Fedora Linux 40 (Xfce) (x86_64) GCC version: (GCC) 14.2.1 20240801 (Red Hat 14.2.1-1) Clang version: Could not collect CMake version: version 3.28.2 Libc version: glibc-2.39

Python version: 3.10.14 (main, Jun 30 2024, 01:17:49) [GCC 14.1.1 20240620 (Red Hat 14.1.1-6)] (64-bit runtime) Python platform: Linux-6.10.4-200.fc40.x86_64-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: NVIDIA GeForce GTX 1650 Nvidia driver version: 555.58.02 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: 43 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 12 On-line CPU(s) list: 0-11 Vendor ID: AuthenticAMD Model name: AMD Ryzen 5 3600X 6-Core Processor CPU family: 23 Model: 113 Thread(s) per core: 2 Core(s) per socket: 6 Socket(s): 1 Stepping: 0 Frequency boost: enabled CPU(s) scaling MHz: 86% CPU max MHz: 4756.6401 CPU min MHz: 2200.0000 BogoMIPS: 8199.84 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip rdpid overflow_recov succor smca sev sev_es Virtualization: AMD-V L1d cache: 192 KiB (6 instances) L1i cache: 192 KiB (6 instances) L2 cache: 3 MiB (6 instances) L3 cache: 32 MiB (2 instances) NUMA node(s): 1 NUMA node0 CPU(s): 0-11 Vulnerability Gather data sampling: Not affected Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Not affected Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Mitigation; untrained return thunk; SMT enabled with STIBP protection Vulnerability Spec rstack overflow: Mitigation; Safe RET Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Retpolines; IBPB conditional; STIBP always-on; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected

Versions of relevant libraries: [pip3] numpy==1.23.0 [pip3] onnx==1.15.0 [pip3] onnxruntime==1.15.0 [pip3] onnxsim==0.4.36 [pip3] torch==2.4.0 [pip3] torchmetrics==0.8.0 [pip3] torchvision==0.19.0 [pip3] triton==3.0.0 [conda] Could not collect`

Environment on second machine: `PyTorch version: 2.4.0+cu121 Is debug build: False CUDA used to build PyTorch: 12.1 ROCM used to build PyTorch: N/A

OS: Kali GNU/Linux Rolling (x86_64) GCC version: (Debian 13.2.0-24) 13.2.0 Clang version: 14.0.6-2 CMake version: version 3.28.3 Libc version: glibc-2.38

Python version: 3.12.5 (main, Aug 18 2024, 01:30:37) [GCC 13.2.0] (64-bit runtime) Python platform: Linux-6.6.15-amd64-x86_64-with-glibc2.38 Is CUDA available: True CUDA runtime version: Could not collect CUDA_MODULE_LOADING set to: LAZY GPU models and configuration: GPU 0: NVIDIA GeForce GTX 1660 SUPER GPU 1: NVIDIA GeForce GTX 1660 SUPER

Nvidia driver version: 555.42.02 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: 39 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 8 On-line CPU(s) list: 0-7 Vendor ID: GenuineIntel Model name: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz CPU family: 6 Model: 60 Thread(s) per core: 2 Core(s) per socket: 4 Socket(s): 1 Stepping: 3 CPU(s) scaling MHz: 65% CPU max MHz: 4000.0000 CPU min MHz: 800.0000 BogoMIPS: 7198.06 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 arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault pti ssbd ibrs ibpb stibp tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts vnmi md_clear flush_l1d Virtualization: VT-x L1d cache: 128 KiB (4 instances) L1i cache: 128 KiB (4 instances) L2 cache: 1 MiB (4 instances) L3 cache: 8 MiB (1 instance) NUMA node(s): 1 NUMA node0 CPU(s): 0-7 Vulnerability Gather data sampling: Not affected Vulnerability Itlb multihit: KVM: Mitigation: VMX disabled Vulnerability L1tf: Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable Vulnerability Mds: Mitigation; Clear CPU buffers; SMT vulnerable Vulnerability Meltdown: Mitigation; PTI Vulnerability Mmio stale data: Unknown: No mitigations Vulnerability Retbleed: Not affected Vulnerability Spec rstack overflow: Not affected Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Retpolines, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling, PBRSB-eIBRS Not affected Vulnerability Srbds: Mitigation; Microcode Vulnerability Tsx async abort: Not affected

Versions of relevant libraries: [pip3] numpy==1.26.4 [pip3] torch==2.4.0 [pip3] torchvision==0.19.0 [pip3] triton==3.0.0 [conda] Could not collect`

Thanks in advance for any suggestions on what the issue might be.

Versions

No response

anti79 commented 2 weeks ago

More output from training:

===========================================================
Train epoch 1: 100%|██████████| 111/111 [02:23<00:00,  1.29s/it, PPYoloELoss/loss=nan, PPYoloELoss/loss_cls=nan, PPYoloELoss/loss_dfl=nan, PPYoloELoss/loss_iou=nan, gpu_mem=2.76]
Validating epoch 1: 100%|██████████| 32/32 [00:04<00:00,  7.99it/s]
===========================================================
SUMMARY OF EPOCH 1
├── Train
│   ├── Ppyoloeloss/loss_cls = nan
│   │   ├── Epoch N-1      = nan    (= nan)
│   │   └── Best until now = nan    (= nan)
│   ├── Ppyoloeloss/loss_iou = nan
│   │   ├── Epoch N-1      = nan    (= nan)
│   │   └── Best until now = nan    (= nan)
│   ├── Ppyoloeloss/loss_dfl = nan
│   │   ├── Epoch N-1      = nan    (= nan)
│   │   └── Best until now = nan    (= nan)
│   └── Ppyoloeloss/loss = nan
│       ├── Epoch N-1      = nan    (= nan)
│       └── Best until now = nan    (= nan)
└── Validation
    ├── Ppyoloeloss/loss_cls = nan
    │   ├── Epoch N-1      = nan    (= nan)
    │   └── Best until now = nan    (= nan)
    ├── Ppyoloeloss/loss_iou = nan
    │   ├── Epoch N-1      = nan    (= nan)
    │   └── Best until now = nan    (= nan)
    ├── Ppyoloeloss/loss_dfl = nan
    │   ├── Epoch N-1      = nan    (= nan)
    │   └── Best until now = nan    (= nan)
...
        ├── Epoch N-1      = 0.0    (= 0.0)
        └── Best until now = 0.0    (= 0.0)