LittlePlyResearch notebook

checkpoint.py

python · 14 lines · Exact bytes

Line 1 ↗
Version & provenance · theory-cm7

Recorded SHA-256 739c3dc8697b66c123d9c5df4c3605910bfda4d70012704ce8ea298a09fadf0aRendered SHA-256 739c3dc8697b66c123d9c5df4c3605910bfda4d70012704ce8ea298a09fadf0a

Apache-2.0 original project code; dependencies retain their own licenses. License notes. Line links are stable within this snapshot. CM-7 completed implementation source; original and public rendered hashes recorded. Host-specific paths use /work placeholders; inspect reproduction instructions before running. Separate Rust helper retains its GPL license.

1"""Committed-cursor resume contract, including per-state exposure reconciliation."""
2import random,hashlib
3import numpy as np
4import torch
5def capture_rng(device=None):
6    n=np.random.get_state()
7    return {'python':random.getstate(),'numpy':(n[0],n[1].tolist(),n[2],n[3],n[4]),'torch':torch.get_rng_state(),
8            'cuda':None if device is None else torch.cuda.get_rng_state(device)}
9def restore_rng(value,device=None):
10    random.setstate(value['python']);n=value['numpy'];np.random.set_state((n[0],np.asarray(n[1],dtype=np.uint32),n[2],n[3],n[4]))
11    torch.set_rng_state(value['torch'])
12    if device is not None:
13        if value['cuda'] is None:raise ValueError('missing CUDA RNG')
14        torch.cuda.set_rng_state(value['cuda'],device)