Register full-checkpoint precision audit before reference measurements
Browse filesFiles changed (6)
123456# Study progressUpdated 2026-11-25T07:34:55+00:00.13 training/control records and 0 final evaluations are complete. This is 10.8% of 120 planned model milestones.123456# Study progressUpdated 2026-11-25T07:39:12+00:00.13 training/control records and 0 final evaluations are complete. This is 10.8% of 120 planned model milestones.
8 unmodified lines910118 unmodified linesThe 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)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)8 unmodified lines910111213141516178 unmodified linesThe 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)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)## Full-checkpoint precision auditThe 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)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)
43 unmodified lines44454647484924 unmodified lines74757677787943 unmodified linessub.add_argument("--device",default="cuda")if action=="verify":sub.add_argument("--pretrained",action="store_true",help="Also compare a full joint derivative on the prepared adapter training corpus")sub.add_argument("--device",default="cuda",help="Device for the optional full pretrained cross-check")if action=="train":sub.add_argument("--method",choices=(*METHODS,"unigram","initial"),required=True)24 unmodified linesfrom .probe_check import verify_pretrainedfrom .records import setup_deviceverify_pretrained(project,setup_device(args.device))returnif args.action=="dashboard":return dashboard(project,args.port)43 unmodified lines4445464748495024 unmodified lines7576777879808182838443 unmodified linessub.add_argument("--device",default="cuda")if action=="verify":sub.add_argument("--pretrained",action="store_true",help="Also compare a full joint derivative on the prepared adapter training corpus")sub.add_argument("--reference",action="store_true",help="Compute the FP64 pretrained reference using the original CUDA signs")sub.add_argument("--device",default="cuda",help="Device for the optional full pretrained cross-check")if action=="train":sub.add_argument("--method",choices=(*METHODS,"unigram","initial"),required=True)24 unmodified linesfrom .probe_check import verify_pretrainedfrom .records import setup_deviceverify_pretrained(project,setup_device(args.device))if args.reference:from .precision import reference_gradientfrom .records import setup_devicereference_gradient(project,setup_device(args.device))returnif args.action=="dashboard":return dashboard(project,args.port)
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768"""Independent, high-precision reference for the first real adapter calibration probe."""
import hashlibimport timefrom unittest.mock import patch
import torch
from .models import build_model, logits_of, token_loss, trainable_digestfrom .objectives import two_window_third_gradientfrom .penalties import random_signsfrom .records import storage_root, time_now, write_jsonfrom .windows import TrainingWindows, generator, probe_rows
def dtype_attention(module,query,key,value,attention_mask,scaling,dropout=0.0,**kwargs): """The upstream eager formula with softmax retaining the study tensor's precision.
https://github.com/huggingface/transformers/blob/main/src/transformers/models/gpt_neox/modeling_gpt_neox.py """ scores = (query @ key.transpose(-2,-1))*scaling if attention_mask is not None: scores = scores+attention_mask weights = torch.nn.functional.dropout(scores.softmax(-1),p=dropout,training=module.training) return (weights @ value).transpose(1,2).contiguous(),weights
def reference_gradient(project,device): """Generate the production CUDA signs and promote the same pretrained weights to FP64.""" from safetensors.torch import save_file from transformers.models.gpt_neox import modeling_gpt_neox as neox storage=storage_root(project) model=build_model("abstracts",0,device,storage).eval() initial=trainable_digest(model) parameters=tuple(p for p in model.parameters() if p.requires_grad) # Generate signs with the *same* device generator as the observed pilot, also for CPU AD. rng=generator(torch.device("cuda"),6247,0,827) shapes=tuple(torch.empty_like(p,device="cuda") for p in parameters) signs=[tuple(g.to(device=device,dtype=torch.float64) for g in random_signs(shapes,rng)) for _ in range(2)] del shapes,parameters model.double() parameters=tuple(p for p in model.parameters() if p.requires_grad) x,y=TrainingWindows(storage/"data"/"abstracts"/"train.bin",6247,8).get(0,device) rows=probe_rows(6247,0,8) x,y=x[rows],y[rows] # RoPE values are frozen position constants and follow the checkpoint's upstream formula. with patch.object(neox,"eager_attention_forward",dtype_attention): with torch.no_grad(): logits=logits_of(model,x) nll=token_loss(logits,y).item() logit_gap=(logits-torch.cat([logits_of(model,t[None,:]) for t in x])).abs().max().item() del logits started=time.perf_counter() value,gradient=two_window_third_gradient(model,parameters,x,y,*signs) flat=torch.cat([p.detach().flatten().cpu() for p in gradient]) elapsed=time.perf_counter()-started directory=storage/"diagnostics" directory.mkdir(parents=True,exist_ok=True) save_file({"gradient":flat},str(directory/f"pythia-reference-{device.type}.safetensors")) h=hashlib.sha256() for sign in (*signs[0],*signs[1]): h.update(sign.float().cpu().contiguous().numpy().tobytes()) result={"timestamp":time_now(),"device":str(device),"dtype":"float64", "initial_trainable_sha256":initial, "probes_sha256":h.hexdigest(),"two_window_cross_entropy":nll, "max_logit_abs_difference":logit_gap,"penalty":value.item(),"gradient_norm":flat.norm().item(), "finite":bool(flat.isfinite().all()),"probe_seconds":elapsed} write_json(project/"results"/"verification"/f"pythia-fp64-{device.type}.json",result) print(result,flush=True) return resultresearch/docs/study.json
research/reports/paper.pdf
research/reports/progress.md+1-1
research/reports/reviews/adapter-verification.md+6
research/src/thirdloss/cli.py+5
research/src/thirdloss/precision.pyAdded+68