vLLM引入硬件无关层以平衡前沿性能与跨平台兼容
Hardware-Agnostic Models in vLLM
vLLM核心架构调整直接影响推理部署选型,这篇技术博客详细解释了如何在追求极致性能的同时通过新机制保障多硬件兼容,做推理服务优化的同学必读。
TL;DR
TL;DR(太长不看)
To achieve state-of-the-art performance at the frontier, vLLM is changing its internal implementation in ways that make it incompatible with fullgraph torch.compile. This may have consequences for users who care about out-of-tree accelerators, older GPUs, or more exotic models. To address this, we are introducing a new set of “HW agnostic” layers in vLLM. These layers will ensure vLLM can continue to move at the speed of light, while at the same time meeting the needs of users who care about portability. On NVIDIA H100 GPUs, the HW agnostic layers achieve total token throughput within 3.4% of the native implementation (geometric mean across three recent models).
为了在前沿领域实现最先进的性能,vLLM 正在改变其内部实现方式,这使得它与 fullgraph torch.compile 不兼容。这可能会影响到关注树外加速器、旧款 GPU 或更奇特模型的用户。为了解决这个问题,我们在 vLLM 中引入了一套新的“硬件无关”层。这些层将确保 vLLM 能够继续以光速推进开发,同时满足对可移植性有需求的用户。在 NVIDIA H100 GPU 上,硬件无关层的总 token 吞吐量与原生实现相差不到 3.4%(基于三个近期模型的几何平均值)。
vLLM at the frontier
前沿领域的 vLLM
vLLM has achieved unprecedented success by positioning itself as the abstraction layer supporting a wide variety of models on a wide variety of hardware. By using a set of well-designed abstractions and torch.compile for optimization and fusion, the project has been able to keep the code defining the actual model logic (commonly known as “model definitions”) relatively simple, whilst still achieving high performance across NVIDIA GPUs, AMD GPUs, Intel XPUs, Google TPUs, IBM Spyre, Huawei Ascend and more.
vLLM 通过将自己定位为支持多种硬件上各种模型的抽象层,取得了前所未有的成功。通过使用一套精心设计的抽象和 torch.compile 进行优化与融合,该项目得以保持定义实际模型逻辑的代码(通常称为“模型定义”)相对简单,同时在 NVIDIA GPU、AMD GPU、Intel XPU、Google TPU、IBM Spyre、华为昇腾等平台上实现了高性能。
However, the architectures of frontier open-weight models are rapidly diverging, which has led the community to revisit whether some of the existing abstractions are fit for purpose. Models increasingly ship with bespoke layers and optimized kernels. This even extends to the core attention mechanism: DeepSeek V4 and Kimi K3 achieve million-token context via completely different approaches. Fitting one of these into vLLM means composing it from the shared layers in model_executor/layers and keeping the whole model fullgraph compilable: written so that Dynamo can trace it, with each new kernel registered as a torch library op with a fake implementation and correct mutation annotations. That work is a tax on model development, and it is paid by whoever adds the model, including the advanced users who bring their own.
然而,前沿开源权重模型的架构正在迅速分化,这促使社区重新审视现有的一些抽象是否仍适用。模型越来越多地附带定制化的层和优化内核。这种情况甚至延伸到了核心的注意力机制:DeepSeek V4 和 Kimi K3 通过完全不同的方法实现了百万 token 的上下文。将这些模型之一适配到 vLLM 中,意味着需要从 model_executor/layers 中的共享层组合而成,并保持整个模型可编译为全图计算:代码需编写得让 Dynamo 能够追踪它,每个新内核都注册为带有虚假实现和正确变异注解的 torch library op。这项工作是对模型开发的额外负担,由添加模型的人承担,包括那些自带模型的高级用户。
At the same time, NVIDIA Blackwell GPUs and rack-scale systems like NVIDIA GB300 NVL72 require careful kernel engineering to exploit new features and effectively overlap computation with communication.
与此同时,NVIDIA Blackwell GPU 和如 NVIDIA GB300 NVL72 这样的机架级系统需要细致的内核工程来利用新功能,并有效地将计算与通信重叠。
While all this is happening, we have seen the rise of coding agents like Claude Code and OpenAI Codex, which make generating code much easier. In particular, these agents are very effective at designing optimizations for a specific model on specific hardware. However, they work best if they do not need to worry about whether a particular change will make things worse for a different model, on a different accelerator.
在此过程中,我们见证了 Claude Code 和 OpenAI Codex 等编码代理的兴起,它们使得生成代码变得更加容易。特别是,这些代理在针对特定硬件上的特定模型设计优化方面非常有效。然而,如果它们不需要担心某项特定更改是否会对不同加速器上的不同模型造成负面影响,它们的效果最佳。
These trends come together and mean that, to achieve state-of-the-art performance on the latest GPU hardware, the community would like to dismantle some of the existing abstractions in vLLM. In particular, vLLM is starting to maintain hardware-specific model definitions, otherwise known as “flat” models. Rather than using torch.compile, flat models use custom fusions and other model-specific and hardware-specific optimizations. New frontier models added to vLLM in recent months all use this flat model definition. Critically, the existing layers and ops consumed by the model definitions are likely to be refactored in a way that makes them fundamentally incompatible with torch.compile.
这些趋势汇聚在一起意味着,为了在最新的 GPU 硬件上实现最先进的性能,社区希望拆解 vLLM 中现有的部分抽象层。具体而言,vLLM 开始维护硬件特定的模型定义,也就是所谓的“扁平化”(flat)模型。与使用 torch.compile 不同,扁平化模型采用自定义融合以及其他模型特定和硬件特定的优化。最近几个月添加到 vLLM 中的前沿模型均使用这种扁平化模型定义。关键在于,模型定义所依赖的现有层和操作可能会以使其与 torch.compile 根本不相容的方式进行重构。
This effort is necessary to enable vLLM to stay competitive on the latest GPU benchmarks. However, it is also important that vLLM continues to serve its users who care about serving diverse models on diverse hardware like older GPUs or out-of-tree (OOT) accelerators.
这项努力对于使 vLLM 在最新的 GPU 基准测试中保持竞争力是必要的。然而,同样重要的是,vLLM 应继续服务于那些关心在不同硬件(如旧款 GPU 或树外 OOT 加速器)上部署多样化模型的用户。
So, what can we do about it? Let’s start by reviewing how vLLM handles model definitions today.
那么,我们能做些什么呢?让我们先从回顾 vLLM 目前如何处理模型定义开始。
How do model definitions work in vLLM?
vLLM 中的模型定义是如何工作的?
Today, vLLM offers three flavours of model definitions.
目前,vLLM 提供三种类型的模型定义。
- The new “flat” models which live under vllm/models/
- The legacy models which live under vllm/model_executor/models
- The transformers modeling backend, which imports models from transformers.
- 位于 vllm/models/ 下的新型“扁平化”模型
- 位于 vllm/model_executor/models 下的传统模型
- transformers 建模后端,该后端从 transformers 导入模型。
A high-level sketch of the current state is shown below.
下图展示了当前状态的高层概览。
Figure 1: The current state of model definitions in vLLM. All three flavours resolve to a single implementation of each common layer, shown here for RowParallelLinear. SpyreRowParallelLinear is an out-of-tree plugin overriding that layer on one accelerator.
图 1:vLLM 中模型定义的当前状态。所有三种类型都解析为每个公共层的单一实现,此处以 RowParallelLinear 为例展示。SpyreRowParallelLinear 是一个树外插件,用于在一个加速器上覆盖该层。
While the modeling logic may live in different places, most models are composed of common layers like attention, mixture-of-experts, linear projections, norms and activations. It is important to understand that, in all 3 cases above, these common layers are still implemented in a single place. In case (1) and (2) these layers are explicitly imported from vllm/model_executor/layers. In case (3), the transformers model gets automatically fused and re-wired to use the vLLM layers. Thus, wherever the model definition is coming from, we are still using a common implementation of the majority of the layers that underpin it.
尽管建模逻辑可能分布在不同的位置,但大多数模型由常见的层组成,如注意力机制、混合专家(MoE)、线性投影、归一化和激活函数。重要的是要理解,在上述三种情况下,这些公共层仍然在单一位置实现。在情况(1)和(2)中,这些层是从 vllm/model_executor/layers 显式导入的。在情况(3)中,transformers 模型会自动融合并重新布线以使用 vLLM 层。因此,无论模型定义来自何处,我们仍然在使用支撑它的大部分层的公共实现。
vLLM’s layer implementations have evolved over several years and offer two important features that we will now discuss in more detail: (a) torch compile support, and (b) OOT extensibility.
vLLM 的层实现经过数年的演进,提供了两个重要特性,我们将进一步详细讨论:(a) torch compile 支持,以及 (b) OOT(Out-of-Tree)可扩展性。
While fullgraph torch compile is not used by the flat models, it remains a critical feature for OOT plugins like IBM Spyre. Spyre relies on TorchDynamo to trace the model graph, and TorchInductor to lower the graph down to representations that run optimally on the target hardware. Crucially, torch compile is also a necessary component for enabling vLLM’s transformers backend to achieve native speed for models like Qwen3 on NVIDIA GPUs.
虽然扁平化模型未使用 fullgraph torch compile,但它对于 IBM Spyre 等 OOT 插件而言仍是关键特性。Spyre 依赖 TorchDynamo 追踪模型图,并使用 TorchInductor 将图降低为能在目标硬件上最优运行的表示形式。至关重要的是,torch compile 也是使 vLLM 的 transformers 后端能够在 NVIDIA GPU 上实现 Qwen3 等模型原生速度的必要组件。
However, for OOT plugins torch compile is not the whole story. Accelerators like Spyre also occasionally need to inject behaviour into the layers (e.g., custom memory layouts) to achieve optimal performance. vLLM’s layer offers two different mechanisms for injecting custom behaviour: CustomOp (which enables the plugin to override the forward function) and PluggableLayer (which enables the plugin to override the entire layer). Without this extensibility, OOT plugins would need to re-implement many of the layers themselves.
然而,对于 OOT 插件而言,torch compile 并非全部。像 Spyre 这样的加速器偶尔也需要向层中注入行为(例如自定义内存布局)以实现最佳性能。vLLM 的层提供了两种用于注入自定义行为的机制:CustomOp(允许插件重写前向函数)和 PluggableLayer(允许插件重写整个层)。如果没有这种可扩展性,OOT 插件将需要自行重新实现许多层。
So, what is the problem here?
那么,这里的问题是什么?
Aside from the fact that having model definitions in three places is pretty confusing, there is a more pressing issue with the above design.
除了模型定义分散在三个位置令人困惑之外,上述设计还存在一个更紧迫的问题。
The flat model workstream needs to change the model definitions, and their underlying layer implementations, to break compatibility with torch compile and remove support for extensibility via CustomOp. This will unlock them to move faster on developing hardware-specific and model-specific performance optimizations, but it also raises some concerns.
扁平化模型工作流需要更改模型定义及其底层层实现,以打破与 torch compile 的兼容性并移除对通过 CustomOp 进行扩展的支持。这将使他们能够更快地开发针对特定硬件和特定模型的性能优化,但也引发了一些担忧。
Firstly, it leaves OOT plugins facing the prospect of maintaining their own set of model definitions and layers, creating a large maintenance burden. Supporting a new model will involve making pull requests to transformers, vLLM, and then potentially every OOT plugin that wants to support it. Yes, coding agents make this easier but this will still require burning through token budgets across multiple different organizations for ultimately no real benefit.
首先,这使得 OOT 插件面临维护自身模型定义和层的困境,造成了巨大的维护负担。支持新模型需要向 transformers、vLLM 提交拉取请求,然后可能还需要向所有希望支持该模型的 OOT 插件提交请求。是的,编码代理使这一过程变得更容易,但这仍然需要消耗多个不同组织的 token 预算,而最终并无实际益处。
Second, vLLM is increasingly relying on the transformers backend to provide support for older or more exotic models. Legacy model definitions are actively being removed from model_executor/models and their registry entries updated to point directly at the transformers modeling backend. Without torch compilable layers, performance for these models on GPU will regress significantly.
其次,vLLM 越来越依赖 transformers 后端来为较旧或更小众的模型提供支持。遗留模型定义正从 model_executor/models 中被主动移除,其注册表条目已更新为直接指向 transformers 建模后端。如果没有可 torch 编译的层,这些模型在 GPU 上的性能将显著下降。
Finally, while the flat model and layers will be optimized for frontier GPUs, we do not expect them to provide support for older GPUs or consumer/prosumer GPUs. vLLM’s own usage statistics show that a significant portion of the user base continues to use such hardware. We believe the project should also evolve in a way that meets their needs.
最后,虽然扁平化的模型和层将为前沿 GPU 进行优化,但我们预计它们不会支持较旧的 GPU 或消费级/准专业级 GPU。vLLM 自身的统计数据表明,相当一部分用户群体仍在继续使用此类硬件。我们认为该项目也应以满足他们需求的方式演进。
What is our solution?
我们的解决方案是什么?
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力