distributed_writer#
No-gather distributed HF checkpoint writer for FSDP2.
Every tensor is sent to exactly one owner rank over batched point-to-point sends and
written from there, so no rank ever materializes the whole model and no unit is
replicated across ranks. Selected by MODELOPT_FSDP2_EXPORT=nogather.
Functions
No-gather distributed HF export. |
- distributed_save_hf_checkpoint(model, export_dir, maxbound, kv_cache_format, max_shard_size='10GB', is_modelopt_qlora=False, extra_state_dict=None)#
No-gather distributed HF export.
Thin wrapper: a caller may be in
torch.inference_mode(), so run the entire write with inference mode DISABLED via a nestedinference_mode(False)context – the.detach()inget_model_state_dictand the version- counted ops in the write path both reject inference tensors. The context form reliably restores normal mode for this scope (a decorator did not, under the caller’s already-active inference_mode).no_gradtoo:inference_mode(False)re-ENABLES autograd, so a bareclone()/detach()on an inference tensor would try to set up grad and read its (missing) version counter –no_gradavoids that while the clones still land as normal tensors because inference mode is off.- Returns:
Whether the tensors carry their original checkpoint names. The reverse conversion is all or nothing across ranks, so this is the same on every rank.
- Parameters:
model (Module)
export_dir (str | Path)
maxbound (float)
kv_cache_format (str | dict[str, dict[str, str]] | None)
max_shard_size (str | int)
is_modelopt_qlora (bool)
extra_state_dict (dict[str, Tensor] | None)
- Return type:
bool