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. Used for every expert-parallel model; a model sharded by FSDP2 alone opts in
with 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: hf_ptq exports under
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.- Parameters:
model (Module)
export_dir (str | Path)
maxbound (float)
kv_cache_format (str | None)
max_shard_size (str | int)
is_modelopt_qlora (bool)
extra_state_dict (dict[str, Tensor] | None)
- Return type:
None