读见

迈向解码极限:ERNIE 5.5 Flash 在 SGLang 上达到 1074 tokens/s

原题Toward the Decode Limit: ERNIE 5.5 Flash at 1074 tokens/s on SGLang

约 11 分钟约 2,646 字原文英文已翻译

推荐理由做在线推理的工程师可以按并行方式、内核执行和推测解码逐项看开销,判断哪些优化值得在自己的请求形态下重测。

读前速览

5 个要点

本文详细介绍了 ERNIE 5.5 Flash 在 SGLang 上实现低延迟解码的完整优化流程,通过张量并行、DSpark 推测解码、MegaLLMoE 和 One-Pass mHC 等技术,将速度提升至 1074 tokens/s。

  1. 张量并行取代 DP/EP,实现负载均衡

    张量并行将计算和权重读取均匀分配到所有 GPU 上,消除了专家并行(EP)因路由不均造成的负载偏斜,并降低了同步开销。

  2. DSpark 推测解码支持并行生成候选 token

    不同于 MTP 的自回归草拟方式,DSpark 在一次前向传递中并行生成一组候选 token,从而改变关键路径上的瓶颈,并提高每步生成的 token 数量。

  3. MegaLLMoE 将路由、专家计算和归约融合进一个内核

    MegaLLMoE 通过任务并行、权重分块以及通信与计算重叠,将所有操作整合进单个 CUDA 内核,从而降低 MoE 层的单步延迟。

  4. One-Pass mHC 打破超连接中的串行依赖

    通过平方范数的双线性展开,可在代数上将聚合权重与归一化缩放合并到一次归约中,消除此前限制推理性能的两遍执行链。

  5. 注意力数据流重构将稀疏操作转移到旁路流

    压缩器和后置分块注意力被移至旁路流,利用空闲的 SM 执行,并通过轻量级信号机制避免内核级同步,使稀疏操作不再处于关键路径上。

完整摘要

ERNIE 5.5 Flash 模型通过一系列低延迟优化,在 SGLang 上实现了 1074 tokens/s 的解码速度。作者从朴素的 DP/EP 实现入手,其速度仅为 102 tokens/s,随后逐步采用张量并行(TP4)、DSpark 推测解码、结合多流执行和 PDL 的通信与计算融合、One-Pass mHC,以及注意力数据流重构。最终配置采用注意力 TP4 和 MoE TP4,在模拟接受长度为 5.5 的情况下,平均每步耗时约 4.65 ms,吞吐量达到 1074 tokens/s。文章详细解释了各项优化的技术原理,包括内核融合策略、权重分块和推测解码机制,并提供了可复现的基准测试命令。

目录 · 8 节

查看原文
Baidu ERNIE Team and SGLang TeamNovember 23, 2026
On this page

我们已为 SGLang 添加 ERNIE 5.5 Flash 的低延迟解码支持,并对整个流程进行了端到端优化。在四张 SM100 GPU 上,BS=1、输入 55K tokens、输出 1K tokens 的条件下,我们引入了低延迟 GEMM 和张量并行,集成了 DSpark 推测解码,并通过迭代调优实现了计算与通信融合、多流执行和 PDL,同时完成了 MegaLLMoE、注意力数据流重构和 One-Pass mHC 等优化。采用 attention TP4 和 MoE TP4 的最终配置后,在模拟 DSpark 平均接受长度为 5.5 时,解码速度达到 1074 tokens/s;采用 DSpark block size 7、模拟接受长度为 7.2 时,解码速度约为 1310 tokens/s。We have added low-latency decoding support for ERNIE 5.5 Flash to SGLang and optimized it end to end. On four SM100 GPUs, BS=1, 55K input tokens and 1K output tokens, we introduced low-latency GEMM and tensor parallelism, integrated DSpark speculative decoding, iteratively tuned compute-communication fusion, multi-stream execution and PDL, and completed optimizations including MegaLLMoE, attention dataflow restructuring and One-Pass mHC. With the final configuration of attention TP4 and MoE TP4, decoding reaches 1074 tokens/s at a simulated mean DSpark acceptance length of 5.5, and about 1310 tokens/s with DSpark block size 7 at a simulated acceptance length of 7.2.

