Ternary neural network

Also known as: ternary quantization

On this page 7

A ternary neural network is a neural network whose weights, and sometimes activations, are restricted to three values: minus one, zero and plus one, usually multiplied by a shared floating-point scaling factor. The technique, also called ternary quantization, stores each weight in about 1.58 bits of information and replaces most multiplications with additions, subtractions and skips.

In edge AI, ternary networks matter because memory size, memory bandwidth and energy per operation limit what phones, microcontrollers and embedded accelerators can run. Ternary weights offer a middle ground between binarized networks and 4-bit quantization: far smaller than 8-bit models, yet noticeably more accurate than networks with only two weight values, because the zero value adds sparsity and expressiveness.

How ternary quantization maps weights

Ternary quantization maps each full-precision weight to one of three levels using a threshold rule. Weights whose magnitude falls below a threshold become zero; larger positive weights become plus one and larger negative weights become minus one. A scaling factor, often computed per layer or per channel, restores the approximate magnitude of the original weights.

A widely used heuristic from early work on ternary weight networks sets the threshold to roughly 0.7 times the mean absolute weight of a layer, and sets the scale to the mean magnitude of the weights that remain nonzero. The more recent absmean scheme used in BitNet b1.58 divides weights by their mean absolute value and rounds to the nearest of the three levels.

The table below compares the main ternarization schemes and what each one learns or fixes.

SchemeThresholdScaling factorsNotes
Ternary weight networksFixed fraction of mean magnitudeOne symmetric scale per layerSimple, closed-form approximation
Trained ternary quantizationFixed fraction of maximum weightSeparate learned positive and negative scalesHigher accuracy, extra parameters
Absmean ternarizationImplicit through roundingMean absolute value per tensorUsed for training language models from scratch
Per-channel ternarizationComputed per output channelOne scale per channelBetter fit for convolutional layers
Common ternarization schemes

Training ternary networks

Ternary networks are almost always trained with quantization-aware training rather than converted after training, because rounding a pretrained model directly to three levels usually causes a large accuracy drop. During training, the network keeps latent full-precision weights, quantizes them in the forward pass and updates the latent copy in the backward pass.

Since the rounding function has a zero gradient almost everywhere, training relies on the straight-through estimator, which passes gradients through the quantizer as if it were the identity function within a clipping range. Practitioners often keep the first and last layers in higher precision, because these layers are small but disproportionately sensitive to quantization error.

Activation precision is a separate choice. Fully ternary networks also ternarize activations, but many practical systems pair ternary weights with 8-bit activations, which preserves accuracy while still eliminating weight multiplications.

Ternary networks compared with other low-bit formats

Ternary networks sit between binary and multi-bit integer formats on the trade-off curve of size, speed and accuracy. The comparison below assumes weight quantization with comparable training effort; exact accuracy depends strongly on architecture, task and model size.

FormatWeight valuesStorage per weightMain arithmeticTypical accuracy impact
FP16Continuous16 bitsFloating-point multiplyReference
INT8256 levels8 bitsInteger multiplyUsually negligible
4-bit16 levels4 bitsInteger multiply or lookupSmall with good calibration
TernaryThree levelsAbout 1.6 to 2 bitsAdd, subtract or skipModerate, smaller with training
BinaryTwo levels1 bitXNOR and popcountOften large
Low-bit weight formats on edge hardware

The zero level is the decisive difference from binarized networks. It lets the network express that an input is irrelevant, it typically makes a substantial share of weights exactly zero, and hardware can skip those operations entirely, combining quantization with model sparsity.

Storage and hardware efficiency

The storage gain of a ternary network depends on how the three values are packed. The theoretical minimum is log base 2 of 3, or about 1.58 bits, but practical kernels use simpler encodings that trade a little space for faster decoding.

Packing methodBits per weightDecoding costTypical use
Two-bit codes2.0Very lowGeneral CPU and GPU kernels
Five trits per byte1.6Low to moderateMemory-bound inference
Sparse index formatVaries with sparsityModerateHighly sparse layers
Lookup-table kernelsAbout 1.6 to 2Low after table setupCPU inference of large models
Packing methods for ternary weights

On general-purpose processors, the main benefit is reduced memory traffic, which dominates energy use in many edge workloads. On custom accelerators and FPGAs, ternary arithmetic also removes multipliers, enabling much smaller and lower-power compute units. Mainstream mobile NPUs, however, are optimized for INT8 and INT4, so ternary models may need specialized kernels to realize their theoretical advantage.

Limitations and common mistakes

The most common mistake is expecting post-training ternarization to work like INT8 conversion; without retraining, accuracy often collapses. Other pitfalls concern measurement and deployment rather than the quantizer itself.

  • Ignoring activations: ternary weights with 16-bit activations save memory but not most compute.
  • Reporting theoretical speedups: gains vanish if the runtime unpacks weights to FP16 before computing.
  • Ternarizing every layer: sensitive layers such as embeddings and classifiers often need higher precision.
  • Small models suffer most: accuracy gaps tend to shrink as model size grows, but remain notable for compact networks.
  • Toolchain gaps: few standard edge inference runtimes support ternary operators natively.

Understanding it simply

A normal neural network stores millions of precise numbers. A ternary neural network keeps only three choices for each one: minus one, zero or plus one. That is like replacing a detailed volume dial with a switch that says down, off or up.

This makes the model much smaller and cheaper to run. The device mostly adds and subtracts instead of multiplying. Some accuracy can be lost, so the network is trained with this limit from the start.

Applied in practice

An engineering team builds a battery-powered wildlife camera that must recognize ten animal species on a microcontroller with 512 KB of SRAM and 2 MB of flash. Their 8-bit convolutional model needs about 1.4 MB of weights and drains the battery in roughly three weeks of continuous sensing.

The team retrains the network with ternary weights and 8-bit activations, keeping the first convolution and the final classifier in 8 bits. Weights shrink to about 0.4 MB, and about 45 percent of them become zero, which the custom kernel skips.

Validation accuracy falls from 91.8 to 90.6 percent, which the team accepts. Because memory reads and arithmetic both drop sharply, measured energy per inference falls by more than half, and the camera now runs for about seven weeks on one battery pack.