Skip to content
kgramaPublic
forked from ggml-org/llama.cpp

About

LNS LLM inference in C/C++

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

 
 

Latest commit

 

History

12,970 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LogLLaMA

Integer LLM inference and training in a Tribonacci logarithmic format, on llama.cpp

License: PolyForm Noncommercial 1.0.0 Rocq: 35 modules

paper / Rocq spec / kernels / ptlf-train / results / llama.cpp

Description

PTLF16 (Pure Tribonacci Logarithmic Float, 16 bit) is a number format for LLM inference and training on top of llama.cpp / ggml. One file, model-PTLF16.gguf, is a full inference format: it is served at 16 bits or at any width from 8 down to 3 bits per weight, chosen at load time, with integer arithmetic inside the model graph. The same file can also be trained in place with ptlf-train and served again without a quantization pass.

Qwen3-14B served from one file gave KL divergence against F16 of 0.0164, 0.0136, 0.0236, and 0.524 at 16, 8, 6, and 4 bits on a 63-token sample. On an NVIDIA Tesla T4 ($0.526/hr), training to a held-out loss target of -0.1 nats reached the target in 3 of 3 seeds on Qwen3-0.6B (mean training cost $0.0143) and Qwen3-1.7B ($0.0228), and in 0 of 3 seeds on SmolLM2-1.7B within 12 steps. On an 8-core Sapphire Rapids CPU, AMX-INT8 training of Llama-3.1-8B-Instruct took 110.8 s per 64-token step.

Against a standard mixed-precision process, computed and not measured, the workflow holds 4.1 bytes of training state per parameter against 16 to 18 and stores one 16 GB file for an 8B model against five files totalling 68 GB. Its measured cost per training token is 59 to 1,500 times the computed lower bound of the standard process; mixed-precision training of the 1.7B and 8B models does not fit in the memory of the instances used here. All measurements use small samples; see Limitations.

Important

The arithmetic primitives, overflow bounds, SIMD/CUDA instruction orderings, architectural operators, and training kernels are specified in Rocq (Coq) across 35 modules in docs/ptlf-spec/ with zero Admitted lemmas. The five generated headers (ptlf_lemmas.h, ptlf_simd.h, ptlf_graph.h, ptlf_train.h, ptlf_cuda.cuh) are emitted from a typed pure-integer Rocq C-AST (docs/ptlf-spec/ptlf_cast.v).

Quick start

1. Build

cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --target llama-perplexity llama-cli ptlf-train -j

2. Convert an F16 / BF16 GGUF to PTLF16

PTLF16 is registered as GGMLQuantizationType.PTLF16 = 79 in gguf-py/gguf/constants.py and GGML_TYPE_PTLF16 = 79 in ggml/include/ggml.h.

python3 scripts/f16_to_ptlf16.py /path/to/model-F16.gguf /path/to/model-PTLF16.gguf

F16, BF16, and F32 tensors are encoded to PTLF16; other tensor types and all metadata are copied unchanged.

3. Run inference (p16, m7 to m2)

A PTLF16 GGUF is loaded by the standard llama.cpp tools. No training step is needed to use it for inference.

# Chat with a PTLF16 model at 8 bits per weight
PTLF_BPW=7 ./build/bin/llama-cli -m /path/to/model-PTLF16.gguf -t 8

Select the weight format at load time with the PTLF_BPW environment variable. On AMX CPUs, use one thread per physical core.

PTLF_BPW=0   # or unset: p16 (16-bit)
PTLF_BPW=7   # m7 (8-bit)
PTLF_BPW=6   # m6 (7-bit)
PTLF_BPW=5   # m5 (6-bit)
PTLF_BPW=4   # m4 (5-bit)
PTLF_BPW=3   # m3 (4-bit)
PTLF_BPW=2   # m2 (3-bit)

Positive values are clamped to 2..7 and apply to the standard 2D linear weights. Embedding, output, MoE, AltUp, LoRA, 1D, and 3D tensors are packed at m7 for every positive value (ptlf_select_bpw in ggml/src/ptlf/ptlf_lemmas.h). The benchmarks below cover p16, m7, m5, and m3 only.