ERNIE 5.5 Flash decode speed after each merged optimization

每个数据点按合并顺序展示一项优化合并后的端到端解码速度,并标注了几项关键优化。第一个数据点是朴素的 DP/EP 实现,从第二个数据点开始使用 TP4。启用 DSpark 后的所有测量均使用 5.5 的模拟接受长度。Each point shows the end-to-end decoding speed after an optimization was merged, in merge order, with several key optimizations annotated. The first point is the naive DP/EP implementation, and TP4 is used from the second point on. All measurements after DSpark is enabled use a simulated acceptance length of 5.5.

低延迟解码的瓶颈The Bottlenecks of Low-Latency Decoding

LLM 解码是自回归的:每一步都依赖上一步的输出。要将解码速度推向极限,通常意味着针对低并发进行激进优化,此时每一步参与计算的 token 极少:常规解码时只有一个,即使采用推测解码,也只有寥寥几个。根据屋顶线模型衡量,其算术强度远低于所需水平,因此这是典型的内存受限型工作负载。ERNIE 5.5 Flash 是一个大型稀疏 MoE 模型,使用 mHC 在各层之间维持多条残差流。在这种情况下,架构中的每一处精细设计都会增加内存流量、同步开销和通信开销。因此,这里的解码从根本上说受延迟限制,而非受计算能力限制。每一步的耗时由一条串行关键路径决定,其中包含三类主要开销:受 HBM 带宽限制的权重读取;与计算量无关的调度、同步及其他开销;以及多 GPU 协作带来的通信延迟。计算量越小,后两类开销所占的比例就越大,直至它们主导整体延迟。LLM decoding is autoregressive: each step depends on the output of the previous one. Pushing decoding speed to its limit generally means optimizing aggressively for low concurrency, where very few tokens take part in each step: one in regular decoding, and only a handful even with speculative decoding. Measured by the roofline model, its arithmetic intensity is far too low, making it a classic memory-bound workload. ERNIE 5.5 Flash is a large sparse MoE model that uses mHC to maintain multiple residual streams across layers. In this setting, every fine-grained architectural detail adds memory traffic, synchronization and communication overhead. Decoding here is therefore fundamentally latency-bound rather than compute-bound. The per-step time is determined by a serial critical path, which carries three main kinds of overhead: weight reads bounded by HBM bandwidth; scheduling, synchronization and other overheads unrelated to the amount of computation; and communication latency introduced by multi-GPU collaboration. The smaller the computation, the larger the share of the latter two, until they dominate the latency.

解码速度等于每步生成的 token 数除以每步延迟,因此优化工作分为两个方向。第一,减少解码步数:投机解码在一次前向传播中并行验证多个候选 token,以较小的额外开销生成更多解码 token,同时提高算术强度。第二,降低每步延迟:针对关键路径上的三类开销,我们让权重读取尽可能逼近带宽上限,通过算子融合减少固定开销,并将通信与计算重叠以隐藏通信延迟。Decoding speed is the number of tokens produced per step divided by the per-step latency, so the optimization work splits into two directions. The first is to reduce the number of decoding steps: speculative decoding verifies multiple candidate tokens in parallel within one forward pass, yielding more decoded tokens at a small extra cost while raising arithmetic intensity. The second is to cut per-step latency: targeting the three kinds of overhead on the critical path, we push weight reads toward the bandwidth limit, cut fixed overheads through operator fusion, and hide communication latency by overlapping it with computation.

低延迟基础:并行化、硬件利用率、算子融合与内核重叠A Low-Latency Foundation: Parallelism, Hardware Utilization, Operator Fusion and Kernel Overlap

