Repository navigation
Nvme offload checkpoint - #4707
Conversation
… into nvme_offload_checkpoint
|
Thank you! I hope your PR can be merged into the master soon. |
Previous PR deepspeedai#4416 had too many issues, closing that one and re-opening. This PR includes a passing test. This is a proposal for an implementation of checkpointing models when training with ZeRO-3 with NVMe offload: 1. Currently, the names of the files used in the checkpoint are based on the Python id of the parameter object, which is just the parameter's address in memory. This is not stable across runs, which has two disadvantages: - The NVMe offloading files grow with every run of the model even if the architecture did not change. This wastes disk space and, at least for me, was a surprise when I first saw it. It is not related to checkpointing. - Without a way to match the file to the offloaded tensor we can't reload the checkpoint. We propose an alternative naming scheme. The parameters are named after their ds_id instead of their Python id, and the tensors are named after their state_name and (new) parameter id. 2. A model checkpoint now has to include all the offloaded tensor files. During checkpoint save/load we copy all the tensor files to/from the "offloaded_tensors" subdirectory of the checkpoint. We provide some logging on the remaining space on the file system due to the potential size of these files, especially as they accumulate in each checkpoint. We do not copy the gradient files. 3. When loading the checkpoint, the optimizer already has prepared buffers for swapping. We need to purge them so that they are replaced with the freshly copied on-disk buffers from the checkpoint. The key differences between this PR and the previous one: - There's a test for a simple model with parameter/optimizer offload set to cpu/cpu, cpu/nvme and nvme/nvme. - Gradient files are not copied. - FP16 and FP32 parameter buffers are handled correctly during load. Fixes deepspeedai#2082. --------- Co-authored-by: Olatunji Ruwase <olruwase@microsoft.com> Co-authored-by: Logan Adams <114770087+loadams@users.noreply.github.com>
|
Hello, I have a question about one of the design details in your PR. There is a copytree command to copy the whole tree of nvme offload directory when saving/loading checkpoint, but I found What would be the difference between them? I am facing the |
|
@w4-jihunlorenzopark, |
|
@tjruwase Thank you for the response and I agree that the lossy overwrite will happen if making In multi-rank training scenario, save_checkpoint function is called by multiple processes. Then, all processes will call copytree line, but the saving logic for nvme offload seems all processes pointing to the same saving directory without the rank id of each process. For my case, the logging line shows The |
@w4-jihunlorenzopark, that looks like a bug. Are you able to provide a PR? |
|
@tjruwase Sure, I will happily send the PR in few days. Before that, I would like to confirm the way how I will implement. During writing this, I am wondering whether Any idea on this? |
|
@w4-jihunlorenzopark, your suggestion of including rank id looks good. Yes, this would only work if DP size is unchanged since ZeRO partitions checkpoint state across DP ranks. The following assertion should help to catch cases of DP changing: |
Previous PR #4416 had too many issues, closing that one and re-opening. This PR includes a passing test.
This is a proposal for an implementation of checkpointing models when training with ZeRO-3 with NVMe offload:
Currently, the names of the files used in the checkpoint are based on the Python id of the parameter object, which is just the parameter's address in memory. This is not stable across runs, which has two disadvantages:
We propose an alternative naming scheme. The parameters are named after their ds_id instead of their Python id, and the tensors are named after their state_name and (new) parameter id.
A model checkpoint now has to include all the offloaded tensor files. During checkpoint save/load we copy all the tensor files to/from the "offloaded_tensors" subdirectory of the checkpoint. We provide some logging on the remaining space on the file system due to the potential size of these files, especially as they accumulate in each checkpoint. We do not copy the gradient files.
When loading the checkpoint, the optimizer already has prepared buffers for swapping. We need to purge them so that they are replaced with the freshly copied on-disk buffers from the checkpoint.
The key differences between this PR and the previous one:
Fixes #2082.