BurnyCoder commited on
Commit
4a6ee3c
·
verified ·
1 Parent(s): c0410cf

Publish CUDA and restart verification before execution

Browse files
research/docs/runbook.md CHANGED
@@ -3,10 +3,10 @@
3
  Install Python 3.12 and [uv](https://docs.astral.sh/uv/). The lock targets Windows AMD64 and Linux x86_64 with an NVIDIA driver supporting the CUDA 13.2 PyTorch wheel. The default scratch model and adapter math use float32. Make a project-local environment and install all locked dependencies with `uv sync --locked`. Copy `.env.example` to `.env` and optionally set `THIRDLOSS_STORAGE` to a directory with room for corpora, CUDA checkpoints and Hub downloads. Use the existing GitHub CLI and Hugging Face login for publication.
4
 
5
  ```sh
6
- uv run pytest -q
7
  uv run thirdloss prepare --stage stories
8
  uv run thirdloss train --stage stories --method third --phase pilot --seed 0 --ratio 0.03
9
- uv run thirdloss dashboard --port 8765
10
  ```
11
 
12
  In another terminal, open the printed dashboard URL. The public explorer reads the last published results. The local dashboard reads running records. Accuracy is top-one token accuracy and NLL is in nats per target token. The training-time column excludes data preparation, checks, validation, checkpoint serialization and publication.
 
3
  Install Python 3.12 and [uv](https://docs.astral.sh/uv/). The lock targets Windows AMD64 and Linux x86_64 with an NVIDIA driver supporting the CUDA 13.2 PyTorch wheel. The default scratch model and adapter math use float32. Make a project-local environment and install all locked dependencies with `uv sync --locked`. Copy `.env.example` to `.env` and optionally set `THIRDLOSS_STORAGE` to a directory with room for corpora, CUDA checkpoints and Hub downloads. Use the existing GitHub CLI and Hugging Face login for publication.
4
 
5
  ```sh
6
+ uv run thirdloss verify
7
  uv run thirdloss prepare --stage stories
8
  uv run thirdloss train --stage stories --method third --phase pilot --seed 0 --ratio 0.03
9
+ uv run thirdloss dashboard --port 18765
10
  ```
11
 
12
  In another terminal, open the printed dashboard URL. The public explorer reads the last published results. The local dashboard reads running records. Accuracy is top-one token accuracy and NLL is in nats per target token. The training-time column excludes data preparation, checks, validation, checkpoint serialization and publication.
research/src/thirdloss/cli.py CHANGED
@@ -34,7 +34,7 @@ def parser():
34
  p = argparse.ArgumentParser(description=__doc__)
35
  p.add_argument("--project",type=Path,default=Path.cwd())
36
  parsers = p.add_subparsers(dest="action",required=True)
37
- for action in ("prepare","train","study","freeze","evaluate","report","dashboard","publish","progress"):
38
  sub = parsers.add_parser(action)
39
  if action in {"prepare","study"}:
40
  sub.add_argument("--stage",choices=(*HORIZONS,"both"),default="both")
@@ -63,6 +63,9 @@ def main(argv=None):
63
  args = parser().parse_args(argv)
64
  project = args.project.resolve()
65
  storage = storage_root(project)
 
 
 
66
  if args.action=="dashboard":
67
  return dashboard(project,args.port)
68
  if args.action in {"report","progress","publish"}:
 
34
  p = argparse.ArgumentParser(description=__doc__)
35
  p.add_argument("--project",type=Path,default=Path.cwd())
36
  parsers = p.add_subparsers(dest="action",required=True)
37
+ for action in ("prepare","train","study","freeze","evaluate","report","dashboard","publish","progress","verify"):
38
  sub = parsers.add_parser(action)
39
  if action in {"prepare","study"}:
40
  sub.add_argument("--stage",choices=(*HORIZONS,"both"),default="both")
 
63
  args = parser().parse_args(argv)
64
  project = args.project.resolve()
65
  storage = storage_root(project)
66
+ if args.action=="verify":
67
+ from .verification import verify
68
+ return verify(project)
69
  if args.action=="dashboard":
70
  return dashboard(project,args.port)
71
  if args.action in {"report","progress","publish"}:
research/src/thirdloss/verification.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Persist a portable verification record from pytest's machine-readable JUnit output."""
2
+
3
+ import subprocess
4
+ import sys
5
+ import xml.etree.ElementTree as ET
6
+
7
+ from .records import time_now, write_json
8
+
9
+
10
+ def verify(project):
11
+ directory = project/"tmp"/"verification"
12
+ directory.mkdir(parents=True,exist_ok=True)
13
+ xml = directory/"pytest.xml"
14
+ completed = subprocess.run([sys.executable,"-m","pytest","-q","--junitxml",str(xml)],cwd=project)
15
+ records = []
16
+ for case in ET.parse(xml).iter("testcase"):
17
+ outcome = next((name for name in ("error","failure","skipped") if case.find(name) is not None),"passed")
18
+ records.append({"test":f"{case.get('classname')}.{case.get('name')}",
19
+ "seconds":float(case.get("time","0")),"outcome":outcome})
20
+ write_json(project/"results"/"verification"/"tests.json",{
21
+ "checked_at":time_now(), "git_revision":subprocess.check_output(
22
+ ["git","rev-parse","HEAD"],cwd=project,text=True).strip(),
23
+ "exit_code":completed.returncode,"cases":records})
24
+ if completed.returncode:
25
+ raise SystemExit(completed.returncode)
research/tests/test_derivatives.py CHANGED
@@ -14,6 +14,29 @@ from torch.func import jacfwd
14
  from thirdloss.penalties import estimate
15
 
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  @pytest.fixture(scope="module", autouse=True)
18
  def small_cpu_tensors():
19
  """Keep the tiny reference calculations deterministic and inexpensive on a CPU."""
 
14
  from thirdloss.penalties import estimate
15
 
16
 
17
+ @pytest.mark.skipif(not torch.cuda.is_available(),reason="CUDA hardware unavailable")
18
+ def test_gpu_production_decoder_third_order_update_matches_cpu():
19
+ """Verify the same fourth derivative on the actual eager CUDA kernels and CPU FP64."""
20
+ from copy import deepcopy
21
+ from thirdloss.models import StoryConfig, StoryTransformer, token_loss
22
+ torch.manual_seed(7)
23
+ cpu = StoryTransformer(StoryConfig(vocab_size=7,width=8,heads=2,layers=1,hidden=12,context=4)).double()
24
+ gpu = deepcopy(cpu).cuda()
25
+ ids = torch.tensor([[2,3,1,0],[4,2,5,3]])
26
+ u = tuple(torch.randint(2,p.shape).double()*2-1 for p in cpu.parameters())
27
+ v = tuple(torch.randint(2,p.shape).double()*2-1 for p in cpu.parameters())
28
+ def calculate(model,device):
29
+ parameters = tuple(model.parameters())
30
+ loss = token_loss(model(ids.to(device)),((ids+1)%7).to(device))
31
+ term = estimate(loss,parameters,"third",tuple(p.to(device) for p in u),tuple(p.to(device) for p in v))
32
+ gradient = torch.autograd.grad(term,parameters)
33
+ return term.detach().cpu(),torch.cat([g.flatten() for g in gradient]).detach().cpu()
34
+ expected = calculate(cpu,"cpu")
35
+ actual = calculate(gpu,"cuda")
36
+ for reference,observed in zip(expected,actual,strict=True):
37
+ torch.testing.assert_close(observed,reference,rtol=2e-8,atol=1e-5)
38
+
39
+
40
  @pytest.fixture(scope="module", autouse=True)
41
  def small_cpu_tensors():
42
  """Keep the tiny reference calculations deterministic and inexpensive on a CPU."""
research/tests/test_training.py CHANGED
@@ -9,8 +9,8 @@ from safetensors.torch import load_file
9
  from thirdloss import train
10
  from thirdloss.models import StoryConfig, StoryTransformer
11
  from thirdloss.objectives import add_penalty
12
- from thirdloss.records import read_json, write_json
13
- from thirdloss.windows import TrainingWindows, gate, generator
14
 
15
 
16
  def small_model(stage, seed, device, storage):
@@ -77,11 +77,10 @@ def test_step_recovery_matches_uninterrupted_weights(tmp_path,monkeypatch):
77
  store2 = tmp_path/"store2"
78
  shutil.copytree(root/"data",store2/"data")
79
  normal = train.run_one(reference,store2,"stories","third","smoke",seed,0.03,torch.device("cpu"))
80
- for path, other in [(root,store2)]:
81
- rel = f"checkpoints/{normal['id']}/export/model.safetensors"
82
- first, second = load_file(str(path/rel)),load_file(str(other/rel))
83
- for name in first:
84
- torch.testing.assert_close(first[name],second[name],rtol=0,atol=0)
85
  assert normal["dev_nll"]==resumed["dev_nll"]
86
  finally:
87
  torch.set_num_threads(prior_threads)
 
9
  from thirdloss import train
10
  from thirdloss.models import StoryConfig, StoryTransformer
11
  from thirdloss.objectives import add_penalty
12
+ from thirdloss.records import write_json
13
+ from thirdloss.windows import gate
14
 
15
 
16
  def small_model(stage, seed, device, storage):
 
77
  store2 = tmp_path/"store2"
78
  shutil.copytree(root/"data",store2/"data")
79
  normal = train.run_one(reference,store2,"stories","third","smoke",seed,0.03,torch.device("cpu"))
80
+ rel = f"checkpoints/{normal['id']}/export/model.safetensors"
81
+ first, second = load_file(str(root/rel)),load_file(str(store2/rel))
82
+ for name in first:
83
+ torch.testing.assert_close(first[name],second[name],rtol=0,atol=0)
 
84
  assert normal["dev_nll"]==resumed["dev_nll"]
85
  finally:
86
  torch.set_num_threads(prior_threads)