摆脱 DP/EP:更少通信,更佳负载均衡。在低延迟场景中,并行方式的选择取决于关键路径延迟,而非吞吐量。我们的分析表明,如果注意力计算采用数据并行,所有内存访问和计算都会集中在部分 rank 上,其余 rank 则只能空闲等待负载较重的 rank。张量并行则以少量通信为代价,将计算和权重读取均匀分摊到所有 rank 上,既能充分利用每块 GPU 的算力,也能缩短负载最重 rank 的串行耗时。MoE 也是如此。EP 要求在专家计算前后各进行一轮跨 GPU 交换,而每一步的计算量都太少,无法掩盖等待时间。TP 只需对专家输出进行归约,从而减少通信量和同步次数。它还会将每个专家均匀拆分到所有 GPU 上,消除 EP 下因路由不均造成的负载倾斜,因此层延迟不再受负载最重的 GPU 所限制。Moving Away from DP/EP: less communication, better load balance. In low-latency scenarios, the choice of parallelism is driven by critical-path latency rather than throughput. Our analysis shows that if attention runs with data parallelism, all memory access and computation fall on a subset of ranks while the remaining ranks sit idle waiting for the heavily loaded ones. Tensor parallelism instead spreads computation and weight reads evenly across all ranks at the cost of a small amount of communication, which both uses the full compute of every GPU and shortens the serial time of the heavily loaded rank. The same holds for MoE. EP requires a round of cross-GPU exchange before and after expert computation, and each step has too little computation to hide the waiting. TP only needs to reduce the expert outputs, which lowers both the communication volume and the number of synchronizations. It also splits every expert evenly across all GPUs, eliminating the load skew caused by uneven routing under EP, so the layer latency is no longer bounded by the most heavily loaded GPU.

细粒度 GEMM:让 SM 保持忙碌。Blackwell 新增的 FP8 UMMA 指令针对大矩阵设计:每条指令处理一个较大的矩阵块,与 TMA 配合时,分块粒度也较粗。在批量大小为 1 且采用 TP 切分时,矩阵维度很小,按这种粒度切分的分块无法充分利用所有 SM,导致大量计算能力和内存带宽闲置。我们模拟 m16n8k32 MMA 指令,以更细的粒度切分分块,让更多 SM 参与计算;当 token 数少于 8 时,我们会应用 swapAB,将 token 维度映射到 N 维度,以减少填充。在 TP4 解码中,这使小型 GEMM 相比 DeepGEMM 的 FP8 GEMM 最多提速 1.9 倍(2048×1024 GEMM、6 个 token:4.30 → 2.23 µs,双方均启用 PDL)。对于权重读取占主导的路由专家,我们进一步采用 W4A8 混合精度,将 FP4 权重与 FP8 激活搭配使用。与 FP8 相比,这能将权重内存流量减半,并在带宽受限时直接缩短读取时间。Fine-grained GEMM: keeping SMs busy. Blackwell’s new FP8 UMMA instructions are designed for large matrices: each instruction covers a large matrix block, and tiles are partitioned coarsely when combined with TMA. At batch size 1 with TP partitioning, matrix dimensions are very small, and tiles cut at this granularity cannot fill all SMs, leaving much of the compute and memory bandwidth idle. We emulate the m16n8k32 MMA instruction to cut tiles more finely so that more SMs participate, and when there are fewer than 8 tokens we apply swapAB, mapping the token dimension to the N dimension to reduce padding. This speeds up small GEMMs by up to 1.9× over DeepGEMM’s FP8 GEMM in TP4 decoding (a 2048×1024 GEMM with 6 tokens: 4.30 → 2.23 µs, PDL enabled for both). For routed experts, where weight reads dominate, we further adopt W4A8 mixed precision, pairing FP4 weights with FP8 activations. This halves weight memory traffic compared with FP8 and directly shortens read time under the bandwidth limit.

算子融合:通信与计算紧密衔接。模型推理涉及许多零散的小算子,例如 Norm、RoPE 和 merge。每个算子的计算开销都很小,但都需要单独承担内核启动以及中间激活读写的开销;在低延迟场景下,这些开销尤为明显。我们将相邻的小算子合并,每个解码步骤可减少数千次内核启动和内存读写。跨 GPU 通信也可以融入计算:借助对称内存,通信无需承担集合通信库的开销,只需在相邻计算内核的末尾执行少量远程写指令;数据本身即可表明数据已到达,无需额外同步。Operator fusion: tight handoff between communication and computation. Model inference involves many scattered small operators such as Norm, RoPE and merge. Each costs little to compute, yet each pays separately for kernel launch and for reading and writing intermediate activations, and these overheads are especially pronounced in low-latency scenarios. We merge adjacent small operators, removing thousands of kernel launches and memory reads and writes per decoding step. Cross-GPU communication is folded into computation as well: with symmetric memory, communication avoids the overhead of a collective-communication library and reduces to a few remote write instructions at the tail of the adjacent compute kernel, with arrival signaled by the data itself and no extra synchronization.

