Skip to content

FSDP checkpoint load RuntimeError appeared between jan11 and feb8 #94409

@qasfb

Description

@qasfb

🐛 Describe the bug

import warnings
warnings.filterwarnings("ignore")
import pdb
import torch
from torch import nn
import torch.distributed as dist
torch.use_deterministic_algorithms(True, warn_only=True)
torch.manual_seed(0)
dist.init_process_group(backend="nccl")
dist.barrier()
global_rank = dist.get_rank()
torch.cuda.set_device(global_rank)
print(global_rank)
#
#
#
# setting up FSDP
from torch.distributed.fsdp import FullyShardedDataParallel as FSDP
from torch.distributed.fsdp import ShardingStrategy
from torch.distributed.fsdp import StateDictType
from torch.distributed.fsdp import MixedPrecision
from torch.distributed.fsdp.wrap import ModuleWrapPolicy
mixed_precision_config = MixedPrecision(
    param_dtype=torch.float16,
    reduce_dtype=torch.float32,
    buffer_dtype=torch.float32,
)
sharding_strategy_config = ShardingStrategy.SHARD_GRAD_OP
model1 = nn.Linear(24, 24)
model2 = nn.Linear(24, 24)
sharded_model = FSDP(
    model1, 
    sharding_strategy=sharding_strategy_config,
    mixed_precision=mixed_precision_config,
    device_id=global_rank, 
    use_orig_params=True,
    # auto_wrap_policy=ModuleWrapPolicy({Block}),
)
x_half = torch.randn(32,24).cuda().half()
x_half.requires_grad_()
sharded_model(x_half).sum().backward()

with FSDP.state_dict_type(sharded_model, StateDictType.LOCAL_STATE_DICT):
    sd = sharded_model.state_dict()
    if global_rank==0:
        print(sd.keys())
    torch.save(sd, f"/tmp/tmp_rank{global_rank}.pth")

torch.distributed.barrier()
t = torch.load(f"/tmp/tmp_rank{global_rank}.pth", map_location="cpu")

Run the script with:

torchrun --standalone --nnodes=1 --nproc_per_node=2 bug_repro.py

The bug occurs with pytorch '2.0.0.dev20230129'

and it says:

Traceback (most recent call last):
  File "bug_repro.py", line 51, in <module>
    t = torch.load(f"/tmp/tmp_rank{global_rank}.pth", map_location="cpu")
  File "condaenv/lib/python3.9/site-packages/torch/serialization.py", line 811, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
  File "condaenv/lib/python3.9/site-packages/torch/serialization.py", line 1174, in _load
    result = unpickler.load()
  File "condaenv/lib/python3.9/site-packages/torch/_utils.py", line 169, in _rebuild_tensor_v2
    tensor = _rebuild_tensor(storage, storage_offset, size, stride)
  File "condaenv/lib/python3.9/site-packages/torch/_utils.py", line 148, in _rebuild_tensor
    return t.set_(storage._untyped_storage, storage_offset, size, stride)
RuntimeError: Trying to resize storage that is not resizable

The bug does not occur with pytorch '2.0.0.dev20230111'

Versions

$ python collect_env.py
Collecting environment information...
PyTorch version: 2.0.0.dev20230129
Is debug build: False
CUDA used to build PyTorch: 11.7
ROCM used to build PyTorch: N/A

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

Python version: 3.9.16 (main, Jan 11 2023, 16:05:54) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.4.0-124-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: Quadro GP100
GPU 1: Quadro GP100

Nvidia driver version: 470.141.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
Byte Order: Little Endian
Address sizes: 46 bits physical, 48 bits virtual
CPU(s): 80
On-line CPU(s) list: 0-79
Thread(s) per core: 2
Core(s) per socket: 20
Socket(s): 2
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 79
Model name: Intel(R) Xeon(R) CPU E5-2698 v4 @ 2.20GHz
Stepping: 1
CPU MHz: 2853.388
CPU max MHz: 3600.0000
CPU min MHz: 1200.0000
BogoMIPS: 4399.96
Virtualization: VT-x
L1d cache: 1.3 MiB
L1i cache: 1.3 MiB
L2 cache: 10 MiB
L3 cache: 100 MiB
NUMA node0 CPU(s): 0-19,40-59
NUMA node1 CPU(s): 20-39,60-79
Vulnerability Itlb multihit: KVM: Mitigation: Split huge pages
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: Mitigation; Clear CPU buffers; SMT vulnerable
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; Retpolines, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Mitigation; Clear CPU buffers; SMT vulnerable
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 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 pti intel_ppin ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap intel_pt xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts md_clear flush_l1d

Versions of relevant libraries:
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.22.4
[pip3] torch==2.0.0.dev20230129
[pip3] torchmetrics==0.10.3
[pip3] torchvision==0.15.0.dev20230129
[conda] blas 1.0 mkl
[conda] mkl 2021.4.0 h06a4308_640
[conda] mkl-service 2.4.0 py39h7f8727e_0
[conda] mkl_fft 1.3.1 py39hd3c417c_0
[conda] mkl_random 1.2.2 py39h51133e4_0
[conda] numpy 1.22.4 pypi_0 pypi
[conda] pytorch 2.0.0.dev20230129 py3.9_cuda11.7_cudnn8.5.0_0 pytorch-nightly
[conda] pytorch-cuda 11.7 h67b0de4_2 pytorch-nightly
[conda] pytorch-mutex 1.0 cuda pytorch-nightly
[conda] torchmetrics 0.10.3 pyhd8ed1ab_0 conda-forge
[conda] torchtriton 2.0.0+0d7e753227 py39 pytorch-nightly
[conda] torchvision 0.15.0.dev20230129 py39_cu117 pytorch-nightly

cc @mrshenli @pritamdamania87 @zhaojuanmao @satgera @rohan-varma @gqchen @aazzolini @osalpekar @jiayisuse @H-Huang @kwen2501 @awgu

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: fsdponcall: distributedAdd this issue/PR to distributed oncall triage queuetriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions