You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am testing out DeepSpeed on a single GTX 1070 GPU. Everything works fine until I try to enable "cpu_offload" in the config, which then doubles GPU memory usage from 4GB to 8GB. CPU memory usage increases significantly as expected, so it seems that the data is being copied successfully. If I also enable "overlap_comm," as recommended here, my system runs out of memory.
I am on Linux Mint 19 using PyTorch 1.7, CUDA 10.2, and latest version of DeepSpeed. Let me know if you need any more information. Thank you for your time.
@anti4m Thanks for using DeepSpeed. This is an interesting observation and I have a few questions.
What is the model and number of parameters?
What is the size of GPU RAM?
Enabling cpu_offload is expected to reduce GPU RAM usage, so it is strange that toggling on/off doubles RAM usage. Are you using nvidia-smi to measure GPU RAM usage?
Yes, overlap_comm trades off increase GPU RAM usage to lower all-reduce latency. One experiment to observe impact of overlap_comm is to reduce train_batch_size. Can you please try that?
I am using a custom transformer model similar to ALBERT with parameter-sharing between layers. There are only ~13 million parameters. If I disable parameter-sharing there are ~110 million parameters.
8GB
Yes, I am using nvidia-smi.
Even when reducing my batch size from 96 to 1, the memory used by overlap_comm exceeds the 8GB available on my GPU.
Another interesting thing to note is that, if cpu_offload is enabled, manually instantiating the DeepSpeedCPUAdam optimizer and passing it to deepspeed.initialize() uses about 80% more CPU memory than allowing deepspeed.initialize() to automatically create the optimizer. VRAM usage is the same in either case.
Thanks for sharing these details, they are very helpful. ZeRO is targeted at multi-billion parameter models and so many of its intermediate buffers are very large (GBs) by default. The good news is that these buffers are configurable . The most relevant knobs are allgather_bucket_size and reduce_bucket_size. Both of these knobs have default values of 5e8, which translate to 1GB each (i.e., 5e8 x 2Bytes). Furthermore, for reduce_bucket_size, we double buffer when overlap_comm is enabled and currently have a hack that further scales it by 4.5 resulting in 9GB footprint by default (5e8 x 2Bytes x 2 x 4.5). So can you try reducing these two knobs in the json configuration by 2 or 3 orders of magnitude?
I reduced both buffers to 1e7 which solved my VRAM issue and allowed me to enable overlap_comm. Thank you for your help! However there is still the strange behavior that I noted at the end of my last comment. Manually instantiating DeepSpeedCPUAdam seems to give me ~20% higher samples/second while using about 7GB of additional CPU memory compared to just calling deepspeed.initialize(). The config is the same in both cases, and both have cpu_offload and overlap_comm enabled. This is the only difference in my code:
Glad to hear that overlap_comm is now working for you.
For the other issue, I think what is happening when you attempt to instantiating DeepSpeedCPUAdam through json is that you are actually instantiating torch.optim.Adam. You can inspect the log for this message to confirm. The reason this is happening is that in order to enable DeepspeedCPUAdam through json you need to set the type field to deepspeed_adam. We need to improve our documentation on this front, so thanks for finding this issue.
Hi @tjruwase, I faced the same issue that when I enable the cpu-offload, the GPU memory goes much higher and I cannot even use the same batch size I used before without cpu-offload. I have checked the log and the cpu optimizer is initialized.
10.0.83.130: [2020-12-19 03:07:07,491] [INFO] [engine.py:716:_configure_zero_optimizer] Creating fp16 ZeRO stage 2 optimizer
10.0.83.130: Checking ZeRO support for optimizer=DeepSpeedCPUAdam type=<class 'deepspeed.ops.adam.cpu_adam.DeepSpeedCPUAdam'>
10.0.83.130: Adam Optimizer #0 is created with AVX512 arithmetic capability.
10.0.83.130: Config: alpha=0.000100, betas=(0.900000, 0.999000), weight_decay=0.010000, adam_w=1
@szhengac, can you please the earlier discussion in this issue regarding internal buffer sizes of ZeRO. You can start from here. Please let us know whether or not the solutions there help your case. Thanks.
@tjruwase Thanks for your quick response. By reducing these two buffer sizes by 5x, the training can continue with zero-offload. However, I do not observe any memory reduction and the training is slower. And, why zero-offload uses more GPU buffer?
@szhengac Thanks for the update. ZeRO-Offload should not use more GPU memory, so something strange is happening. To help debug this issue, can you please provide the following?
How big is your model?
What is GPU RAM size?
What is GPU RAM usage with and without zero-offload?
With zero-offload, a 10B model should easily train on one A100 GPU with 40GB. For sanity check, can you please report the memory usage for batch size 1 with 1 GPU using zero-offload?
zero_optimization.allgather_bucket_size and zero_optimization.reduce_bucket_size have the biggest impact on memory usage during zero_optimization.stage=2
both default to 500000000 => 1GB buffer (5e8 x 2Bytes)
Overlap comm - increases gpu memory requirements
zero_optimization.overlap_comm=true trades off increase GPU RAM usage to lower all-reduce latency.
overlap_comm uses 4.5x the zero_optimization.allgather_bucket_size and zero_optimization.reduce_bucket_size resulting in 9GB footprint by default (5e8 x 2Bytes x 2 x 4.5), so for example this 2.5x change in buffer size may be a sufficient reduction:
@stas00 Thanks for the nice summary of my discussion and catching my typo as well :). @szhengac, I hope you find this summary useful as well.
Hopefully, we can work together to enable the maximum benefits of zero-offload for your models. So my suggestion is that we start with small configuration to nail down the expected memory usage by running with batch size = 1 on 1 GPU.
At this point I'm almost done integrating deepspeed into transformers: huggingface/transformers#9211
so my main goal at the moment is to test various configurations and ensure that they all work.
Then we can start on sorting out which config to use when.
Activity
tjruwase commentedon Oct 9, 2020
@anti4m Thanks for using DeepSpeed. This is an interesting observation and I have a few questions.
What is the model and number of parameters?
What is the size of GPU RAM?
Enabling
cpu_offloadis expected to reduce GPU RAM usage, so it is strange that toggling on/off doubles RAM usage. Are you using nvidia-smi to measure GPU RAM usage?Yes,
overlap_commtrades off increase GPU RAM usage to lower all-reduce latency. One experiment to observe impact ofoverlap_commis to reduce train_batch_size. Can you please try that?anti4m commentedon Oct 9, 2020
I am using a custom transformer model similar to ALBERT with parameter-sharing between layers. There are only ~13 million parameters. If I disable parameter-sharing there are ~110 million parameters.
8GB
Yes, I am using nvidia-smi.
Even when reducing my batch size from 96 to 1, the memory used by overlap_comm exceeds the 8GB available on my GPU.
Another interesting thing to note is that, if cpu_offload is enabled, manually instantiating the DeepSpeedCPUAdam optimizer and passing it to deepspeed.initialize() uses about 80% more CPU memory than allowing deepspeed.initialize() to automatically create the optimizer. VRAM usage is the same in either case.
tjruwase commentedon Oct 9, 2020
Thanks for sharing these details, they are very helpful. ZeRO is targeted at multi-billion parameter models and so many of its intermediate buffers are very large (GBs) by default. The good news is that these buffers are configurable . The most relevant knobs are
allgather_bucket_sizeandreduce_bucket_size. Both of these knobs have default values of 5e8, which translate to 1GB each (i.e., 5e8 x 2Bytes). Furthermore, for reduce_bucket_size, we double buffer whenoverlap_commis enabled and currently have a hack that further scales it by 4.5 resulting in 9GB footprint by default (5e8 x 2Bytes x 2 x 4.5). So can you try reducing these two knobs in the json configuration by 2 or 3 orders of magnitude?anti4m commentedon Oct 9, 2020
I reduced both buffers to 1e7 which solved my VRAM issue and allowed me to enable overlap_comm. Thank you for your help! However there is still the strange behavior that I noted at the end of my last comment. Manually instantiating DeepSpeedCPUAdam seems to give me ~20% higher samples/second while using about 7GB of additional CPU memory compared to just calling deepspeed.initialize(). The config is the same in both cases, and both have cpu_offload and overlap_comm enabled. This is the only difference in my code:
opt = deepspeed.ops.adam.DeepSpeedCPUAdam(model.parameters(), lr=0.00015)model_engine, _, data_loader, _ = deepspeed.initialize(args=cmd_args, model=model, optimizer=opt, training_data=dataset)Versus
model_engine, optimizer, data_loader, _ = deepspeed.initialize(args=cmd_args, model=model, model_parameters=model.parameters(), training_data=dataset)tjruwase commentedon Oct 9, 2020
Glad to hear that
overlap_commis now working for you.For the other issue, I think what is happening when you attempt to instantiating DeepSpeedCPUAdam through json is that you are actually instantiating torch.optim.Adam. You can inspect the log for this message to confirm. The reason this is happening is that in order to enable DeepspeedCPUAdam through json you need to set the type field to
deepspeed_adam. We need to improve our documentation on this front, so thanks for finding this issue.anti4m commentedon Oct 9, 2020
Yes, you are correct. Thank you. I am now closing the issue.
szhengac commentedon Dec 19, 2020
Hi @tjruwase, I faced the same issue that when I enable the cpu-offload, the GPU memory goes much higher and I cannot even use the same batch size I used before without cpu-offload. I have checked the log and the cpu optimizer is initialized.
10.0.83.130: [2020-12-19 03:07:07,491] [INFO] [engine.py:716:_configure_zero_optimizer] Creating fp16 ZeRO stage 2 optimizer
10.0.83.130: Checking ZeRO support for optimizer=DeepSpeedCPUAdam type=<class 'deepspeed.ops.adam.cpu_adam.DeepSpeedCPUAdam'>
10.0.83.130: Adam Optimizer #0 is created with AVX512 arithmetic capability.
10.0.83.130: Config: alpha=0.000100, betas=(0.900000, 0.999000), weight_decay=0.010000, adam_w=1
tjruwase commentedon Dec 20, 2020
@szhengac, can you please the earlier discussion in this issue regarding internal buffer sizes of ZeRO. You can start from here. Please let us know whether or not the solutions there help your case. Thanks.
szhengac commentedon Dec 20, 2020
@tjruwase Thanks for your quick response. By reducing these two buffer sizes by 5x, the training can continue with zero-offload. However, I do not observe any memory reduction and the training is slower. And, why zero-offload uses more GPU buffer?
tjruwase commentedon Dec 21, 2020
@szhengac Thanks for the update. ZeRO-Offload should not use more GPU memory, so something strange is happening. To help debug this issue, can you please provide the following?
szhengac commentedon Dec 21, 2020
Hi @tjruwase,
tjruwase commentedon Dec 22, 2020
@szhengac Thanks for providing these details.
With zero-offload, a 10B model should easily train on one A100 GPU with 40GB. For sanity check, can you please report the memory usage for batch size 1 with 1 GPU using zero-offload?
stas00 commentedon Dec 22, 2020
This discussion was very helpful, @tjruwase
I just have a brief suggestion:
You must have meant by 2-3 times, and not orders of magnitude.
We are trying to reduce 9GB to fit into 8GB, not into 0.08GB ;)
stas00 commentedon Dec 22, 2020
This is the summary I saved away from this discussion:
ZeRO features that decrease gpu memory usage
CPU offload
ZeRO features that increase gpu memory usage
zero_optimization.allgather_bucket_size and zero_optimization.reduce_bucket_size have the biggest impact on memory usage during zero_optimization.stage=2
both default to 500000000 => 1GB buffer (5e8 x 2Bytes)
Overlap comm - increases gpu memory requirements
zero_optimization.overlap_comm=true trades off increase GPU RAM usage to lower all-reduce latency.
overlap_comm uses 4.5x the zero_optimization.allgather_bucket_size and zero_optimization.reduce_bucket_size resulting in 9GB footprint by default (5e8 x 2Bytes x 2 x 4.5), so for example this 2.5x change in buffer size may be a sufficient reduction:
"allgather_bucket_size": 200000000,
"reduce_bucket_size": 200000000,
tjruwase commentedon Dec 22, 2020
@stas00 Thanks for the nice summary of my discussion and catching my typo as well :). @szhengac, I hope you find this summary useful as well.
Hopefully, we can work together to enable the maximum benefits of zero-offload for your models. So my suggestion is that we start with small configuration to nail down the expected memory usage by running with batch size = 1 on 1 GPU.
stas00 commentedon Dec 22, 2020
At this point I'm almost done integrating deepspeed into transformers:
huggingface/transformers#9211
so my main goal at the moment is to test various configurations and ensure that they all work.
Then we can start on sorting out which config to use when.
szhengac commentedon Dec 24, 2020
I will revisit this after I figure out another issue.
xiexbing commentedon Sep 14, 2023
the software issues are solved.