多流执行与 PDL:关键路径决定延迟。即使工作分配更加均衡、算子融合程度更高,推理延迟仍受限于关键路径上的串行内核启动调度。因此,我们将彼此独立的计算分派到不同流上并行执行,并限制非关键路径内核可用的 SM 数量,避免它们占用关键路径内核的资源。此外,模型前向传递中几乎所有内核都通过 PDL(程序化依赖启动)启动,使相邻内核的启动和收尾开销能够重叠。一些内核还会提前发出不依赖前序结果的内存访问,从而进一步隐藏关键路径上的串行开销。Multi-stream execution and PDL: the critical path determines latency. Even with more balanced work distribution and operator fusion, inference latency is still limited by serial kernel launch scheduling on the critical path. We therefore dispatch mutually independent computations to different streams to run in parallel, and cap the number of SMs available to off-critical-path kernels so that they do not take resources from critical-path kernels. In addition, almost all kernels in the model forward pass are launched with PDL (Programmatic Dependent Launch), so the launch and teardown overheads of adjacent kernels overlap. Some kernels also issue memory accesses that do not depend on preceding results ahead of time, further hiding serial overhead on the critical path.

注意力数据流重构:避免稀疏操作进入关键路径Attention Dataflow Restructuring: Keeping Sparse Operations off the Critical Path

ERNIE 5.5 Flash 的注意力采用 HCA 和 MLA-DSA 稀疏结构,并包含两种独特的结构设计:跨头低秩后混合(VHA post-mix),使不同头的输出能够相互交互;以及门控注意力,通过门控投影提升模型质量。VHA 引入的跨头交互也会影响注意力后处理的计算方式。ERNIE 5.5 Flash’s attention uses the HCA and MLA-DSA sparse structures and includes two distinctive structural designs: cross-head low-rank post-mixing (VHA post-mix), which lets the outputs of different heads interact, and gated attention, which uses a gating projection to improve model quality. The cross-head interaction introduced by VHA also shapes the computation of attention post-processing.

在注意力机制本身,ERNIE 5.5 Flash 超过 80% 的层使用 HCA 注意力。在传统实现中,注意力计算依赖当前层的 query,以及来自 SWA 窗口和压缩器的 keys 与 values。我们发现,压缩器只有在累积满一个压缩块的 token 后,才会生成新的压缩 keys 和 values;但它的执行链位于注意力 kernel 之前,会延迟该 kernel 的启动;与此同时,压缩器本身的 GPU 利用率也很低。因此,我们将压缩器以及依赖新压缩 KV 的那一个 KV 块上的注意力计算(late tile attention),从注意力主体中分离出来,利用空闲的 SM 在旁路 stream 上运行。随后通过轻量级的 release/acquire 信号通知主 stream 上的 combine kernel 收集结果,从而避免 kernel 级同步。这样便将压缩器移出了 HCA 层的关键路径。Within attention itself, more than 80% of ERNIE 5.5 Flash’s layers use HCA attention. In a conventional implementation, attention depends on the current layer’s query together with keys and values from both the SWA window and the compressor. We observed that the compressor produces new compressed keys and values only once it has accumulated a full compression block of tokens, yet its execution chain sits ahead of the attention kernel and delays the kernel’s launch; meanwhile, the compressor itself has very low GPU utilization. We therefore separate the compressor, together with the attention over the one KV block that depends on the newly compressed KV (late tile attention), from the main attention body and run them on a side stream using idle SMs. A lightweight release/acquire signal then notifies the combine kernel on the main stream to collect the result, avoiding kernel-level synchronization. This takes the compressor off the critical path of the HCA layer.

HCA attention pipeline before and after moving the compressor and late tile to a side stream