# Native PTLF16 (p16)
./build/bin/llama-perplexity \
  -m /path/to/model-PTLF16.gguf \
  -f /path/to/wiki.test.raw \
  --chunks 1 -c 128 -t 8

# Rotated m7 (8-bit)
PTLF_BPW=7 ./build/bin/llama-perplexity \
  -m /path/to/model-PTLF16.gguf \
  -f /path/to/wiki.test.raw \
  --chunks 1 -c 128 -t 8

# Rotated m5 (6-bit) and m3 (4-bit)
PTLF_BPW=5 ./build/bin/llama-perplexity -m /path/to/model-PTLF16.gguf -f /path/to/wiki.test.raw --chunks 1 -c 128 -t 8
PTLF_BPW=3 ./build/bin/llama-perplexity -m /path/to/model-PTLF16.gguf -f /path/to/wiki.test.raw --chunks 1 -c 128 -t 8

4. Run integer training (ptlf-train)

./build/bin/ptlf-train \
  -m /path/to/model-PTLF16.gguf \
  -f /path/to/c4_train.txt \
  --eval-file /path/to/c4_val.txt \
  --eval-every 1 --eval-batches 2 \
  --steps 3 --seq 64 --lr 1e-5 --opt adamw \
  --target-loss 2.40 --mllog \
  --save-out /path/to/trained-PTLF16.gguf -t 8

Switches:

--opt adamw|sgd        Hadamard m7-state AdamW (default) or SGD with momentum
--lr <float>           learning rate (0 enables eval-only mode)
--wd <float>           weight decay
--steps <N>            number of steps
--seq <N>              sequence length
--repeat               fixed-window mode
--seed <N>             seed
--eval-file <path>     held-out token stream
--eval-every <N>       evaluate every N steps
--eval-batches <N>     held-out batches per evaluation
--target-loss <float>  stop when held-out loss is at or below this value
--mllog                emit :::MLLOG events
--save-out <path>      write the trained PTLF16 GGUF checkpoint
-t <N>                 OpenMP thread count (physical core count for AMX-INT8)

5. Verify Rocq proofs and regenerate C headers

sh docs/ptlf-spec/emit_lemmas.sh

This compiles the 35 Rocq modules in docs/ptlf-spec/ and regenerates:

  • ggml/src/ptlf/ptlf_lemmas.h & ggml/src/ptlf/ptlf_lemmas_tv.h
  • ggml/src/ptlf/ptlf_simd.h
  • ggml/src/ptlf/ptlf_graph.h
  • ggml/src/ptlf/ptlf_train.h

Workflow

The standard process keeps FP32 training checkpoints, an F16 / BF16 export, and one post-training quantized file per serving width (Q8_0, Q6_K, Q4_K_M, optionally with imatrix calibration). The PTLF workflow keeps one file, model-PTLF16.gguf:

  1. Convert. Encode an F16 / BF16 GGUF to model-PTLF16.gguf with scripts/f16_to_ptlf16.py. One deterministic pass, no calibration data.
  2. Train. Run full-parameter integer training with ptlf-train on model-PTLF16.gguf (Intel AMX-INT8 or NVIDIA CUDA INT8) and export a PTLF16 GGUF checkpoint. There are no FP32 master weights and no loss scaling.
  3. Serve. Load the same file at p16 (16-bit) or at any of m7 (8-bit) down to m2 (3-bit). Low-bit formats are packed from the PTLF16 weights at load time.

Training state is 4.125 bytes per parameter for 2D projections (2 for the PTLF16 weight, 1 + 2/32 for each of the two m7 AdamW moments), plus one reused gradient buffer. See Comparison with the Standard Process for the standard figures and for cost per token.

Formats

