GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: let a reused checkpoint directory replace earlier steps · cslht11/diffct@4e0c0a9

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • diffct
    • _solver_state.py
  • tests
    • test_solver_checkpoint_edges.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎diffct/_solver_state.py‎

Copy file name to clipboardExpand all lines: diffct/_solver_state.py
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,15 @@ def save_checkpoint(operator, directory, states, metadata, iteration, history, m
288288
step = Path(directory).resolve() / f"step-{iteration:06d}"
289289
step.mkdir(parents=True, exist_ok=True)
290290
rank = step / f"rank-{getattr(operator, 'rank', 0):05d}"
291-
rank.mkdir()
291+
rank.mkdir(exist_ok=True)
292292
for name, source in states.items():
293293
source = TensorStore(source.detach()) if isinstance(source, torch.Tensor) else source
294-
target = NpyStore.create(rank / f"{name}.npy", source.shape, dtype=source.dtype)
294+
path = rank / f"{name}.npy"
295+
if path.exists():
296+
# Re-saving replaces only this rank's previous file; other
297+
# ranks may be writing the same step concurrently.
298+
path.unlink()
299+
target = NpyStore.create(path, source.shape, dtype=source.dtype)
295300
copy_blocks(source, target, elements)
296301
target.flush()
297302
manifest[name] = dict(shape=list(source.shape), dtype=str(source.dtype), fingerprint=fingerprint(target, elements))
Collapse file

‎tests/test_solver_checkpoint_edges.py‎

Copy file name to clipboardExpand all lines: tests/test_solver_checkpoint_edges.py
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,17 @@ def test_four_rank_atomic_metadata_failure_rejects_collectively_before_more_oper
285285
assert len(record["calls"]) == record["calls_at_publication"], "rank executed another operator after publication failure"
286286
assert record["complete_state_observations"] >= 2, "missing all-rank write/flush evidence before step2 publication"
287287
assert record["elapsed"] < 15, "publication failure waited for the Gloo timeout"
288+
289+
290+
def test_reusing_a_checkpoint_directory_replaces_steps(tmp_path):
291+
from diffct import Projector, cgls
292+
from diffct.geometry import circular_trajectory_2d_parallel
293+
294+
trajectory = circular_trajectory_2d_parallel(8, device="cpu", dtype=torch.float32)
295+
projector = Projector(trajectory, volume_shape=(16, 16), detector_shape=(24,),
296+
beam="parallel", backend="torch")
297+
sinogram = projector(torch.rand(16, 16))
298+
first = cgls(projector, sinogram, iterations=2, checkpoint_directory=str(tmp_path))
299+
second = cgls(projector, sinogram, iterations=2, checkpoint_directory=str(tmp_path))
300+
assert [p.name for p in sorted(tmp_path.iterdir())] == ["step-000001", "step-000002"]
301+
torch.testing.assert_close(first.volume.float(), second.volume.float())

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.