基于这条流水线,我们为 TP 下每个 rank 配置 16 个头设计了一种注意力内核,并将尾部块折叠处理:键/值缓存块独立调度;将查询的 RMSNorm 和 RoPE 融合到注意力序言中,并利用 TMA 隐藏其开销;将合并后的注意力输出直接广播到每个 rank,从而省去单独的通信步骤。Building on this pipeline, we designed an attention kernel for 16 heads per rank under TP that folds the tail block: key/value cache blocks are scheduled independently; the query’s RMSNorm and RoPE are fused into the attention prologue, with TMA hiding their cost; and the combined attention output is broadcast directly to every rank, eliminating a separate communication step.

VHA 后混合结构会在对注意力输出应用逆 RoPE 后,沿头维度进行线性混合。按照这一顺序,必须先将逆 RoPE 的结果写回 HBM,再由后混合阶段读入,这会造成一次无法避免的 HBM 往返。我们观察到,逆 RoPE 会在每个头内应用相同的旋转,而后混合则作用于与之正交的维度,因此根据结合律,两者可以按任意顺序执行。利用这一性质,我们交换逆 RoPE 和后混合的顺序,再将逆 RoPE 与输出投影的量化合并到后混合阶段,从而避免两次 HBM 往返。再结合 combine 内核中的跨 GPU 写回,原先因通信而彼此分离的四个后处理步骤被缩减为两个内核。The VHA post-mix structure linearly mixes across heads after inverse RoPE has been applied to the attention output. In this order, the inverse RoPE result must first be written back to HBM and then read in by post-mix, an unavoidable HBM round trip. We observed that inverse RoPE applies the same rotation within each head, while post-mix acts on an orthogonal dimension, so by associativity the two can be applied in either order. Exploiting this property, we swap the order of inverse RoPE and post-mix, and then merge inverse RoPE with the quantization for the output projection into the post-mix stage, avoiding two HBM round trips. Together with the cross-GPU write-back in the combine kernel, the four post-processing steps that were previously separated by communication are reduced to two kernels.

Swapping post-mix and inverse RoPE to fuse attention post-processing

MegaLLMoE:一种低延迟 MoE 巨型内核MegaLLMoE: A Low-Latency MoE Megakernel

在 ERNIE 5.5 Flash 的 Multi-Router Latent MoE 层中,两组路由器会为每个 token 从 512 个专家中选出 10 个。路由专家在 2048 维的潜在空间中进行计算,而共享专家则处理 4096 维的隐藏层输入。在小批量解码中,每个阶段的计算量都很小,因此内核启动、阶段间等待以及中间数据的读写会显著增加每步延迟。MegaLLMoE 将路由、专家计算和跨 GPU 规约融合到一个 CUDA 内核中,使每个 rank 只需启动一次内核即可完成整个层的前向传播。它从三个方面降低每步延迟:任务并行、专家负载均衡和跨 GPU 通信。In ERNIE 5.5 Flash’s Multi-Router Latent MoE layer, two groups of routers select 10 of 512 experts for each token. Routed experts compute in a 2048-dimensional latent space, while shared experts process the 4096-dimensional hidden input. In small-batch decoding, each stage has little computation, so kernel launches, inter-stage waiting and intermediate reads and writes noticeably increase per-step latency. MegaLLMoE fuses routing, expert computation and cross-GPU reduction into a single CUDA kernel, so each rank completes the forward pass of the whole layer with one kernel launch. It attacks per-step latency on three fronts: task parallelism, expert load balancing and cross-GPU communication.

