Open TuyetHan opened 6 months ago
It looks like you are seeing out-of-memory (OOM) because your activation size is too large, which is not directly related to FSDP:
File "/project/p_trancal/trsclbjob/lib/python3.10/site-packages/torch/nn/modules/activation.py", line 1126, in forward
attn_mask = F._canonical_mask(
File "/project/p_trancal/trsclbjob/lib/python3.10/site-packages/torch/nn/functional.py", line 5115, in _canonical_mask
torch.zeros_like(mask, dtype=target_type)
torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 29.07 GiB. GPU 3 has a total capacity of 39.43 GiB of which 25.15 GiB is free. Including non-PyTorch memory, this process has 14.27 GiB memory in use. Of the allocated memory 11.74 GiB is allocated by PyTorch, and 932.02 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables)
You may want to check your input activation sizes since you are trying to allocate a 29.07 GiB attn_mask
.
🐛 Describe the bug
I want to train a model on HPC using SLURM and accelerate to config FSDP. However, no matter how I change the configuration, It seems not to have much effect on CUDA memory usage (It doesn't save CUDA memory).
I've tried changing ShardingStrategy, number of Nodes/GPU/Process, MixedPrecision, Wrap policy, enabling/disabling CPUOffload, CPURam Efficiency Loading, .... but so far still fail on the same line of code and requires the same memory 29.07G. The batch size is already 1 and when I reduce input size, it returns Segmentation Fault (don't know why).
Below is errors:
This is my SLURM config:
This is my main function:
And result of print Plugin: Check plugin: FullyShardedDataParallelPlugin(sharding_strategy=<ShardingStrategy.FULL_SHARD: 1>, backward_prefetch=None, mixed_precision_policy=MixedPrecision(param_dtype=None, reduce_dtype=torch.float16, buffer_dtype=None, keep_low_precision_grads=False, cast_forward_inputs=False, cast_root_forward_inputs=True, _module_classes_to_ignore=(<class 'torch.nn.modules.batchnorm._BatchNorm'>,)), auto_wrap_policy=functools.partial(<function size_based_auto_wrap_policy at 0x7ff04fdf7d90>, min_num_params=20000), cpu_offload=CPUOffload(offload_params=True), ignored_modules=None, state_dict_type=<StateDictType.FULL_STATE_DICT: 1>, state_dict_config=FullStateDictConfig(offload_to_cpu=True, rank0_only=True), optim_state_dict_config=FullOptimStateDictConfig(offload_to_cpu=True, rank0_only=True), limit_all_gathers=True, use_orig_params=True, param_init_fn=<function FullyShardedDataParallelPlugin.__post_init__.. at 0x7fefffba2200>, sync_module_states=True, forward_prefetch=False, activation_checkpointing=False)
Versions
Collecting environment information... PyTorch version: 2.2.1+cu121 Is debug build: False CUDA used to build PyTorch: 12.1 ROCM used to build PyTorch: N/A
OS: Red Hat Enterprise Linux release 8.6 (Ootpa) (x86_64) GCC version: (GCC) 8.5.0 20210514 (Red Hat 8.5.0-18) Clang version: Could not collect CMake version: version 3.20.2 Libc version: glibc-2.28
Python version: 3.12.1 | packaged by Anaconda, Inc. | (main, Jan 19 2024, 15:51:05) [GCC 11.2.0] (64-bit runtime) Python platform: Linux-4.18.0-372.9.1.el8.x86_64-x86_64-with-glibc2.28 Is CUDA available: True CUDA runtime version: Could not collect CUDA_MODULE_LOADING set to: LAZY GPU models and configuration: GPU 0: Quadro RTX 6000 Nvidia driver version: 530.30.02 cuDNN version: Probably one of the following: /scratch/software/packages/cuda/12.1/targets/x86_64-linux/lib/libcudnn.so.8.9.5 /scratch/software/packages/cuda/12.1/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8.9.5 /scratch/software/packages/cuda/12.1/targets/x86_64-linux/lib/libcudnn_adv_train.so.8.9.5 /scratch/software/packages/cuda/12.1/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8.9.5 /scratch/software/packages/cuda/12.1/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8.9.5 /scratch/software/packages/cuda/12.1/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8.9.5 /scratch/software/packages/cuda/12.1/targets/x86_64-linux/lib/libcudnn_ops_train.so.8.9.5 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 CPU(s): 96 On-line CPU(s) list: 0-95 Thread(s) per core: 2 Core(s) per socket: 24 Socket(s): 2 NUMA node(s): 2 Vendor ID: AuthenticAMD CPU family: 23 Model: 49 Model name: AMD EPYC 7352 24-Core Processor Stepping: 0 CPU MHz: 2300.000 CPU max MHz: 2300.0000 CPU min MHz: 1500.0000 BogoMIPS: 4591.32 Virtualization: AMD-V L1d cache: 32K L1i cache: 32K L2 cache: 512K L3 cache: 16384K NUMA node0 CPU(s): 0-23,48-71 NUMA node1 CPU(s): 24-47,72-95 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 nonstop_tsc cpuid extd_apicid aperfmperf 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 ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr wbnoinvd amd_ppin 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
Versions of relevant libraries: [pip3] numpy==1.26.4 [pip3] torch==2.2.1 [conda] numpy 1.26.4 pypi_0 pypi [conda] torch 2.2.1 pypi_0 pypi
cc @mrshenli @pritamdamania87 @zhaojuanmao @satgera @rohan-varma @gqchen @aazzolini @osalpekar @jiayisuse @H-Huang @kwen2501 @awgu @penguinwu @fegin @XilunWu @wanchaol @fduwjj @wz337 @tianyu-l @wconstab @yf225 @chauhang