Transformadores Cuantizables: Eliminando Valores Atípicos Ayudando a las Cabezas de Atención a No Hacer Nada
Quantizable Transformers: Removing Outliers by Helping Attention Heads Do Nothing
June 22, 2023
Autores: Yelysei Bondarenko, Markus Nagel, Tijmen Blankevoort
cs.AI
Resumen
Los modelos Transformer han sido ampliamente adoptados en diversos dominios en los últimos años, y especialmente los modelos de lenguaje de gran escala han impulsado significativamente el campo de la IA. Debido a su tamaño, la capacidad de estas redes ha aumentado enormemente, pero esto ha conllevado un incremento significativo en el cómputo necesario. La cuantización es una de las formas más efectivas de reducir el tiempo computacional y el consumo de memoria de las redes neuronales. Sin embargo, muchos estudios han demostrado que los modelos Transformer modernos tienden a aprender valores atípicos fuertes en sus activaciones, lo que dificulta su cuantización. Para mantener un rendimiento aceptable, la existencia de estos valores atípicos requiere que las activaciones estén en un ancho de bits mayor, el uso de formatos numéricos diferentes, un ajuste fino adicional u otras soluciones alternativas. Mostramos que los valores atípicos fuertes están relacionados con un comportamiento muy específico de las cabezas de atención que intentan aprender una operación "no-op" o simplemente una actualización parcial del residual. Para lograr los ceros exactos necesarios en la matriz de atención para una no-actualización, la entrada a la función softmax se empuja a ser cada vez más grande durante el entrenamiento, causando valores atípicos en otras partes de la red. Basándonos en estas observaciones, proponemos dos modificaciones simples (e independientes) al mecanismo de atención: softmax recortado y atención con compuerta. Demostramos empíricamente que los modelos preentrenados utilizando nuestros métodos aprenden valores atípicos significativamente más pequeños mientras mantienen y, en ocasiones, incluso mejoran el rendimiento en tareas de punto flotante. Esto nos permite cuantizar los Transformers a una cuantización completa INT8 de las activaciones sin ningún esfuerzo adicional. Demostramos la efectividad de nuestros métodos tanto en modelos de lenguaje (BERT, OPT) como en Transformers de visión.
English
Transformer models have been widely adopted in various domains over the last
years, and especially large language models have advanced the field of AI
significantly. Due to their size, the capability of these networks has
increased tremendously, but this has come at the cost of a significant increase
in necessary compute. Quantization is one of the most effective ways to reduce
the computational time and memory consumption of neural networks. Many studies
have shown, however, that modern transformer models tend to learn strong
outliers in their activations, making them difficult to quantize. To retain
acceptable performance, the existence of these outliers requires activations to
be in higher bitwidth or the use of different numeric formats, extra
fine-tuning, or other workarounds. We show that strong outliers are related to
very specific behavior of attention heads that try to learn a "no-op" or just a
partial update of the residual. To achieve the exact zeros needed in the
attention matrix for a no-update, the input to the softmax is pushed to be
larger and larger during training, causing outliers in other parts of the
network. Based on these observations, we propose two simple (independent)
modifications to the attention mechanism - clipped softmax and gated attention.
We empirically show that models pre-trained using our methods learn
significantly smaller outliers while maintaining and sometimes even improving
the floating-point task performance. This enables us to quantize transformers
to full INT8 quantization of the activations without any additional effort. We
demonstrate the effectiveness of our methods on both language models (BERT,
OPT) and vision transformers.