MegaLLMoE task layout across CTAs

  • 基于数据依赖的任务编排。路由器、Latent Down 和共享专家读取相同的输入,可由不同的 CTA(线程块)并行计算。Latent Down/Up 和专家计算均支持 Split-K,以提高任务并行度,并在线程块集群内累加部分和。内核使用计数器和位图标记数据就绪状态,并通过轻量级的 release/acquire 语义实现阶段间的高效同步。
    Task orchestration by data dependency. The router, Latent Down and the shared experts read the same input and can be computed in parallel by different CTAs (thread blocks). Latent Down/Up and expert computation both support Split-K to increase task parallelism, with partial sums added within a thread block cluster. The kernel marks data readiness with counters and bitmaps and uses lightweight release/acquire semantics for efficient synchronization between stages.
  • 权重分块与动态任务调度。在小批量解码中,活跃专家处理的 token 很少,读取权重因此成为主要瓶颈。模型采用 W4A8 混合精度方案,使用 FP4 权重和 FP8 激活值,从而减少总体数据读取量。Gate 和 Up 权重以交错方式存储,由 TMA 按整块加载,再通过 UMMA 执行乘法。每 8 个 CTA 组成一组,共同处理同一个专家:组内各 CTA 沿输出通道并行计算该专家的投影;不同组之间则动态调度 Up/Gate 和 Down 任务,以均衡负载。
    Weight tiling and dynamic task scheduling. In small-batch decoding, active experts process few tokens and weight reads become the main bottleneck. The model uses a W4A8 mixed-precision scheme with FP4 weights and FP8 activations, reducing the overall amount of data read. Gate and Up weights are stored interleaved, loaded as whole blocks by TMA, and multiplied by UMMA. Groups of 8 CTAs cooperate on the same expert: within a group, CTAs compute the expert’s projection in parallel along output channels, and across groups, Up/Gate and Down tasks are scheduled dynamically to balance load.
  • 通信与计算重叠。MegaLLMoE 使用张量并行对路由专家和共享专家的 FFN 权重进行分区,在潜在空间和隐藏空间中各执行一次 AllReduce。两次归约都使用单轮 NVLS 多播,并通过 Lamport 槽位协议检测数据是否就绪。第一次归约会在路由专家的输出块就绪后逐块传输,从而使通信与其余数据块的计算重叠。
    Overlapping communication with computation. MegaLLMoE uses tensor parallelism to partition the FFN weights of both routed and shared experts, performing only one AllReduce each in the latent and hidden spaces. Both reductions use single-round NVLS multicast and detect data readiness through a Lamport slot protocol. The first reduction transfers routed-expert outputs block by block as they become ready, so communication overlaps with the computation of the remaining blocks.

单遍 mHC:通过双线性展开打破串行依赖One-Pass mHC: Breaking the Serial Dependency with Bilinear Expansion

ERNIE 5.5 Flash 使用 mHC(流形约束超连接)在各层之间构建多条残差流:每个子层的输入由残差流加权聚合并归一化得到。聚合权重和归一化尺度都依赖全局归约操作,二者形成串行数据依赖;这条两遍执行链限制了推理性能。在小批量解码中,mHC 的计算开销可以忽略,其性能几乎完全受串行归约链的延迟限制。ERNIE 5.5 Flash uses mHC (Manifold-Constrained Hyper-Connections) to build multiple residual streams across layers: the input of each sublayer is obtained by weighted aggregation and normalization of the residual streams. Both the aggregation weights and the normalization scale depend on global reductions, and the two form a serial data dependency; this two-pass execution chain limits inference performance. In small-batch decoding, mHC’s computation is negligible, and its performance is bounded almost entirely by the latency of the serial reduction chain.

内积的双线性性质提供了一种打破这种依赖关系的方法:我们将聚合结果的平方范数展开为聚合权重关于残差流格拉姆矩阵的二次型。由于格拉姆矩阵仅取决于输入,我们在计算聚合权重的同一次归约中计算它,而归一化尺度随后只需通过廉价的标量运算即可得出。这样一来,两个串行归约在代数上合并为单次遍历,mHC 不再成为瓶颈。The bilinearity of the inner product offers a way to break this dependency: we expand the squared norm of the aggregated result into a quadratic form of the aggregation weights over the Gram matrix of the residual streams. Since the Gram matrix depends only on the inputs, we compute it in the same reduction as the aggregation weights, and the normalization scale then follows from inexpensive scalar arithmetic. The two serial reductions thus merge algebraically into a single pass, and mHC is no longer a bottleneck.

One-Pass mHC removes one grid synchronization

除此之外,我们将层间跨 GPU 通信、mHC 和低精度量化融合到单个内核中,并通过对称内存将归约结果直接写入对端内存。将残差混合矩阵投影到双随机流形上的 Sinkhorn 迭代与 MoE 不存在数据依赖关系,因此我们将其安排在独立的流上并行运行,使其脱离关键路径。On top of this, we fuse the cross-GPU communication between layers, mHC and low-precision quantization into a single kernel, with reduction results written directly into peer memory through symmetric memory. The Sinkhorn iterations that project the residual mixing matrix onto the doubly stochastic manifold have no data dependency on the MoE, so we schedule them on a separate stream to run in parallel, moving them off the critical path.

