pytorch - ✅(Solved) Fix Resnet50 training regressed on pytorch 2.10 and later on 8 x AMD MI300X GPU (About 30-40%). [1 pull requests, 12 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#180500Fetched 2026-04-17 08:22:00
View on GitHub
Comments
12
Participants
2
Timeline
115
Reactions
0
Timeline (top)
mentioned ×42subscribed ×42unsubscribed ×13commented ×12

Root Cause

Resnet50 training regressed on pytorch 2.10 and later on 8 x AMD MI300X GPU (About 30-40%). I was able to root cause the regression to https://github.com/pytorch/pytorch/pull/167564. Other observations:

  • Regression mostly in backward pass
  • Was not able to see the regression with 8 x H100 GPUs
  • No regression b/w 2.9 & 2.10 with num_workers=1 in dataloader (But reduction in perf compared to num_workers=4)

Fix Action

Fix / Workaround

CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 52 bits physical, 57 bits virtual Byte Order: Little Endian CPU(s): 384 On-line CPU(s) list: 0-383 Vendor ID: AuthenticAMD Model name: AMD EPYC 9654 96-Core Processor CPU family: 25 Model: 17 Thread(s) per core: 2 Core(s) per socket: 96 Socket(s): 2 Stepping: 1 Frequency boost: enabled CPU(s) scaling MHz: 46% CPU max MHz: 3707.8120 CPU min MHz: 1500.0000 BogoMIPS: 4793.01 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 amd_lbr_v2 nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic 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 invpcid_single hw_pstate ssbd mba perfmon_v2 ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif x2avic v_spec_ctrl avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid overflow_recov succor smca fsrm flush_l1d Virtualization: AMD-V L1d cache: 6 MiB (192 instances) L1i cache: 6 MiB (192 instances) L2 cache: 192 MiB (192 instances) L3 cache: 768 MiB (24 instances) NUMA node(s): 2 NUMA node0 CPU(s): 0-95,192-287 NUMA node1 CPU(s): 96-191,288-383 Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Not affected Vulnerability Retbleed: 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 always-on, RSB filling, PBRSB-eIBRS Not affected Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected

CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 52 bits physical, 57 bits virtual Byte Order: Little Endian CPU(s): 384 On-line CPU(s) list: 0-383 Vendor ID: AuthenticAMD Model name: AMD EPYC 9654 96-Core Processor CPU family: 25 Model: 17 Thread(s) per core: 2 Core(s) per socket: 96 Socket(s): 2 Stepping: 1 Frequency boost: enabled CPU(s) scaling MHz: 49% CPU max MHz: 3707.8120 CPU min MHz: 1500.0000 BogoMIPS: 4793.01 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 amd_lbr_v2 nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic 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 invpcid_single hw_pstate ssbd mba perfmon_v2 ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif x2avic v_spec_ctrl avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid overflow_recov succor smca fsrm flush_l1d Virtualization: AMD-V L1d cache: 6 MiB (192 instances) L1i cache: 6 MiB (192 instances) L2 cache: 192 MiB (192 instances) L3 cache: 768 MiB (24 instances) NUMA node(s): 2 NUMA node0 CPU(s): 0-95,192-287 NUMA node1 CPU(s): 96-191,288-383 Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Not affected Vulnerability Retbleed: 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 always-on, RSB filling, PBRSB-eIBRS Not affected Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected

PR fix notes

PR #180573: Avoid unnecessary refcount bump in inplace op Python bindings

Description (problem / solution / changelog)

For inplace method ops returning Tensor(a!), the Python binding lambda previously returned at::Tensor by value from the Tensor& C++ return. This copy bumps the intrusive_ptr refcount from 1 to 2, triggering incref_pyobject which acquires the GIL - a significant source of contention in multi-threaded DDP workloads on free-threaded Python.

Change the codegen to make the lambda return void and return self_ (the Python object) directly, avoiding the Tensor copy entirely.

See #180500

Authored with Claude.

Changed files

  • aten/src/ATen/native/miopen/BatchNorm_miopen.cpp (modified, +2/-2)
  • aten/src/ATen/native/miopen/Conv_miopen.cpp (modified, +42/-45)
  • tools/autograd/gen_python_functions.py (modified, +28/-1)
  • torch/csrc/StorageSharing.cpp (modified, +17/-14)

Code Example

2.9  
--------------------------
(worker=1)
Epoch 0: time: 38781.05
Epoch 1: time: 29419.08
Epoch 2: time: 29534.13
--------------------------
(worker=4)
Epoch 0: time: 20061.06
Epoch 1: time: 12552.80
Epoch 2: time: 11260.89
================

2.10
---------------------------
(worker=1)
Epoch 0: time: 37727.24
Epoch 1: time: 30252.50
Epoch 2: time: 29508.82
---------------------------
(worker=4)
Epoch 0: time: 25480.75
Epoch 1: time: 16017.86
Epoch 2: time: 17256.26

---

import os
import time
import torch
import torch.nn as nn
import torch.optim as optim
import torch.distributed as dist
from torch.nn.parallel import DistributedDataParallel as DDP
from torch.utils.data import DataLoader, DistributedSampler
from torchvision import datasets, transforms, models

def setup(rank, world_size):
    os.environ['MASTER_ADDR'] = '127.0.0.1' #localhost'
    os.environ['MASTER_PORT'] = '49153' #'12355'
    os.environ['RANK'] = str(rank)
    os.environ['LOCAL_RANK'] = str(rank)
    os.environ['WORLD_SIZE'] = str(world_size)
    dist.init_process_group("nccl", init_method="env://", rank=rank, world_size=world_size)
    print(f"Rank {dist.get_rank()} setup")

def cleanup():
    if dist.is_initialized():
        dist.destroy_process_group()

def train(rank, world_size):
    torch.cuda.set_device(rank)
    setup(rank, world_size)
    #torch.cuda.set_device(rank)

    # 1. Load ResNet50
    # Weights=None for training from scratch, or ResNet50_Weights.DEFAULT for fine-tuning
    model = models.resnet50(weights=None) #.to(rank)
    model.cuda(rank)
    model = DDP(model, device_ids=[rank])

    # 3. Loss, Optimizer, and Scaler (for Mixed Precision)
    criterion = nn.CrossEntropyLoss().to(rank)
    optimizer = optim.SGD(model.parameters(), lr=0.1 * (world_size * 64 / 256), momentum=0.9, weight_decay=1e-4)
    scheduler = optim.lr_scheduler.StepLR(optimizer, step_size=30, gamma=0.1)

    # 2. Data Pipeline
    transform = transforms.Compose([
        transforms.RandomResizedCrop(224),
        transforms.RandomHorizontalFlip(),
        transforms.ToTensor(),
        transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
    ])

    # FakeData used here; replace with datasets.ImageFolder for your own data
    dataset = datasets.FakeData(size=80000, image_size=(3, 224, 224), num_classes=1000, transform=transform)
    sampler = DistributedSampler(dataset, num_replicas=world_size, rank=rank, shuffle=True)
    train_loader = DataLoader(dataset, batch_size=32, sampler=sampler, num_workers=4, pin_memory=True)

    if rank == 0:
        print(f"Len: {len(train_loader)}")
        print("Start traing")
    # 4. Training Loop
    model.train()
    dist.barrier()
    for epoch in range(3):
        sampler.set_epoch(epoch)

        start = time.perf_counter_ns()
        for i, (images, target) in enumerate(train_loader):
            images, target = images.to(rank, non_blocking=True), target.to(rank, non_blocking=True)

            output = model(images)
            loss = criterion(output, target)

            # Backward pass with Scaler
            optimizer.zero_grad()
            loss.backward()
            optimizer.step()
        torch.cuda.synchronize()
        dist.barrier()
        if rank == 0:
            print(f"Epoch {epoch}: time: {(time.perf_counter_ns() - start)/1000000:.2f}")
        dist.barrier()
        scheduler.step()

    torch.cuda.synchronize()
    dist.barrier()
    cleanup()

if __name__ == "__main__":
    world_size = torch.cuda.device_count()
    import torch.multiprocessing as mp
    mp.spawn(train, args=(world_size,), nprocs=world_size, join=True)

---

PyTorch version: 2.9.1+rocm7.13.0a20260401
Is debug build: False
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: 7.13.60800-96e30b429c

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

Python version: 3.12.3 (main, Mar  3 2026, 12:15:18) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-6.2.0-25-generic-x86_64-with-glibc2.39
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to:
GPU models and configuration: AMD Instinct MI300X (gfx942:sramecc+:xnack-)
Nvidia driver version: Could not collect
cuDNN version: Could not collect
Is XPU available: False
HIP runtime version: 7.13.60800
MIOpen runtime version: 3.5.1
Is XNNPACK available: True
Caching allocator config: N/A

CPU:
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Address sizes:                   52 bits physical, 57 bits virtual
Byte Order:                      Little Endian
CPU(s):                          384
On-line CPU(s) list:             0-383
Vendor ID:                       AuthenticAMD
Model name:                      AMD EPYC 9654 96-Core Processor
CPU family:                      25
Model:                           17
Thread(s) per core:              2
Core(s) per socket:              96
Socket(s):                       2
Stepping:                        1
Frequency boost:                 enabled
CPU(s) scaling MHz:              46%
CPU max MHz:                     3707.8120
CPU min MHz:                     1500.0000
BogoMIPS:                        4793.01
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 amd_lbr_v2 nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic 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 invpcid_single hw_pstate ssbd mba perfmon_v2 ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif x2avic v_spec_ctrl avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid overflow_recov succor smca fsrm flush_l1d
Virtualization:                  AMD-V
L1d cache:                       6 MiB (192 instances)
L1i cache:                       6 MiB (192 instances)
L2 cache:                        192 MiB (192 instances)
L3 cache:                        768 MiB (24 instances)
NUMA node(s):                    2
NUMA node0 CPU(s):               0-95,192-287
NUMA node1 CPU(s):               96-191,288-383
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Mmio stale data:   Not affected
Vulnerability Retbleed:          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 always-on, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected

Versions of relevant libraries:
[pip3] mypy==1.16.0
[pip3] mypy_extensions==1.1.0
[pip3] numpy==2.1.2
[pip3] onnx==1.19.1
[pip3] onnx-ir==0.1.15
[pip3] onnxscript==0.5.4
[pip3] optree==0.13.0
[pip3] torch==2.9.1+rocm7.13.0a20260401
[pip3] torchaudio==2.9.0+rocm7.13.0a20260401
[pip3] torchvision==0.24.0+rocm7.13.0a20260401
[pip3] triton==3.5.1+rocm7.13.0a20260401
[conda] Could not collect

---

PyTorch version: 2.10.0+rocm7.13.0a20260401
Is debug build: False
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: 7.13.60800

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

Python version: 3.12.3 (main, Mar  3 2026, 12:15:18) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-6.2.0-25-generic-x86_64-with-glibc2.39
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to:
GPU models and configuration: AMD Instinct MI300X (gfx942:sramecc+:xnack-)
Nvidia driver version: Could not collect
cuDNN version: Could not collect
Is XPU available: False
HIP runtime version: 7.13.60800
MIOpen runtime version: 3.5.1
Is XNNPACK available: True
Caching allocator config: N/A

CPU:
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Address sizes:                   52 bits physical, 57 bits virtual
Byte Order:                      Little Endian
CPU(s):                          384
On-line CPU(s) list:             0-383
Vendor ID:                       AuthenticAMD
Model name:                      AMD EPYC 9654 96-Core Processor
CPU family:                      25
Model:                           17
Thread(s) per core:              2
Core(s) per socket:              96
Socket(s):                       2
Stepping:                        1
Frequency boost:                 enabled
CPU(s) scaling MHz:              49%
CPU max MHz:                     3707.8120
CPU min MHz:                     1500.0000
BogoMIPS:                        4793.01
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 amd_lbr_v2 nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic 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 invpcid_single hw_pstate ssbd mba perfmon_v2 ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif x2avic v_spec_ctrl avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid overflow_recov succor smca fsrm flush_l1d
Virtualization:                  AMD-V
L1d cache:                       6 MiB (192 instances)
L1i cache:                       6 MiB (192 instances)
L2 cache:                        192 MiB (192 instances)
L3 cache:                        768 MiB (24 instances)
NUMA node(s):                    2
NUMA node0 CPU(s):               0-95,192-287
NUMA node1 CPU(s):               96-191,288-383
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Mmio stale data:   Not affected
Vulnerability Retbleed:          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 always-on, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected

Versions of relevant libraries:
[pip3] mypy==1.16.0
[pip3] mypy_extensions==1.1.0
[pip3] numpy==2.1.2
[pip3] onnx==1.19.1
[pip3] onnx-ir==0.1.12
[pip3] onnxscript==0.5.4
[pip3] optree==0.13.0
[pip3] torch==2.10.0+rocm7.13.0a20260401
[pip3] torchaudio==2.10.0+rocm7.13.0a20260401
[pip3] torchvision==0.25.0+rocm7.13.0a20260401
[pip3] triton==3.6.0+rocm7.13.0a20260401
[conda] Could not collect
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

Resnet50 training regressed on pytorch 2.10 and later on 8 x AMD MI300X GPU (About 30-40%). I was able to root cause the regression to https://github.com/pytorch/pytorch/pull/167564. Other observations:

  • Regression mostly in backward pass
  • Was not able to see the regression with 8 x H100 GPUs
  • No regression b/w 2.9 & 2.10 with num_workers=1 in dataloader (But reduction in perf compared to num_workers=4)

Output

2.9  
--------------------------
(worker=1)
Epoch 0: time: 38781.05
Epoch 1: time: 29419.08
Epoch 2: time: 29534.13
--------------------------
(worker=4)
Epoch 0: time: 20061.06
Epoch 1: time: 12552.80
Epoch 2: time: 11260.89
================

2.10
---------------------------
(worker=1)
Epoch 0: time: 37727.24
Epoch 1: time: 30252.50
Epoch 2: time: 29508.82
---------------------------
(worker=4)
Epoch 0: time: 25480.75
Epoch 1: time: 16017.86
Epoch 2: time: 17256.26

Reproducer:

import os
import time
import torch
import torch.nn as nn
import torch.optim as optim
import torch.distributed as dist
from torch.nn.parallel import DistributedDataParallel as DDP
from torch.utils.data import DataLoader, DistributedSampler
from torchvision import datasets, transforms, models

def setup(rank, world_size):
    os.environ['MASTER_ADDR'] = '127.0.0.1' #localhost'
    os.environ['MASTER_PORT'] = '49153' #'12355'
    os.environ['RANK'] = str(rank)
    os.environ['LOCAL_RANK'] = str(rank)
    os.environ['WORLD_SIZE'] = str(world_size)
    dist.init_process_group("nccl", init_method="env://", rank=rank, world_size=world_size)
    print(f"Rank {dist.get_rank()} setup")

def cleanup():
    if dist.is_initialized():
        dist.destroy_process_group()

def train(rank, world_size):
    torch.cuda.set_device(rank)
    setup(rank, world_size)
    #torch.cuda.set_device(rank)

    # 1. Load ResNet50
    # Weights=None for training from scratch, or ResNet50_Weights.DEFAULT for fine-tuning
    model = models.resnet50(weights=None) #.to(rank)
    model.cuda(rank)
    model = DDP(model, device_ids=[rank])

    # 3. Loss, Optimizer, and Scaler (for Mixed Precision)
    criterion = nn.CrossEntropyLoss().to(rank)
    optimizer = optim.SGD(model.parameters(), lr=0.1 * (world_size * 64 / 256), momentum=0.9, weight_decay=1e-4)
    scheduler = optim.lr_scheduler.StepLR(optimizer, step_size=30, gamma=0.1)

    # 2. Data Pipeline
    transform = transforms.Compose([
        transforms.RandomResizedCrop(224),
        transforms.RandomHorizontalFlip(),
        transforms.ToTensor(),
        transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
    ])

    # FakeData used here; replace with datasets.ImageFolder for your own data
    dataset = datasets.FakeData(size=80000, image_size=(3, 224, 224), num_classes=1000, transform=transform)
    sampler = DistributedSampler(dataset, num_replicas=world_size, rank=rank, shuffle=True)
    train_loader = DataLoader(dataset, batch_size=32, sampler=sampler, num_workers=4, pin_memory=True)

    if rank == 0:
        print(f"Len: {len(train_loader)}")
        print("Start traing")
    # 4. Training Loop
    model.train()
    dist.barrier()
    for epoch in range(3):
        sampler.set_epoch(epoch)

        start = time.perf_counter_ns()
        for i, (images, target) in enumerate(train_loader):
            images, target = images.to(rank, non_blocking=True), target.to(rank, non_blocking=True)

            output = model(images)
            loss = criterion(output, target)

            # Backward pass with Scaler
            optimizer.zero_grad()
            loss.backward()
            optimizer.step()
        torch.cuda.synchronize()
        dist.barrier()
        if rank == 0:
            print(f"Epoch {epoch}: time: {(time.perf_counter_ns() - start)/1000000:.2f}")
        dist.barrier()
        scheduler.step()

    torch.cuda.synchronize()
    dist.barrier()
    cleanup()

if __name__ == "__main__":
    world_size = torch.cuda.device_count()
    import torch.multiprocessing as mp
    mp.spawn(train, args=(world_size,), nprocs=world_size, join=True)

Versions

2.9

PyTorch version: 2.9.1+rocm7.13.0a20260401
Is debug build: False
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: 7.13.60800-96e30b429c

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

Python version: 3.12.3 (main, Mar  3 2026, 12:15:18) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-6.2.0-25-generic-x86_64-with-glibc2.39
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to:
GPU models and configuration: AMD Instinct MI300X (gfx942:sramecc+:xnack-)
Nvidia driver version: Could not collect
cuDNN version: Could not collect
Is XPU available: False
HIP runtime version: 7.13.60800
MIOpen runtime version: 3.5.1
Is XNNPACK available: True
Caching allocator config: N/A

CPU:
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Address sizes:                   52 bits physical, 57 bits virtual
Byte Order:                      Little Endian
CPU(s):                          384
On-line CPU(s) list:             0-383
Vendor ID:                       AuthenticAMD
Model name:                      AMD EPYC 9654 96-Core Processor
CPU family:                      25
Model:                           17
Thread(s) per core:              2
Core(s) per socket:              96
Socket(s):                       2
Stepping:                        1
Frequency boost:                 enabled
CPU(s) scaling MHz:              46%
CPU max MHz:                     3707.8120
CPU min MHz:                     1500.0000
BogoMIPS:                        4793.01
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 amd_lbr_v2 nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic 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 invpcid_single hw_pstate ssbd mba perfmon_v2 ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif x2avic v_spec_ctrl avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid overflow_recov succor smca fsrm flush_l1d
Virtualization:                  AMD-V
L1d cache:                       6 MiB (192 instances)
L1i cache:                       6 MiB (192 instances)
L2 cache:                        192 MiB (192 instances)
L3 cache:                        768 MiB (24 instances)
NUMA node(s):                    2
NUMA node0 CPU(s):               0-95,192-287
NUMA node1 CPU(s):               96-191,288-383
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Mmio stale data:   Not affected
Vulnerability Retbleed:          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 always-on, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected

Versions of relevant libraries:
[pip3] mypy==1.16.0
[pip3] mypy_extensions==1.1.0
[pip3] numpy==2.1.2
[pip3] onnx==1.19.1
[pip3] onnx-ir==0.1.15
[pip3] onnxscript==0.5.4
[pip3] optree==0.13.0
[pip3] torch==2.9.1+rocm7.13.0a20260401
[pip3] torchaudio==2.9.0+rocm7.13.0a20260401
[pip3] torchvision==0.24.0+rocm7.13.0a20260401
[pip3] triton==3.5.1+rocm7.13.0a20260401
[conda] Could not collect

2.10

PyTorch version: 2.10.0+rocm7.13.0a20260401
Is debug build: False
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: 7.13.60800

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

Python version: 3.12.3 (main, Mar  3 2026, 12:15:18) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-6.2.0-25-generic-x86_64-with-glibc2.39
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to:
GPU models and configuration: AMD Instinct MI300X (gfx942:sramecc+:xnack-)
Nvidia driver version: Could not collect
cuDNN version: Could not collect
Is XPU available: False
HIP runtime version: 7.13.60800
MIOpen runtime version: 3.5.1
Is XNNPACK available: True
Caching allocator config: N/A

CPU:
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Address sizes:                   52 bits physical, 57 bits virtual
Byte Order:                      Little Endian
CPU(s):                          384
On-line CPU(s) list:             0-383
Vendor ID:                       AuthenticAMD
Model name:                      AMD EPYC 9654 96-Core Processor
CPU family:                      25
Model:                           17
Thread(s) per core:              2
Core(s) per socket:              96
Socket(s):                       2
Stepping:                        1
Frequency boost:                 enabled
CPU(s) scaling MHz:              49%
CPU max MHz:                     3707.8120
CPU min MHz:                     1500.0000
BogoMIPS:                        4793.01
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 amd_lbr_v2 nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic 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 invpcid_single hw_pstate ssbd mba perfmon_v2 ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif x2avic v_spec_ctrl avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid overflow_recov succor smca fsrm flush_l1d
Virtualization:                  AMD-V
L1d cache:                       6 MiB (192 instances)
L1i cache:                       6 MiB (192 instances)
L2 cache:                        192 MiB (192 instances)
L3 cache:                        768 MiB (24 instances)
NUMA node(s):                    2
NUMA node0 CPU(s):               0-95,192-287
NUMA node1 CPU(s):               96-191,288-383
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Mmio stale data:   Not affected
Vulnerability Retbleed:          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 always-on, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected

Versions of relevant libraries:
[pip3] mypy==1.16.0
[pip3] mypy_extensions==1.1.0
[pip3] numpy==2.1.2
[pip3] onnx==1.19.1
[pip3] onnx-ir==0.1.12
[pip3] onnxscript==0.5.4
[pip3] optree==0.13.0
[pip3] torch==2.10.0+rocm7.13.0a20260401
[pip3] torchaudio==2.10.0+rocm7.13.0a20260401
[pip3] torchvision==0.25.0+rocm7.13.0a20260401
[pip3] triton==3.6.0+rocm7.13.0a20260401
[conda] Could not collect

cc @awgu @wanchaol @fegin @fduwjj @wz337 @wconstab @d4l3k @pragupta @msaroufim @dcci @aditvenk @xmfan @weifengpy @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @xinyazhang

extent analysis

TL;DR

The most likely fix for the ResNet50 training regression on PyTorch 2.10 with AMD MI300X GPUs is to revert the changes introduced in the PyTorch pull request #167564 or to apply a workaround by setting num_workers=1 in the dataloader.

Guidance

  • The regression is mostly in the backward pass, suggesting an issue with the computation or memory access patterns.
  • The fact that the regression is not seen with num_workers=1 in the dataloader or with 8 x H100 GPUs implies that the issue might be related to parallelism or GPU-specific optimizations.
  • To mitigate the issue, try setting num_workers=1 in the dataloader or experiment with different parallelism settings.
  • Verify the fix by comparing the training times and performance metrics between the original and modified configurations.

Example

No specific code changes are suggested at this point, but modifying the DataLoader initialization to use num_workers=1 might look like this:

train_loader = DataLoader(dataset, batch_size=32, sampler=sampler, num_workers=1, pin_memory=True)

Notes

The root cause of the regression is not fully understood and may require further investigation or debugging. The suggested workaround may not completely resolve the issue but can help mitigate its effects.

Recommendation

Apply the workaround by setting num_workers=1 in the dataloader, as this is a relatively simple change that can help alleviate the regression without requiring a full understanding of the underlying cause.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

pytorch - ✅(Solved) Fix Resnet50 training regressed on pytorch 2.10 and later on 8 x AMD MI300X GPU (About 30-40%). [1 pull requests, 12 comments, 2 participants]