[Feature] Make Hugging Face safetensors export configurable
Motivation
The current in-training Hugging Face safetensors export path is not very user-friendly. Users cannot customize the PreTrainedModel.save_pretrained call or artifact layout, and FP32-master/BF16 mixed-precision training exports FP32 weights unless users perform a separate conversion. Evaluation and serving commonly need BF16 artifacts without changing the training parameter dtype.
Issue #296 previously requested control over the saved model dtype and remains open. Setting the training model dtype to BF16 is not equivalent to selecting BF16 only for the exported Hugging Face model. The offline FSDP merger is also not a direct replacement because it consumes verl's native per-rank checkpoints rather than an already exported Hugging Face safetensors model.
Example
Consider an 8B model trained with the default mixed-precision configuration:
- Training: BF16 compute with FP32 master weights.
- Current Hugging Face export: One roughly 32 GB FP32
model.safetensorsfile. - Missing controls: No option to export BF16 weights or configure the safetensors shard size.
Proposed changes
The following PRs have been created to address these limitations:
- #7997 forwards optional
hf_save_pretrained_kwargstoPreTrainedModel.save_pretrained, includingmax_shard_sizefor sharded safetensors. - #8019 adds
hf_export_dtypeto select an export-only floating-point dtype independently of training precision.
Both preserve the current behavior when the new options are unset.
Source: verl-project/verl