DSpark 推测解码:每次前向传播生成多个词元DSpark Speculative Decoding: Multiple Tokens per Forward Pass

我们在 ERNIE 5.5 Flash 的后训练阶段引入了 DSpark,这是一种并行推测解码方案。与 MTP 逐次自回归生成一个 token 不同,DSpark 在一次前向传播中并行生成整块候选 token,因此草稿生成成本不会随推测长度线性增长。目标模型在一次前向传播中验证多个 token,这改变了关键路径上的瓶颈;为适应多 token 验证,我们相应调整了注意力和 LM head 的划分方式。每步耗时增加不到一半,而每步生成的 token 数量则成倍增长。We introduced DSpark, a parallel speculative decoding scheme, in the post-training stage of ERNIE 5.5 Flash. Unlike MTP, which drafts autoregressively one token at a time, DSpark generates a whole block of candidates in parallel in a single forward pass, so the drafting cost does not grow linearly with the speculation length. The target model verifies multiple tokens in one forward pass, which shifts the critical-path bottleneck; we adjusted the partitioning of attention and the LM head accordingly to suit multi-token verification. While per-step time increases by less than half, the number of tokens produced per step multiplies.

性能数据与复现Performance Data and Reproduction

我们使用 4 张采用 SM100 架构的 GPU,搭配 CUDA 13.0、PyTorch 2.14.1 和 HALOps 0.2.0。SGLang 是基于 PR #52603 构建的。FP4 检查点可在 Hugging Face 和 ModelScope 上获取,其中打包了 DSpark 草稿模型,因此 --model-path 和 --speculative-draft-model-path 都指向该检查点。We use 4 SM100-architecture GPUs with CUDA 13.0, PyTorch 2.14.1 and HALOps 0.2.0. SGLang is built from PR #52603. The FP4 checkpoint is available on Hugging Face and ModelScope. It bundles the DSpark draft, so both --model-path and --speculative-draft-model-path point to it.

启动服务器并按如下方式运行基准测试。设置 SGLANG_ERNIE55_LOW_LATENCY_DECODE=1 可启用低延迟后端,另外三个环境变量用于模拟 5.5 的接受长度:Launch the server and run the benchmark as follows. Setting SGLANG_ERNIE55_LOW_LATENCY_DECODE=1 enables the low-latency backend, and the other three environment variables simulate an acceptance length of 5.5:

export SGLANG_ERNIE55_LOW_LATENCY_DECODE=1
export SGLANG_SIMULATE_ACC_LEN=5.5
export SGLANG_SIMULATE_ACC_GREEDY=1
export SGLANG_DSPARK_SIMULATE_FOLD=1

python -m sglang.launch_server \
  --model-path <model_path> \
  --speculative-algorithm DSPARK \
  --speculative-draft-model-path <model_path> \
  --speculative-dspark-block-size 5 \
  --tp-size 4 --quantization fp8 --bf16-gemm-backend torch \
  --max-running-requests 1 --cuda-graph-max-bs-decode 1 \
  --mem-fraction-static 0.8 --context-length 131072 \
  --trust-remote-code --port 30085

使用 55K 个输入令牌和 1K 个输出令牌复现性能数据:Reproduce the performance data with 55K input tokens and 1K output tokens:

python -m sglang.benchmark.serving \
  --backend sglang-oai-chat --base-url http://127.0.0.1:30085 \
  --dataset-name random --dataset-path <ShareGPT_V3_unfiltered_cleaned_split.json> \
  --random-input-len 56320 --random-output-len 1024 --random-range-ratio 1.0 \
  --num-prompts 10 --max-concurrency 1 --warmup-requests 1 \
  --extra-request-body '{"ignore_eos": true, "temperature": 0.0, "top_p": 1.0, "seed": 42}'