In a Logarithmic Number System (LNS), multiplication and division are integer addition and subtraction of log codes, and sqrt / rsqrt are single-bit shifts. PTLF16 uses the Tribonacci constant T = 1.839286755... (the real root of T^3 = T^2 + T + 1) as its base:

  • Bit layout (PTLF16 / p16): 16-bit unsigned integer (1 sign bit + 15 magnitude bits). Magnitude r = 0 is exact zero; any non-zero code represents (-1)^s * T^((r - 16384) / 256).
  • Rotated low-bit formats (m7 down to m2): 32-element blocks rotated by a sign-masked Walsh-Hadamard transform and quantized to 2..7 magnitude bits + 1 sign bit with one PTLF16 block scale, for AVX512-VNNI, AMX-INT8, CUDA __dp4a, and INT8 Tensor Cores.
Format Relative step Max rel. rounding error Positive range
BF16 (7-bit mantissa) 0.781% (2^-7) 0.391% [1.18e-38, 3.39e+38]
PTLF16 (256 codes per T) 0.238% (T^(1/256) - 1) 0.119% [1.16e-17, 8.64e+16]
FP16 (10-bit mantissa) 0.098% (2^-10) 0.049% [6.10e-5, 6.55e+4]

All PTLF16 operations saturate; no code represents NaN or infinity.

What's implemented

  • Inference: a PTLF16 GGUF is a complete inference format. It loads through libllama (src/ptlf_load.cpp) and runs at p16 or any of m7 to m2 from the same file, with activations, norms, attention, and the residual stream in PTLF16 at every width.
  • Integer execution: zero float, zero double, and zero int64_t in ggml/src/ptlf/ptlf_lemmas.h, ptlf_simd.h, ptlf_train.h, and ptlf_cuda.cuh. Three API boundary codecs (ptlf16_decode_f32_once, ptlf_encode_f64, ptlf_graph_decode_f32_op) in ggml/src/ptlf/ptlf_graph.h interface with the llama.cpp host API.
  • Formal verification in Rocq: 35 modules, zero Admitted lemmas in docs/ptlf-spec/. A typed pure-integer C-AST (docs/ptlf-spec/ptlf_cast.v) emits the five headers with machine-checked decls_pure_int, decls_no_float, and ceval_fn semantic equivalence proofs.
  • CPU kernels: AMX-INT8 tiles with a 16-wide AVX-512 register-arithmetic epilogue (mant_poly3 and 4-bit inv_q in place of LUT gathers), and an AVX512-VNNI path.
  • CUDA kernels (ggml/src/ptlf/ptlf_cuda.cuh): signed __dp4a GEMV/GEMM, 16x16x32 INT8 Tensor Core WMMA GEMM, warp-parallel RMSNorm/Softmax, tiled online-softmax attention, and GPU m7 AdamW, selected at runtime with PTLF_CUDA=1.
  • RoPE: 32-bit Binary Angular Measurement (BAM) partial RoPE (NEOX, MROPE, IMROPE) with zero float and zero 64-bit arithmetic.
  • Hadamard sign mask 0x87777888U: 16 set bits, WH[0] = 0, spectrum of 16 zeros and 16 coefficients of magnitude 8.
  • m3: direct int8 storage in AMX panel layout with cross-block Top-4 m7 residual correction.
  • Tensor-presence dispatch: zero LLM_ARCH_* branches in src/ptlf_load.cpp and ptlf_graph.h. Covers dense GQA, QK-norm, Q-gate, attention sinks, sparse MoE, Gated DeltaNet, AltUp / Laurel / PLE / Dual-FFN, GeGLU, logit softcapping, and an integer radix KV cache.
  • Training (ptlf-train): float-free and int64_t-free training in tools/ptlf-train/ptlf-train.cpp with AMX-INT8 forward/backward (dX / dW), Hadamard-basis m7-state AdamW and SGD, held-out evaluation, a stopping target, and MLPerf-style :::MLLOG output.

Benchmarks

CPU: AWS EC2 r7i.4xlarge (8 physical Intel Xeon Sapphire Rapids cores / 16 vCPUs, AVX-512BW + AVX512-VNNI + AMX-INT8, 128 GB RAM). GPU: AWS EC2 g4dn.xlarge (NVIDIA Tesla T4, 15,360 MiB VRAM, $0.526/hr on demand). Raw logs are in docs/ptlf-paper/results/.

