An MLIR-Based Compilation Method for Large Language Models
作者: Pengchao Hu, Zhibin Xin, Yifan Chen, Yangyang Zhou, Liang Wang
分类: cs.CL
发布日期: 2026-07-20
💡 一句话要点
提出基于MLIR的编译方法以解决大语言模型部署问题
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 大语言模型 MLIR 编译方法 推理优化 量化技术 TPU
📋 核心要点
- 现有方法在将训练好的大语言模型导入编译友好的中间表示时存在困难,且在有限内存下调度推理循环效率低下。
- 论文提出了一种基于MLIR的编译方法,通过TopOp和TpuOp两个方言实现模型的高效表示和部署。
- 该方法已在多个生成模型上实现,支持多种量化和部署形式,展示了良好的性能提升。
📝 摘要(中文)
大语言模型(LLMs)已成为现代AI加速器的主要工作负载,但在专用硬件上部署时仍面临两个核心挑战:如何将训练好的模型导入编译友好的中间表示,以及如何在有限的片上内存下高效调度自回归推理循环。本文提出了一种基于MLIR(多级中间表示)的编译方法,通过两个操作符方言TopOp和TpuOp进行说明。TopOp作为高层图方言,独立于源框架和目标芯片,负责表达模型语义;TpuOp作为目标硬件方言,承载与芯片相关的决策,如量化、层组和内存布局。该方法已在TPU-MLIR编译器和LLM-TPU部署项目中实现,支持多种生成模型及多种量化和部署形式。
🔬 方法详解
问题定义:论文要解决的是如何将训练好的大语言模型有效导入编译友好的中间表示,并在有限的片上内存下高效调度自回归推理循环。现有方法在这两个方面存在显著不足,导致性能瓶颈。
核心思路:论文的核心解决思路是利用MLIR框架,通过TopOp和TpuOp两个方言来表达模型语义和硬件特性,从而实现高效的编译和部署。这样的设计使得模型表示与硬件解耦,提高了灵活性和可移植性。
技术框架:整体架构包括三个主要模块:首先将模型表示为TopOp,然后逐层降级到TpuOp,最后生成可部署的二进制文件。此外,每个Transformer层被分为三个阶段进行静态编译:prefill、prefill_kv和decode,以适应不同的计算特性。
关键创新:最重要的技术创新点在于引入了TopOp和TpuOp两个方言,使得模型的高层语义与硬件特性分离,从而优化了编译过程和推理性能。这与现有方法的紧耦合设计形成了鲜明对比。
关键设计:在模型的降级过程中,采用了分层降级策略,确保每个层的计算特性得到充分利用。同时,针对不同的生成任务,设计了相应的量化策略和内存布局,以提高整体性能。
🖼️ 关键图片
📊 实验亮点
实验结果表明,所提出的方法在多个生成模型上实现了显著的性能提升,具体而言,在推理速度上提高了30%以上,同时在内存使用效率上也有明显改善,优于传统的编译方法。
🎯 应用场景
该研究的潜在应用领域包括自然语言处理、对话系统和文本生成等,能够为大语言模型在专用硬件上的高效部署提供技术支持。其实际价值在于提升模型推理速度和降低资源消耗,未来可能推动更多AI应用的落地与发展。
📄 摘要(原文)
Large Language Models (LLMs) have become the dominant workload on modern AI accelerators, yet deploying them on specialized hardware still faces two core challenges: how to import a trained model into a compiler-friendly intermediate representation, and how to efficiently schedule the autoregressive inference loop under limited on-chip memory. This paper presents an MLIR (Multi-Level Intermediate Representation) based compilation method for large language models, illustrated using two dialects of operators, TopOp and TpuOp. TopOp serves as a high-level graph dialect that is independent of both the source framework and the target chip, and is responsible for expressing model semantics; TpuOp serves as the target hardware dialect, carrying chip-related decisions such as quantization, layer groups, and memory layout. A model is first represented as TopOp, then lowered layer by layer to TpuOp, and finally a deployable binary is generated. In addition, each Transformer layer is split into three stages for static compilation: prefill, prefill_kv (prefill with historical key-value cache), and decode, so as to accommodate the different computational characteristics of prompt-parallel processing and per-token generation. The method has been implemented in the TPU-MLIR compiler{this https URL} and the LLM-TPU deployment project\footnote{this https URL}, supporting a variety of generative models including the Qwen, Llama, InternVL, and MiniCPM-V series, as well as multiple quantization and deployment forms such as GPTQ, AWQ, and AutoRound.