下表展示了主要优化阶段的性能。集成 DSpark 后,数据是在模拟接受长度为 5.5 的条件下测得的。由于各项优化是逐步落地的,我们记录了每个阶段的解码速度和单步耗时。解码速度根据基准测试的平均 TPOT(每个输出 token 的耗时,不包括第一个 token)计算得出,即 1 / TPOT;单步耗时则为 TPOT 乘以接受长度。The table below shows the performance at the main optimization stages. After DSpark was integrated, data are measured at a simulated acceptance length of 5.5. Since the optimizations landed incrementally, we recorded the decoding speed and per-step time at each stage. Decoding speed is derived from the benchmark’s mean TPOT (time per output token, excluding the first token) as 1 / TPOT, and per-step time is TPOT multiplied by the acceptance length.

Optimization Per-step time (ms) Decoding speed (tokens/s)
Naive DP/EP implementation 9.80 102
Low-latency backend / TP 7.52 133
DSpark speculative decoding 10.5 524
Communication-computation fusion / multi-stream / PDL 7.27 757
One-Pass mHC / quantization fusion 6.58 836
Attention dataflow restructuring / multi-stream management 5.80 948
MegaLLMoE 5.12 1074

使用 DSpark 块大小 7(--speculative-dspark-block-size 7)并将模拟接受长度设为 7.2(SGLANG_SIMULATE_ACC_LEN=7.2)时,每步耗时上升至 5.50 毫秒,但每步生成的 token 更多,解码速度达到约 1310 token/s。With DSpark block size 7 (--speculative-dspark-block-size 7) and a simulated acceptance length of 7.2 (SGLANG_SIMULATE_ACC_LEN=7.2), the per-step time rises to 5.50 ms, but each step yields more tokens, and decoding reaches about 1310 tokens/s.

这项工作的一部分是在 AI RSI 的帮助下完成的。ERNIE Evolve 提供了许多宝贵的优化思路和实践经验,AI RSI 的能力与创造力正在重塑我们的研发方式。本文中的核心算子,包括低延迟 GEMM、MegaLLMoE 融合算子和 One-Pass mHC,均已在 HALOps 仓库中开源。该仓库还收录了我们更多用于高效 LLM 推理的高性能工作。欢迎讨论与贡献。Part of this work was done with the help of AI RSI. ERNIE Evolve contributed many valuable optimization ideas and practices, and the capability and creativity of AI RSI are reshaping how we do research and development. The core kernels in this article, including low-latency GEMM, the MegaLLMoE fused operator and One-Pass mHC, are open-sourced in the HALOps repository, which also contains more of our high-performance work for efficient LLM inference. Discussion and contributions are welcome.

致谢Acknowledgments

感谢 SGLang 社区提供高性能的开源推理框架;本文中的推测解码、CUDA Graph 和基准测试工作流均直接基于 SGLang 构建。感谢 DeepSeek 开源 FlashMLA 和 DeepGEMM,为我们的注意力和 GEMM 优化提供了起点和基线。感谢 Triton 团队,Gluon 让我们能够在 Blackwell 上快速编写并迭代通信融合内核。感谢 NVIDIA 提供 Blackwell 平台和 CUDA 生态;PDL 等特性为本文中的许多重叠优化奠定了基础。We thank the SGLang community for its high-performance open-source inference framework; the speculative decoding, CUDA Graph and benchmarking workflows in this article are built directly on SGLang. We thank DeepSeek for open-sourcing FlashMLA and DeepGEMM, which provided the starting point and baseline for our attention and GEMM optimizations. We thank the Triton team, whose Gluon let us quickly write and iterate on communication-fused kernels on Blackwell. We thank NVIDIA for the Blackwell platform and the CUDA ecosystem; features such as PDL underpin many of the overlap optimizations in this article.

值得记下

  1. 在 4 块 SM100 GPU 上,BS=1,输入 55K tokens、输出 1K tokens……在 DSpark 模拟平均接受长度为 5.5 时,解码速度达到 1074 tokens/s。
  2. 最终配置采用注意力 TP4 和 MoE TP4,在 DSpark 模拟平均接受长度为 5.5 时,解码速度达到 1074 tokens/s;当 DSpark block size 为 7、模拟接受长度为 7.2 时,速度约为 1310 tokens/s。
  3. 与 TP4 相比,最终配置将端到端平均延迟降低了 65.5%,输出吞吐量达到其 2.91×。

← 回到本期 · 第 5 条