Inference accuracy and latency (WikiText-2, 63 scored tokens)

PTLF_BPW=<0|7|5|3> ./build/bin/llama-perplexity -m model-PTLF16.gguf \
  -f wiki.test.raw --chunks 1 -c 128 -t <threads>

KLD and top-1 are against the F16 logits of the same model. Every row is one run. Runs: A = AVX512-VNNI build, 16 threads (bench_master.log); B = AMX-INT8 build, 8 threads for m7/m5 and 16 threads for p16/m3 (bench_full.log); C = bench_verify.log; D = mlperf_train.log.

Model Format Run PPL KLD vs F16 Top-1 (%) Time/pass (s)
Qwen3-8B (dense, 8B) F16 B 5.0010 +/- 1.74 - - 2.63
p16 A 5.0566 +/- 1.79 0.00541 +/- 0.00164 95.24 -
m7 A 5.0744 +/- 1.80 0.01817 +/- 0.00533 90.48 27.88
m5 A 4.8099 +/- 1.68 0.03435 +/- 0.00991 92.06 27.96
m3 A 7.8107 +/- 3.11 0.41318 +/- 0.11119 77.78 69.30
p16 B 6.0212 +/- 1.84 0.21171 +/- 0.01715 88.89 16.19
m7 B 6.0001 +/- 1.85 0.20186 +/- 0.01512 92.06 9.01
m5 B 5.5580 +/- 1.67 0.18239 +/- 0.01401 93.65 9.00
m3 B 8.7855 +/- 2.93 0.57614 +/- 0.08385 80.95 61.24
Qwen3-14B (dense, 14.8B) F16 B 4.8569 +/- 1.64 - - 5.22
p16 A 4.6900 +/- 1.58 0.01640 +/- 0.00299 95.24 28.71
m7 A 4.7086 +/- 1.60 0.01361 +/- 0.00340 96.83 49.25
m5 A 4.5269 +/- 1.46 0.02356 +/- 0.00552 95.24 49.51
m3 A 7.6981 +/- 2.89 0.52439 +/- 0.14783 71.43 131.98
p16 B 4.9641 +/- 1.45 0.12743 +/- 0.01179 95.24 29.80
m7 B 5.0084 +/- 1.49 0.12200 +/- 0.01144 96.83 15.38
m5 B 4.9060 +/- 1.41 0.13539 +/- 0.01270 95.24 15.47
m3 B 8.1287 +/- 2.72 0.60430 +/- 0.13996 71.43 16.93
Llama-3.1-8B-Instruct (dense, 8B) F16 B 5.7266 +/- 1.59 - - 2.68
p16 D 6.7226 +/- 1.74 0.10550 +/- 0.00665 93.65 15.55
m7 D 6.5966 +/- 1.70 0.09985 +/- 0.00619 92.06 8.70
m5 D 6.6686 +/- 1.71 0.12921 +/- 0.01081 93.65 8.73
m3 B 12.9473 +/- 3.60 0.82310 +/- 0.10186 71.43 62.58
Qwen3.8-27B (Gated DeltaNet, 27B) F16 B 4.5416 +/- 1.25 - - 10.16
p16 C 9.7382 +/- 3.15 0.68100 +/- 0.09257 74.60 57.01
m7 C 10.0602 +/- 3.28 0.69316 +/- 0.09421 73.02 33.28
m3 B 24.8986 +/- 9.63 1.68777 +/- 0.19594 49.21 35.49
gpt-oss-20b (MoE, 21B) F16 C 213.55 +/- 83.6 - - 1.84
p16 C 122.18 +/- 47.4 0.20272 +/- 0.01984 60.32 71.55
m7 C 156.68 +/- 59.8 0.25234 +/- 0.02778 50.79 12.00

On both Qwen models, run B records higher KLD than run A at every width, including p16. The cause has not been isolated. Gemma-4-26B-A4B-it is not in the table: the upstream BF16 baseline gives PPL 91,701, and PTLF m7 / m5 give KLD 37.1 / 34.7 against it with 0% top-1 agreement (time per pass 2.24 s for BF16, 3.97 s for m7 / m5).

