BurnyCoder commited on
Commit
3568e2c
·
verified ·
1 Parent(s): 9fb2774

Register full-checkpoint precision audit before reference measurements

Browse files
research/docs/study.json CHANGED
The diff for this file is too large to render. See raw diff
 
research/reports/paper.pdf CHANGED
Binary files a/research/reports/paper.pdf and b/research/reports/paper.pdf differ
 
research/reports/progress.md CHANGED
@@ -1,6 +1,6 @@
1
  # Study progress
2
 
3
- Updated 2026-11-25T07:34:55+00:00.
4
 
5
  13 training/control records and 0 final evaluations are complete. This is 10.8% of 120 planned model milestones.
6
 
 
1
  # Study progress
2
 
3
+ Updated 2026-11-25T07:39:12+00:00.
4
 
5
  13 training/control records and 0 final evaluations are complete. This is 10.8% of 120 planned model milestones.
6
 
research/reports/reviews/adapter-verification.md CHANGED
@@ -9,3 +9,9 @@ The first version used a single close pair of parameter displacements. The finit
9
  The first probe of the pretrained model produced finite adapter-gradient coordinates but an infinite single-precision norm. A replay of the same training windows and random signs found that the sum of squares overflowed. The implementation widens the norm reduction to double precision when the ordinary result is infinite or zero. Scores, calibration draws, gates and tuning ratios keep their registered definitions. The original measurements include the number of nonfinite coordinates, both norms, elapsed time, and peak device allocations. [Replay record](../../results/verification/pythia-calibration-replay.json) · [PyTorch norm accumulation](https://docs.pytorch.org/docs/stable/generated/torch.linalg.vector_norm.html)
10
 
11
  The joint computation also allocated more memory than the device’s dedicated VRAM. The adapter path now differentiates the two windows sequentially. For fixed probes, write their contractions as r₀ and r₁ and their mean as R. The derivative of the squared norm of R with respect to each rᵢ equals R. Propagating this cotangent through each window’s third-derivative graph and summing the resulting fourth-order contributions includes the cross-window terms. The two windows use identical probes, frozen weights during the calculation, and deterministic forwards. The verification suite compares the scalar and every gradient coordinate against a joint calculation in double precision. [Source](../../src/thirdloss/objectives.py) · [Gradient caching and the chain rule](https://arxiv.org/abs/2101.06983) · [Test](../../tests/test_derivatives.py)
 
 
 
 
 
 
 
9
  The first probe of the pretrained model produced finite adapter-gradient coordinates but an infinite single-precision norm. A replay of the same training windows and random signs found that the sum of squares overflowed. The implementation widens the norm reduction to double precision when the ordinary result is infinite or zero. Scores, calibration draws, gates and tuning ratios keep their registered definitions. The original measurements include the number of nonfinite coordinates, both norms, elapsed time, and peak device allocations. [Replay record](../../results/verification/pythia-calibration-replay.json) · [PyTorch norm accumulation](https://docs.pytorch.org/docs/stable/generated/torch.linalg.vector_norm.html)
10
 
11
  The joint computation also allocated more memory than the device’s dedicated VRAM. The adapter path now differentiates the two windows sequentially. For fixed probes, write their contractions as r₀ and r₁ and their mean as R. The derivative of the squared norm of R with respect to each rᵢ equals R. Propagating this cotangent through each window’s third-derivative graph and summing the resulting fourth-order contributions includes the cross-window terms. The two windows use identical probes, frozen weights during the calculation, and deterministic forwards. The verification suite compares the scalar and every gradient coordinate against a joint calculation in double precision. [Source](../../src/thirdloss/objectives.py) · [Gradient caching and the chain rule](https://arxiv.org/abs/2101.06983) · [Test](../../tests/test_derivatives.py)
12
+
13
+ ## Full-checkpoint precision audit
14
+
15
+ The full pretrained GPU replay used the same weight digest, inputs and sign tensors in both calculations. Its penalty and fourth-order gradient differed substantially between joint and sequential windows. Fresh initialization and regenerated probes reproduced the sequential calculation within the same process. Deterministic initialization and a passing small-model derivative test alone were insufficient to certify numerical accuracy at this checkpoint. The CPU single-precision comparison agreed across batching for the contracted third derivative. The first adapter pilot is diagnostic pending this audit. No confirmatory adapter training or test-set scoring preceded the audit. [GPU gradient comparison](../../results/verification/pythia-joint-cuda.json) · [CPU third-derivative comparison](../../results/verification/pythia-window-comparison.json) · [PyTorch numerical accuracy](https://docs.pytorch.org/docs/stable/notes/numerical_accuracy.html)
16
+
17
+ The independent reference promotes the pinned float32 model to double precision, retains double precision at attention softmax, uses the original CUDA signs, and computes the joint penalty gradient via the per-window chain rule. Comparing errors to this reference tests whether the implementation accurately evaluates the specified loss derivatives on real Pythia weights. [Reference calculation](../../src/thirdloss/precision.py)
research/src/thirdloss/cli.py CHANGED
@@ -44,6 +44,7 @@ def parser():
44
  sub.add_argument("--device",default="cuda")
45
  if action=="verify":
46
  sub.add_argument("--pretrained",action="store_true",help="Also compare a full joint derivative on the prepared adapter training corpus")
 
47
  sub.add_argument("--device",default="cuda",help="Device for the optional full pretrained cross-check")
48
  if action=="train":
49
  sub.add_argument("--method",choices=(*METHODS,"unigram","initial"),required=True)
@@ -74,6 +75,10 @@ def main(argv=None):
74
  from .probe_check import verify_pretrained
75
  from .records import setup_device
76
  verify_pretrained(project,setup_device(args.device))
 
 
 
 
77
  return
78
  if args.action=="dashboard":
79
  return dashboard(project,args.port)
 
44
  sub.add_argument("--device",default="cuda")
45
  if action=="verify":
46
  sub.add_argument("--pretrained",action="store_true",help="Also compare a full joint derivative on the prepared adapter training corpus")
47
+ sub.add_argument("--reference",action="store_true",help="Compute the FP64 pretrained reference using the original CUDA signs")
48
  sub.add_argument("--device",default="cuda",help="Device for the optional full pretrained cross-check")
49
  if action=="train":
50
  sub.add_argument("--method",choices=(*METHODS,"unigram","initial"),required=True)
 
75
  from .probe_check import verify_pretrained
76
  from .records import setup_device
77
  verify_pretrained(project,setup_device(args.device))
78
+ if args.reference:
79
+ from .precision import reference_gradient
80
+ from .records import setup_device
81
+ reference_gradient(project,setup_device(args.device))
82
  return
83
  if args.action=="dashboard":
84
  return dashboard(project,args.port)
research/src/thirdloss/precision.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Independent, high-precision reference for the first real adapter calibration probe."""
2
+
3
+ import hashlib
4
+ import time
5
+ from unittest.mock import patch
6
+
7
+ import torch
8
+
9
+ from .models import build_model, logits_of, token_loss, trainable_digest
10
+ from .objectives import two_window_third_gradient
11
+ from .penalties import random_signs
12
+ from .records import storage_root, time_now, write_json
13
+ from .windows import TrainingWindows, generator, probe_rows
14
+
15
+
16
+ def dtype_attention(module,query,key,value,attention_mask,scaling,dropout=0.0,**kwargs):
17
+ """The upstream eager formula with softmax retaining the study tensor's precision.
18
+
19
+ https://github.com/huggingface/transformers/blob/main/src/transformers/models/gpt_neox/modeling_gpt_neox.py
20
+ """
21
+ scores = (query @ key.transpose(-2,-1))*scaling
22
+ if attention_mask is not None:
23
+ scores = scores+attention_mask
24
+ weights = torch.nn.functional.dropout(scores.softmax(-1),p=dropout,training=module.training)
25
+ return (weights @ value).transpose(1,2).contiguous(),weights
26
+
27
+
28
+ def reference_gradient(project,device):
29
+ """Generate the production CUDA signs and promote the same pretrained weights to FP64."""
30
+ from safetensors.torch import save_file
31
+ from transformers.models.gpt_neox import modeling_gpt_neox as neox
32
+ storage=storage_root(project)
33
+ model=build_model("abstracts",0,device,storage).eval()
34
+ initial=trainable_digest(model)
35
+ parameters=tuple(p for p in model.parameters() if p.requires_grad)
36
+ # Generate signs with the *same* device generator as the observed pilot, also for CPU AD.
37
+ rng=generator(torch.device("cuda"),6247,0,827)
38
+ shapes=tuple(torch.empty_like(p,device="cuda") for p in parameters)
39
+ signs=[tuple(g.to(device=device,dtype=torch.float64) for g in random_signs(shapes,rng)) for _ in range(2)]
40
+ del shapes,parameters
41
+ model.double()
42
+ parameters=tuple(p for p in model.parameters() if p.requires_grad)
43
+ x,y=TrainingWindows(storage/"data"/"abstracts"/"train.bin",6247,8).get(0,device)
44
+ rows=probe_rows(6247,0,8)
45
+ x,y=x[rows],y[rows]
46
+ # RoPE values are frozen position constants and follow the checkpoint's upstream formula.
47
+ with patch.object(neox,"eager_attention_forward",dtype_attention):
48
+ with torch.no_grad():
49
+ logits=logits_of(model,x)
50
+ nll=token_loss(logits,y).item()
51
+ logit_gap=(logits-torch.cat([logits_of(model,t[None,:]) for t in x])).abs().max().item()
52
+ del logits
53
+ started=time.perf_counter()
54
+ value,gradient=two_window_third_gradient(model,parameters,x,y,*signs)
55
+ flat=torch.cat([p.detach().flatten().cpu() for p in gradient])
56
+ elapsed=time.perf_counter()-started
57
+ directory=storage/"diagnostics"
58
+ directory.mkdir(parents=True,exist_ok=True)
59
+ save_file({"gradient":flat},str(directory/f"pythia-reference-{device.type}.safetensors"))
60
+ h=hashlib.sha256()
61
+ for sign in (*signs[0],*signs[1]): h.update(sign.float().cpu().contiguous().numpy().tobytes())
62
+ result={"timestamp":time_now(),"device":str(device),"dtype":"float64", "initial_trainable_sha256":initial,
63
+ "probes_sha256":h.hexdigest(),"two_window_cross_entropy":nll,
64
+ "max_logit_abs_difference":logit_gap,"penalty":value.item(),"gradient_norm":flat.norm().item(),
65
+ "finite":bool(flat.isfinite().all()),"probe_seconds":elapsed}
66
+ write_json(project/"results"/"verification"/f"pythia-fp64-{device.type}.json",result)
67
+ print(result,flush=True)
68
+ return result