Skip to content

Commit e84574c

Browse files
diego-urgellmeta-codesync[bot]
authored andcommitted
Plumb use_collectives knob from KnobOptions to dcp.async_save (#1064)
Summary: Pull Request resolved: #1064 ### This Diff Adds a `use_collectives: bool = True` field to `KnobOptions` and threads it through `DistributedCheckpointSaver._checkpoint_impl` to both `dcp.async_save(...)` and `dcp.save(...)`. When set to `False`, DCP skips the cross-rank gather/scatter rounds it normally uses to coordinate the global save plan. Each rank writes its local shards independently. The `use_collectives` parameter is a real public kwarg on `dcp.{save,async_save}` (see `caffe2/torch/distributed/checkpoint/state_dict_saver.py`), added in upstream PyTorch PR #147758 specifically for cases where the coord-side rounds become "prohibitively expensive as the job scale grows". ### Motivation At 397B TP=8 EP=16 (qwen35_moe_sp project), the gather/scatter rounds account for ~50 minutes of a ~67 minute save wall. Setting `use_collectives=False` removes that bottleneck entirely. Trade-off documented in the docstring: the resulting checkpoint is no longer cross-world re-shardable; restart with the same parallelism layout still works. This is the correct default-True behavior — existing users are unaffected; the knob is opt-in. Default `True` preserves backward compatibility for every existing torchtnt consumer. Reviewed By: galrotem Differential Revision: D105451194 fbshipit-source-id: f3eb80236c83793b37021c0fa023365c59cd8db4
1 parent 6745f20 commit e84574c

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

torchtnt/framework/callbacks/checkpointer_types.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ class KnobOptions:
2020
max_per_rank_io_concurrency: Maximum number of concurrent IO operations per rank in checkpointing.
2121
Defaults to 16.
2222
enable_storage_optimization: Enable storage efficiency optimizations for Distributed Checkpointing.
23+
use_collectives: If ``False``, skip the cross-rank gather/scatter rounds that DCP uses to
24+
coordinate the global save plan. Each rank writes its local shards
25+
independently. Defaults to ``True``. Setting to ``False`` removes the
26+
coord-side bottleneck that becomes prohibitively expensive at large scales
27+
(e.g. ~50 minutes of a ~67 minute save wall at 397B TP=8 EP=16). Trade-off:
28+
the resulting checkpoint is no longer cross-world re-shardable; restart
29+
with the same parallelism layout still works.
2330
"""
2431

2532
# use a more conservative number of concurrent IO operations per rank in Checkpointing
@@ -28,6 +35,8 @@ class KnobOptions:
2835
# This would enable storage efficiency optimizations (model store):
2936
# e.g. Compression, Batching, Quantization etc.
3037
enable_storage_optimization: bool = True
38+
# Skip DCP coord-side gather/scatter rounds.
39+
use_collectives: bool = True
3140

3241

3342
@dataclass

torchtnt/framework/callbacks/dcp_saver.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ def _checkpoint_impl(
198198
storage_writer=storage_writer,
199199
planner=planner,
200200
async_stager=stager,
201+
use_collectives=self._knob_options.use_collectives,
201202
)
202203
self._prev_snapshot = cast(Future, prev_snapshot)
203204
if curr_snapshot_wait:
@@ -210,6 +211,7 @@ def _checkpoint_impl(
210211
process_group=self._process_group,
211212
storage_writer=storage_writer,
212213
planner=planner,
214+
use_collectives=self._knob_options.use_collectives,
213215
)
214216

215217
return True

0 commit comments

Comments
 (0)