AMX-INT8 training: Llama-3.1-8B-Instruct on r7i.4xlarge

Non-repeating C4.

./build/bin/ptlf-train -m Llama-3.1-8B-Instruct-PTLF16.gguf -f c4_train.txt \
  --eval-file c4_val.txt --eval-every 1 --eval-batches 2 \
  --steps 3 --seq 64 --lr 1e-5 --opt adamw --mllog -t 8

Step time excludes the 25.9 s evaluation. Train loss is on one 64-token sequence per step; eval loss is on 128 held-out tokens.

Step Train loss (nats) Loss code Eval loss (nats) Step time (s)
0 - - 2.5184 -
1 3.3830 16896 2.5183 101.1
2 3.1573 16867 2.4797 115.0
3 3.3669 16894 2.4621 116.4

Mean step time is 110.8 s. A second run with 16 threads, learning rate 1e-4, and 4 eval batches printed step-1 train loss 3.3749 (code 16895) and was terminated after step 1.

Training cost to a loss target on NVIDIA Tesla T4

Full-parameter ptlf-train with all kernels on the T4 (Y, dX, dW, m7 AdamW), non-repeating C4, learning rate 1e-5, AdamW, one 64-token sequence per step, evaluation every 3 steps on 4 held-out batches. The target is the initial held-out loss minus 0.1 nats. Step limit: 15 for Qwen3-0.6B, 12 for the 1.7B models. Training time is the trainer's elapsed time minus evaluation time, with every evaluation counted at the duration of the step-0 evaluation (15.2 to 15.3 s for Qwen3-0.6B, 34.5 to 34.7 s for Qwen3-1.7B, 33.7 to 33.8 s for SmolLM2-1.7B); later evaluations are not timed separately in the logs. Model load time is not included: the timer starts after the model is loaded. Cost is training hours times $0.526/hr, and energy is mean power times training time. The switches below are reconstructed from the configuration recorded in the result files.

PTLF_CUDA=1 ./build/bin/ptlf-train -m model-PTLF16.gguf -f c4_train.txt \
  --eval-file c4_val.txt --eval-every 3 --eval-batches 4 \
  --steps <15|12> --seq 64 --lr 1e-5 --opt adamw \
  --target-loss <initial loss - 0.1> --seed <42|137|2026> \
  --mllog --save-out trained-PTLF16.gguf
Model (target) Seed Steps Tokens Time (s) Power (W) Energy (kWh) Initial loss Final loss Target reached Cost (USD) USD / Mtok
Qwen3-0.6B (<= 4.3639) 42 6 384 117.83 32.77 0.00107 4.4639 4.2962 yes 0.0172 44.83
137 3 192 59.05 32.52 0.00053 4.4639 4.3624 yes 0.0086 44.94
2026 6 384 117.69 33.08 0.00108 4.4639 4.2947 yes 0.0172 44.78
mean 5 320 98.19 32.79 0.00090 4.4639 4.3178 3 / 3 0.0143 44.85
Qwen3-1.7B (<= 3.8367) 42 3 192 117.92 32.40 0.00106 3.9367 3.8322 yes 0.0172 89.74
137 6 384 232.48 32.83 0.00212 3.9367 3.8150 yes 0.0340 88.46
2026 3 192 116.95 32.29 0.00105 3.9367 3.8267 yes 0.0171 89.00
mean 4 256 155.78 32.51 0.00141 3.9367 3.8246 3 / 3 0.0228 89.06
SmolLM2-1.7B (<= 2.7769) 42 12 768 438.60 34.38 0.00419 2.8769 2.8599 no 0.0641 83.44
137 12 768 439.67 33.30 0.00407 2.8769 2.8648 no 0.0642 83.65
2026 12 768 438.34 34.17 0.00416 2.8769 2.8585 no 0.0640 83.39
mean 12 768 438.87 33.95 0.00414 2.8769 2.8611 0 / 3 0.0641 83.49

