Repository navigation
[Torchtrain][Checkpoint] Add support to allow dtype conversion - #222
Conversation
| # Context: https://github.com/pytorch/torchtitan/blob/main/torchtitan/models/llama/model.py#L348 | ||
| self.states["model"].pop("freqs_cis") | ||
|
|
||
| if self.export_dtype != torch.float32: |
There was a problem hiding this comment.
technically, shouldn't we do the check once per parameter whether the current parameter matches the export type?
and shouldn't we not assume that float32 is the type that the model came from? (what if the model was actually in bf16 but someone wanted to export in .. fp8
There was a problem hiding this comment.
For now, the state dict generated by the model is fp32. So if we train with torchtitan and we do a state_dict call, the dtype is fp32.
|
|
||
|
|
||
| DTYPE_MAP = { | ||
| "fp16": torch.float16, |
There was a problem hiding this comment.
do we have helpers in torch somewhere for short versions of our torch dtypes? would be nice not to invent our own mapping if there is one already
There was a problem hiding this comment.
I tried searching in PyTorch, but I can't seem to find a map.
Maybe we should just do.
{
"torch.float16": torch.float16,
...
}
There was a problem hiding this comment.
Alright taking the decision of doing:
{
"float16": torch.float16,
...
}
Adds a field of checkpoint.export_dtype: we allow dtype conversion only when we are checkpoint model weights only and the current dtype is not the same as the export dtype at the end of the training. Also add a change to get rid of `freqs_cis` buffer when exporting. We can see with export_dtype=bf16, the model weights is about half of the size when comparing to export_dtype=fp32. ``` # model_weights_only=false (pytorch-3.10) [[email protected] ~/local/torchtrain (add_export_dtype)]$ du -h test_runner_checkpoint_full_checkpoint 212M test_runner_checkpoint_full_checkpoint/step-5 212M test_runner_checkpoint_full_checkpoint/step-10 212M test_runner_checkpoint_full_checkpoint/step-15 212M test_runner_checkpoint_full_checkpoint/step-20 846M test_runner_checkpoint_full_checkpoint # model_weights_only=true and export_dtype = fp32 (pytorch-3.10) [[email protected] ~/local/torchtrain (add_export_dtype)]$ du -h test_runner_checkpoint_model_weights_only 212M test_runner_checkpoint_model_weights_only/step-5 70M test_runner_checkpoint_model_weights_only/step-10 281M test_runner_checkpoint_model_weights_only # model_weights_only=true and export_dtype = bf16 (pytorch-3.10) [[email protected] ~/local/torchtrain (add_export_dtype)]$ du -h test_runner_checkpoint_model_weights_only_bf16 212M test_runner_checkpoint_model_weights_only_bf16/step-5 35M test_runner_checkpoint_model_weights_only_bf16/step-10 247M test_runner_checkpoint_model_weights_only_bf16 ```
…ch#222) Adds a field of checkpoint.export_dtype: we allow dtype conversion only when we are checkpoint model weights only and the current dtype is not the same as the export dtype at the end of the training. Also add a change to get rid of `freqs_cis` buffer when exporting. We can see with export_dtype=bf16, the model weights is about half of the size when comparing to export_dtype=fp32. ``` # model_weights_only=false (pytorch-3.10) [[email protected] ~/local/torchtrain (add_export_dtype)]$ du -h test_runner_checkpoint_full_checkpoint 212M test_runner_checkpoint_full_checkpoint/step-5 212M test_runner_checkpoint_full_checkpoint/step-10 212M test_runner_checkpoint_full_checkpoint/step-15 212M test_runner_checkpoint_full_checkpoint/step-20 846M test_runner_checkpoint_full_checkpoint # model_weights_only=true and export_dtype = fp32 (pytorch-3.10) [[email protected] ~/local/torchtrain (add_export_dtype)]$ du -h test_runner_checkpoint_model_weights_only 212M test_runner_checkpoint_model_weights_only/step-5 70M test_runner_checkpoint_model_weights_only/step-10 281M test_runner_checkpoint_model_weights_only # model_weights_only=true and export_dtype = bf16 (pytorch-3.10) [[email protected] ~/local/torchtrain (add_export_dtype)]$ du -h test_runner_checkpoint_model_weights_only_bf16 212M test_runner_checkpoint_model_weights_only_bf16/step-5 35M test_runner_checkpoint_model_weights_only_bf16/step-10 247M test_runner_checkpoint_model_weights_only_bf16 ```
oneCCL 2022 hangs when a process that hosts a TorchStore storage volume also runs FSDP collectives (oneCCL pytorch#222), and concurrent first weight pulls deadlock in communicator creation (pytorch#225). On XPU the storage volumes therefore run in their own procs, a twin of the trainer mesh on the same devices, and the first pull after setup runs one generator at a time. Both are config fields defaulting to device_type == "xpu", so CUDA is unchanged.
oneCCL 2022 hangs when a process that hosts a TorchStore storage volume also runs FSDP collectives (oneCCL pytorch#222), and concurrent first weight pulls deadlock in communicator creation (pytorch#225). On XPU, MonarchActorSystem therefore runs the storage volumes in their own procs, a twin of the trainer mesh on the same devices (MonarchActorSystem.Config.storage_volumes_in_own_procs), and the router runs the first pull after setup one generator at a time (InterGeneratorRouter.Config.sequential_initial_pull). Both default to device_type == "xpu", so CUDA is unchanged.
Adds a field of checkpoint.export_dtype: we allow dtype conversion only when we are checkpoint model weights only and the current dtype is not the same as the export dtype at the end of the training.
Also add a change to get rid of
freqs_cisbuffer when exporting.We can see with export_dtype=bf16, the model weights is about half of the size when comparing to export_dtype=fp32.