← phi · docs

Measurements

What the pruning, the quantization and the checks did when measured. Every figure here is copied from a result file in ezexe/p4-phi-experiments, which holds the scripts that wrote them, and each section names its file, its script and, where GitHub Actions ran it, the run.

simulatedexact over the levels storeduniform over every level

Single-digit flips the minimal-form check catches

measure_detection.py builds a synthetic weight tensor shaped 256 × 128 × 3 × 3 from four distributions, φ-masks it, quantizes it with FibonacciEncoder at 8 and 10 digits, and runs simulate_corruption with 200,000 flips. Beside the simulated share it prints the exact share over the levels stored and the share averaged over every level, which does not depend on the weights.

digitsweightsrmsesimulated±2σexactuniform

The share depends on where the weights fall on the grid: a 0 flipped to 1 is caught only beside a 1, and levels in the middle of the grid hold more 1s with gaps between them than the lowest levels do.

python scripts/measure_detection.py                     # synthetic weights
python scripts/measure_detection.py --models resnet18,resnet50

Result file: experiments/phi-prune/results/measure_detection.txt, a run with the defaults; script: scripts/measure_detection.py.

Per-tensor against per-channel quantization

probe_pretrained_encoding.py --strategies quantizes every convolution of torchvision's ImageNet ResNets at 10 digits, every weight of it, one strategy at a time, and compares 64 CIFAR-10 test images upscaled to 224 px against the dense model in fp32. agree is the share whose top-1 ImageNet class stays the dense model's; tensor is per-tensor quantization, channel is per-channel, encode_tensor(..., axis=0), and clipP clamps the weights to their 100 − P and P percentiles before quantizing per tensor.

One scale and one quantization offset for a whole tensor spread the levels so thin on the three V2 models that every probed image changed class; one per output channel kept 87.5% to 95.3% of them, and clipping did not come close. The probe does not prune.

Result file: experiments/phi-prune/results/probe-encoding-36066245824.txt, from Actions run 36066245824 of ezexe/phi; script: scripts/probe_pretrained_encoding.py.

fp16 and the quantized ResNets

The same script without --strategies compares four variants of each model, dense, dense quantized per tensor under a mask that keeps every weight, φ-pruned with no fine-tuning, and pruned and quantized, in fp32 and under CPU fp16 autocast on 32 of the 64 images. It prints the share of images with logits that are not finite, the agreement with the dense fp32 model, and the largest block output in fp32, against 65504, fp16's largest finite value.

modelvariantnonfinite32nonfinite16agree32agree16max|block|

No logit was non-finite and no block output came near 65504, so fp16 overflow is not why the quantized V2 models changed their answers. The pruned variants are not fine-tuned here, so their agreement is low by construction.

Result file: experiments/phi-prune/results/probe-encoding-36060638869.txt, from Actions run 36060638869; 10-digit codewords, 2 threads.

Fine-tune, prune and quantize ResNet-152 V2 on a CPU

finetune_encode_check.py runs the steps of the variant cells of quickstart_gpu.ipynb on a CPU: a dense fine-tune of ResNet-152 with its IMAGENET1K_V2 weights on 5000 CIFAR-10 training images at 128 px, φ-pruning of the convolutions, and a fine-tune with the masks held fixed. The pruned convolutions are then quantized per tensor and per channel. Each model is scored on 2000 test images in fp32 and on the first 256 under fp16 autocast.

runmodelfp32fp16non-finite fp16

Per-tensor quantization left the pruned model at 9.25% in both runs, near the 10% of one answer for every image on ten classes; per-channel quantization kept the pruned model's accuracy, 19.00% against 19.10% and 32.85% against 31.70%. No fp16 logit was non-finite.

Script: scripts/finetune_encode_check.py, on a GitHub runner with 2 threads.

φ against 2 of every 4 on a small transformer

transformer_check.py trains a character-level GPT with 4 layers, width 128 and MLP width 512 on the source of the Python standard library, on a CPU, for 1500 steps, then prunes MLP hidden neurons, so that a pruned neuron loses its row in fc1 and its column in fc2, and fine-tunes each arm for 300 steps with the mask held fixed. The figures are validation bits per character after fine-tuning, shown to four places from the JSON files. Lower is better.

armdensityseed 0seed 1seed 2

At half of the neurons the φ mask, whose densities were 0.4932 to 0.4946, finished above 2 of every 4 in every seed, by 0.0159 on average. The script's criterion K1, which keeps φ when that difference is below the pooled standard deviation over seeds, 0.0247, recorded it as surviving. Reordering the neurons before the φ mask gives exactly the heaviest half, as the script's docstring says, so phi-reorder and top-50 match to the last digit. At a quarter, φ and 1 of every 4 differ by 0.0006 on average, and K2, which asks φ to win by more than σ, recorded φ as killed. At three quarters, where phi-comp puts the constraint on the pruned neurons instead, K5 asked it to beat 3 of every 4 in every seed and recorded it as killed, since seed 1 went the other way.

Both files were written by an earlier version of the script, before it recorded which part it ran and which Python, platform and torch it ran on. The script makes the same parts again with:

python experiments/phi-register/scripts/transformer_check.py --part low --out low.json
python experiments/phi-register/scripts/transformer_check.py --part high --out high.json

Result files: low.json and high.json under experiments/phi-register/results/transformer-check; script: transformer_check.py. It trains on the standard library of the Python that runs it, so a run on another Python gives other figures. The same files hold the check's quantization part, which belongs to the register model, and its delta part is a run of its own, --part delta.