Held-out loss decrease from the initial evaluation to the last one (learning rate 1e-5, one 64-token sequence per step; training time excludes evaluation and model load).

Model Hardware Seed Steps Loss decrease (nats) Nats / step Nats / 1,000 tokens Nats / 1,000 s
Qwen3-0.6B T4 42 6 0.1677 0.0279 0.437 1.423
Qwen3-0.6B T4 137 3 0.1015 0.0338 0.529 1.719
Qwen3-0.6B T4 2026 6 0.1692 0.0282 0.441 1.438
Qwen3-1.7B T4 42 3 0.1045 0.0348 0.544 0.886
Qwen3-1.7B T4 137 6 0.1217 0.0203 0.317 0.523
Qwen3-1.7B T4 2026 3 0.1100 0.0367 0.573 0.941
SmolLM2-1.7B T4 42 12 0.0170 0.0014 0.022 0.039
SmolLM2-1.7B T4 137 12 0.0121 0.0010 0.016 0.028
SmolLM2-1.7B T4 2026 12 0.0184 0.0015 0.024 0.042
Llama-3.1-8B r7i.4xlarge - 3 0.0563 0.0188 0.293 0.169

Held-out loss decrease per optimizer step next to two published standard-process runs. The Qwen-2.5 losses are read from Figure 8 of Hogan et al. 2025 and are approximate; that run uses 4 GPUs at batch size 1 with gradient accumulation 8, 4096-token chunks of Q-language text, and 10 warmup steps. The SmolLM2-1.7B card does not state the dataset, the sequence length, or whether all parameters are trained, and its first logged evaluation is at step 200. Data, starting loss, and held-out sets differ between rows; no standard-process run was made on the models and data used here.

Run Model Optimizer, learning rate Sequences / step Steps in interval Loss at start Loss at end Nats / step
Published (Hogan et al.) Qwen-2.5 1.5B Adam, 1e-5 32 0 to 200 ~2.12 ~1.93 ~0.0010
Published (Hogan et al.) Qwen-2.5 3B Adam, 1e-5 32 0 to 200 ~2.00 ~1.82 ~0.0009
Published (model card) SmolLM2-1.7B AdamW, 5e-6 256 200 to 400 1.2704 1.0435 0.0011
ptlf-train Qwen3-0.6B m7 AdamW, 1e-5 1 0 to 3 or 6 4.4639 4.2947 to 4.3624 0.028 to 0.034
ptlf-train Qwen3-1.7B m7 AdamW, 1e-5 1 0 to 3 or 6 3.9367 3.8150 to 3.8322 0.020 to 0.037
ptlf-train SmolLM2-1.7B m7 AdamW, 1e-5 1 0 to 12 2.8769 2.8585 to 2.8648 0.0010 to 0.0015
ptlf-train Llama-3.1-8B m7 AdamW, 1e-5 1 0 to 3 2.5184 2.4621 0.019

The ratio of the ptlf-train rate to the published rate is about 20 to 40 for the Qwen rows and about 0.9 to 1.4 for SmolLM2-1.7B, the one model present on both sides. A ptlf-train step processes 64 tokens; a step of the published Qwen-2.5 runs processes about 131,000 (32 chunks of 4,096). The starting losses differ (3.94 and 4.46 nats against about 2.0 to 2.1), and the two Qwen ptlf-train runs end at the first evaluation at or below the target.

Precision of the reported losses. The trainer's arithmetic is exact integer arithmetic, so a loss on a given set of tokens carries no numerical error: the three seeds of each model log the same initial loss (4.4639, 3.9367, and 2.8769). Two other quantities bound how finely a loss change can be read:

  • Code step. Each batch loss is a PTLF16 code with a relative step of 0.238%, which is 0.007 nats at a loss of 2.88, 0.009 nats at 3.94, and 0.011 nats at 4.46. The reported loss is the mean of four batch losses.
  • Token sample. The loss is computed on 256 held-out tokens and a different sample of tokens gives a different value. llama-perplexity on a 256-token context of the same held-out file reports a standard error across tokens of 5.49 on a perplexity of 24.30 (Qwen3-0.6B), 3.02 on 14.22 (Qwen3-1.7B), and 1.51 on 9.31 (SmolLM2-1.7B) at m7, which is 0.23, 0.21, and 0.16 nats.

