arXiv:2603.24239cs.PLcs.AI2026-03

用字节码虚拟机实现实时编译,解决动态张量计算的效率难题。

DVM: A Bytecode Virtual Machine Approach for Dynamic Tensor Computation

  • 基于字节码虚拟机的运行时编译器,按需高效生成指令。
  • 相比TorchInductor等,算子/模型效率最高提升11.77倍,编译时间快5个数量级。
  • 适合需要高动态性与低延迟的AI推理场景,如边缘设备部署。

动态张量计算在人工智能中普遍存在,如模型中的动态张量形状和控制流。现有运行时编译因编译耗时影响效率,而离线编译则面临编译时间长、设备内存占用高或优化机会牺牲的问题。本文重新思考运行时编译的可行性,提出关键在于加速编译或隐藏编译开销。为此,我们设计了实时编译器DVM:基于字节码虚拟机的运行时操作符编译器,将操作符程序编码为字节码在CPU上处理,并解码为虚拟指令直接在NPU上执行。在此基础上,进一步提出操作符融合机制,支持基于符号推导的静态图融合与基于运行时的动态图融合,涵盖模式与堆叠两种融合方式,显著提升融合机会。在算子、子图和模型上的评估表明,相较于TorchInductor、PyTorch-eager和MindSpore-graph-O0,DVM在算子/模型效率上最高提升11.77倍,在最大编译时间上最快达5个数量级,兼具高效与低延迟优势。

原文摘要 · Abstract (English)

Dynamism is common in AI computation, e.g., the dynamic tensor shapes and the dynamic control flows in models. Due to the long compilation time, existing runtime compilation damages the model efficiency, while the offline compilers either suffer from the long compilation time and device memory footprint to cover all the possible execution instances of a dynamic model, or sacrifice optimization opportunities for usability. In this paper, we rethink the feasibility of runtime compilation for dynamic models and identify that the key for it to work is to speed up the compilation or hide the compilation overhead. To do this, we propose a real-time compiler, DVM. In DVM, we design a runtime operator compiler based on a bytecode virtual machine to perform effective and efficient compilation for each dynamic operator instance given its input. Specifically, instead of compiling programs into machine code, we encode the operator program into bytecode on the CPU and decode the bytecode into virtual instructions for direct execution on the NPU. Based on the runtime operator compiler, we further propose an operator fuser, which performs symbol-deduction-based fusion on static graphs and runtime fusion on dynamic graphs. Both pattern- and stacking-based fusion are supported to increase fusion opportunities. Evaluation on operators, subgraphs, and models shows that, compared with TorchInductor, PyTorch-eager and MindSpore-graph-O0, we are up to 11.77$\times$ better in terms of the operator/model efficiency and up to 5 orders of magnitude faster in terms of the maximum compilation time.

动态计算虚拟机编译优化NPU

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。