When you upload an image for an artificial intelligence chatbot to examine, that image is sent to a data centre’s servers. There, image-processing models called vision transformers (ViTs) can analyse it and help generate a response for you within moments. But if you try running a ViT directly on your smartphone for the same task, it’s likely to consume a large amount of time, storage space, battery life, or a combination thereof.
To change that, ViTs must be compressed to a form that small chips can handle. One way to do this is through quantization: a process which reduces the amount of data, or bits, used to represent the numbers in a model, reducing both its size and the energy it needs to process images.
“It’s like writing down a shopping list with prices rounded to the nearest dollar, rather than to the cent,” said Zhe Wang, a Senior Research Engineer at the A*STAR Institute of Advanced Intelligence and Computing (A*STAR IAIC), formerly the A*STAR Institute of Infocomm Research (A*STAR I2R). “The total still comes out close to right, but the list is much simpler to add together.”
However, quantization can also significantly reduce a model’s accuracy. With this in mind, Wang and A*STAR IAIC colleagues, including Senior Research Engineer Kaixin Xu and Principal Scientist Min Wu, are working with research partners at Nanyang Technological University, Singapore, to develop a new post-training quantization method that mitigates accuracy loss in ViT neural networks.
Xu explained that existing methods generally quantize layers in a ViT one by one. However, this means even a small error introduced in an early layer can grow across successive layers, resulting in a suboptimal final model. In addition, each layer’s best settings depend on how earlier layers were compressed.
“Our method compresses the whole network in a single optimisation,” said Xu. “The quantity we minimise is the error at the very end of the network, which is the only error that actually affects the prediction.”
Moreover, instead of restricting all layers to the same number of bits, the team developed an efficient algorithm that identifies which layers are more sensitive to quantization and allocates more bits to those, further minimising errors.
When tested against 64 image samples from a training database, the team’s quantized ViT models showed smaller accuracy drops than those produced by other approaches. When quantized from 32-bit to 6-bit, the team’s models showed almost no accuracy loss; when further quantized to 4-bit, the team’s models had modest losses, while others dropped to near-zero accuracy.
Their tests also showed that quantizing ViTs decreases their size as much as eightfold, making them practicable for small devices beyond smartphones. “It can enable a drone to inspect power lines, a car to recognise road scenes, an ultrasound machine to become portable, or a factory camera to check parts on a line,” said Wu.
The researchers say their study can be extended to optimise not just model size, but also latency, energy use and arithmetic operations. “We plan to extend this study to hardware-software co-optimisation, and to implement the technology on real edge platforms,” Wang added.
The A*STAR-affiliated researchers contributing to this research are from the A*STAR Institute of Advanced Intelligence and Computing (A*STAR IAIC).