The measured loss decreases are 0.10 to 0.17 nats on the Qwen models and 0.012 to 0.018 nats on SmolLM2-1.7B.

Each saved checkpoint was then loaded by llama-perplexity at m7 and m3 and evaluated on held-out c4_val.txt.

PTLF_CUDA=1 PTLF_BPW=<7|3> ./build/bin/llama-perplexity -m trained-PTLF16.gguf \
  -f c4_val.txt -c 256 --chunks 1

Values are PPL +/- standard error; baseline is the converted file before training. In each of the 18 checkpoint cells the difference from baseline is smaller than the standard error.

Model Width Baseline Seed 42 Seed 137 Seed 2026
Qwen3-0.6B m7 24.3044 +/- 5.49 24.9933 +/- 5.47 24.0753 +/- 5.34 24.3307 +/- 5.23
m3 117.3840 +/- 34.20 121.4462 +/- 35.12 124.4418 +/- 35.70 114.8124 +/- 33.53
Qwen3-1.7B m7 14.2246 +/- 3.02 14.3946 +/- 2.97 14.7923 +/- 3.01 14.0506 +/- 2.92
m3 48.9864 +/- 13.26 48.2222 +/- 12.86 47.2628 +/- 11.76 54.5731 +/- 15.43
SmolLM2-1.7B m7 9.3145 +/- 1.51 9.2006 +/- 1.50 9.2071 +/- 1.49 9.2129 +/- 1.51
m3 70.4252 +/- 17.07 69.1673 +/- 17.24 66.2754 +/- 16.02 79.7567 +/- 20.69

Comparison with the standard process (computed)

No standard-process run was made. Standard figures are computed from parameter counts, vendor peak throughput, and AWS us-east-1 Linux on-demand list prices (December 2026). Parameter counts are computed from the published layer dimensions with tied embeddings counted once.

Stored artifacts for one 8B model served at 16, 8, 6, and 4 bits: the standard process stores 5 files totalling 68 GB (FP32 32 GB, F16 16 GB, Q8_0 8.5 GB, Q6_K 6.6 GB, Q4_K_M 4.9 GB); the workflow stores 1 file of 16 GB. Packing is paid at load: on Llama-3.1-8B-Instruct with 8 threads, the time from process start to thread-pool start was 0.5 s at p16 and 87.8 s at m7.

Training state in GB (weights, gradients, AdamW moments; activations excluded):

Model, parameters FP32 (16 B) Mixed (18 B) BF16 (8 B) PTLF16 + m7 (4.125 B) Smallest instance for mixed precision ptlf-train instance used
Qwen3-0.6B, 0.596e9 9.5 10.7 4.8 2.5 g4dn.xlarge, T4 16 GB, $0.526/hr g4dn.xlarge, $0.526/hr
Qwen3-1.7B, 1.721e9 27.5 31.0 13.8 7.1 g6e.xlarge, L40S 48 GB, $1.861/hr g4dn.xlarge, $0.526/hr
SmolLM2-1.7B, 1.711e9 27.4 30.8 13.7 7.1 g6e.xlarge, L40S 48 GB, $1.861/hr g4dn.xlarge, $0.526/hr
Llama-3.1-8B, 8.030e9 128.5 144.5 64.2 33.1 r7i.8xlarge, 256 GB RAM, $2.117/hr r7i.4xlarge, 128 GB RAM, $1.058/hr

Whether training fits in device memory at one 64-token sequence per step. Values are computed state plus activations in GB. Activations are counted per layer as 8*s*d + 4*s*d_ff + h*s^2 elements plus 2*s*V for logits and probabilities, at 4 bytes for FP32 and 2 bytes otherwise. The PTLF16 column also includes the gradient buffer (2 bytes times the largest tensor, grad_scratch in ptlf_train.h). "no" means the total exceeds the memory of the device. Framework, driver, and operating-system memory are not counted.

