2022年11月,Google在《Fast Inference from Transformers via Speculative Decoding》里提出投机解码的策略;DeepMind稍晚一点,在2023年初的《Accelerating Large Language Model Decoding with Speculative Sampling》也提出了一样的解码策略。(以这两家的关系,很可能私底下就沟通过这个idea了)Google的论文相比DeepMind的,做了更多的实验和分析,更为详尽一些。
在speculative decoding之前,研究人员已经在模型推理加速这个方向做了不少工作:
模型蒸馏:以Hinton的《Distilling the Knowledge in a Neural Network》为代表,以及后面衍生出的各种蒸馏方法(参考《Knowledge Distillation: A Survey》),可以把规模更大的、性能更强的模型的能力,部分迁移到规模较小的模型上,在效果上相比直接训练小模型有一定的提升。transformer上蒸馏相关的经典工作有《TinyBERT: Distilling BERT for Natural Language Understanding》和《DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighter》等。
模型量化:如《Quantized Neural Networks: Training Neural Networks with Low Precision Weights and Activations》、《LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale》、《Zeroquant: Efficient and affordable post-training quantization for large-scale transformers》等,把模型参数量化到int8、int4以及更低的精度,在减少空间需求的同时,最大化地保持模型的推理效果。
高效模型结构设计:如使用稀疏层的《Sparse is Enough in Scaling Transformers》,减少KV缓存需求的MQA《Fast Transformer Decoding: One Write-Head is All You Need》、GQA《《GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints》》以及最近DeepSeek-V2中的MLA等,还有通过进化算法进行高效架构搜索的工作《Primer: Searching for Efficient Transformers for Language Modeling》。
《Consistent Accelerated Inference via Confident Adaptive Transformers》
《Why should we add early exits to neural networks?》
《Controlling Computation versus Quality for Neural Sequence Models》
《The Right Tool for the Job: Matching Model and Instance Complexities》
《Depth-Adaptive Transformer》
等
MoE也属于动态激活的方案之一。
而《Training compute-optimal large language models》的scaling law则指出模型规模没有原先预想的影响那么大,可以通过增加训练数据等方法让小模型逼近大模型的效果。
以上这些方案虽然可以在一定程度上提升推理效率,但是要么需要重新训练模型,要么对模型的效果有损害。
也有一些方案在解码的方法上进行优化,比如《Blockwise Parallel Decoding for Deep Autoregressive Models》和《Lossless Acceleration for Seq2seq Generation with Aggressive Decoding》。