Skip to content

Commit 1584a18

Browse files
authored
[torch_checkpointing][test] use real barrier for test (#4574)
This test does `CheckpointWriterConfig(barrier_config=None)`, which I'm about to disallow without further config. * In meta-pytorch/torch_checkpointing@32f50c1, we change the default barrier from `None` to `DefaultStoreBarrier`. This is does not affect Titan; it currently explicitly sets up a `TCPStoreBarrier`. * Current torch_checkpointing behaviour is to write to a temp dir and atomically rename iff a barrier is configured. I am soon to make this an explicit flag (defaulting to True), which will make this test break. So fixing the test before I make the api change. Tested with `pytest ./tests/unit_tests/cpu/test_torch_checkpointing.py`
1 parent 98c6cea commit 1584a18

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

‎tests/unit_tests/cpu/test_torch_checkpointing.py‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -613,31 +613,31 @@ def test_hf_consolidation_uses_the_path_the_backend_supplies(self) -> None:
613613
the writer names, that is where the shards are, so the callback must
614614
consolidate from it verbatim.
615615
"""
616-
received: list[str] = []
616+
617+
def _pre_finalize_callback_ensure_nonempty_dir(path, _logger) -> None:
618+
self.assertTrue(os.path.isdir(path))
619+
self.assertGreater(
620+
len(os.listdir(path)),
621+
0,
622+
msg=f"callback was handed {path!r}, which holds no shards",
623+
)
624+
617625
with tempfile.TemporaryDirectory() as root:
618626
checkpoint_id = os.path.join(root, "step-1", "sharded")
619627
config = BackendCheckpointManager.Config(
620628
default=ItemSpec(requires_copy=False),
621-
save=SyncCheckpointSaverConfig(
622-
writer_config=CheckpointWriterConfig(barrier_config=None)
623-
),
629+
save=SyncCheckpointSaverConfig(writer_config=CheckpointWriterConfig()),
624630
# O_DIRECT alignment support varies across CI filesystems and
625631
# is unrelated to the callback-path contract under test.
626632
storage_config=LocalFileSystemStorageConfig(use_direct_io=False),
627-
pre_finalize_callback=lambda path, _logger: received.append(path),
633+
pre_finalize_callback=_pre_finalize_callback_ensure_nonempty_dir,
628634
)
629635
manager = config.build()
630636
try:
631637
manager.save(checkpoint_id, {MODEL: torch.ones(2)})
632638
finally:
633639
manager.close()
634640

635-
self.assertEqual(1, len(received))
636-
self.assertTrue(
637-
os.listdir(received[0]),
638-
f"callback was handed {received[0]!r}, which holds no shards",
639-
)
640-
641641
def test_a_finished_hf_export_is_a_valid_checkpoint(self) -> None:
642642
# A final HF export keeps the backend's metadata in its nested "sharded"
643643
# directory and the consolidated files at the root. Recognising only the

0 commit comments

Comments
 (0)