Device, memory Model FP32 Mixed BF16 PTLF16 + m7
T4, 16.1 GB Qwen3-0.6B fits (9.8) fits (10.8) fits (4.9) fits (2.9), run completed
T4, 16.1 GB Qwen3-1.7B no (27.9) no (31.2) fits (14.0) fits (7.9), run completed
T4, 16.1 GB SmolLM2-1.7B no (27.7) no (31.0) fits (13.9) fits (7.4), run completed
32 GiB host, 34.4 GB Llama-3.1-8B no (129.3) no (145.0) no (64.7) no (34.6)
128 GiB host, 137.4 GB Llama-3.1-8B fits (129.3) no (145.0) fits (64.7) fits (34.6), run completed

With the same count, all-BF16 training of Qwen3-1.7B exceeds the T4's 16.1 GB above about 660 tokens per step. The 8B ptlf-train total of 34.6 GB is 33.1 state, 1.05 gradient buffer, and 0.41 activations.

Cost per million training tokens at one 64-token sequence per step. The last column states whether mixed-precision training fits in the memory of the instance ptlf-train used; where it does not, the standard bound is for a larger instance and the ratio compares two different instances. The standard columns are lower bounds: 6N FLOPs per token at 100% of single-precision peak (T4 8.1 TFLOPS and L40S 91.6 TFLOPS from the NVIDIA datasheets; r7i.8xlarge 3.28 TFLOPS from 16 cores, 3.2 GHz all-core turbo, 16 lanes, and an assumed two AVX-512 FMA units per core). The ptlf-train columns are measured; all figures exclude evaluation time and model load.

Model Standard instance FLOPs / step s / step USD / Mtok ptlf-train instance s / step USD / Mtok Ratio Mixed precision on ptlf-train instance
Qwen3-0.6B g4dn.xlarge 2.29e11 0.028 0.065 g4dn.xlarge 19.6 to 19.7 44.85 700 fits (10.8 of 16.1 GB)
Qwen3-1.7B g6e.xlarge 6.61e11 0.0072 0.058 g4dn.xlarge 38.7 to 39.3 89.06 1,500 does not fit (31.2 of 16.1 GB)
SmolLM2-1.7B g6e.xlarge 6.57e11 0.0072 0.058 g4dn.xlarge 36.5 to 36.6 83.49 1,400 does not fit (31.0 of 16.1 GB)
Llama-3.1-8B r7i.8xlarge 3.08e12 0.94 8.6 r7i.4xlarge 110.8 509 59 does not fit (145.0 of 137.4 GB)

The datasheet mixed-precision peaks are 65 TFLOPS (T4) and 362 TFLOPS (L40S, FP16 dense); using them would divide the two GPU bounds by 8.0 and 4.0.

Limitations

  • Sample sizes: inference rows score 63 tokens; training runs process 192 to 768 tokens and evaluate on 128 or 256.
  • Run A versus run B KLD on the Qwen models is unexplained; the AMX latency figures come from run B.
  • In the benchmark runs, ptlf-train exited with a segmentation fault on gpt-oss-20b, Qwen3.8-27B, and Gemma-4-26B-A4B-it. All training results are on dense models.
  • ptlf-train has no learning-rate warmup or gradient clipping. In a 10-step run with 8-token sequences and learning rate 3e-5 on Llama-3.1-8B-Instruct, held-out loss rose from 6.2779 to 8.2361 nats.
  • Llama-3.1 per-dimension rope_freqs, gpt-oss-20b sliding-window attention and YaRN scaling are not implemented. The Qwen3.8-27B rows predate the p16_ln divisor of 18922 in the DeltaNet decay gate.

Scope

The Rocq proofs cover integer arithmetic: value ranges, saturation, instruction order, and indexing. They do not cover the learned weights, the accuracy of a converted or trained model, or host-side code outside the generated headers. Running a model in PTLF16 arithmetic does not explain why its weights prefer a token; it specifies how the computation is carried out.

Documentation

Tools

Development

License

About

LNS LLM inference in C/C++

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages