vllm.v1.attention.ops.dcp_alltoall ¶
DCP All-to-All communication backend for attention.
Provides All-to-All (A2A) communication as an alternative to AllGather + ReduceScatter (AG+RS) for Decode Context Parallel (DCP). Instead of gathering the full Q tensor and scattering partial outputs, A2A exchanges partial attention outputs and their LSE values across ranks, then combines them with exact LSE-weighted reduction.
This reduces the number of NCCL calls per attention layer from 3 (AG for Q, AG for K metadata, RS for output) to 2 (A2A for output, A2A for LSE), lowering per-step communication overhead for long-context decode where NCCL latency is a significant fraction of step time.
Usage
vllm serve model --tp 16 --dcp 16 --dcp-comm-backend a2a
Reference: https://arxiv.org/abs/2507.07120
_dcp_lse_combine_kernel ¶
_dcp_lse_combine_kernel(
recv_output_ptr,
recv_lse_ptr,
out_ptr,
out_lse_ptr,
ro_stride_N,
ro_stride_B,
ro_stride_H,
ro_stride_D,
rl_stride_N,
rl_stride_B,
rl_stride_H,
o_stride_B,
o_stride_H,
o_stride_D,
N: constexpr,
HEAD_DIM: constexpr,
IS_BASE_E: constexpr,
RETURN_LSE: constexpr,
)
Triton kernel for LSE-weighted combination of partial attention outputs.
After All-to-All, each rank has: - recv_output [N, B, H_local, D]: partial outputs from all KV shards - recv_lse [N, B, H_local]: partial LSEs from all KV shards
This kernel computes the weighted combination locally (no communication).
Grid: (B, H_local) Each program handles one (batch, head) and processes all D elements.
Source code in vllm/v1/attention/ops/dcp_alltoall.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
_lse_weighted_combine ¶
_lse_weighted_combine(
outputs: Tensor,
lses: Tensor,
return_lse: bool = False,
is_lse_base_on_e: bool = True,
) -> Tensor | tuple[Tensor, Tensor]
CPU reference implementation for LSE-weighted combination.
This is a pure PyTorch implementation used for testing and validation. For GPU execution, use dcp_lse_combine_triton instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outputs | Tensor | Partial attention outputs [N, B, H, D] N = number of KV shards (ranks) B = batch size (num_tokens) H = number of heads per rank D = head dimension | required |
lses | Tensor | Log-sum-exp values [N, B, H] | required |
return_lse | bool | If True, also return the global LSE | False |
is_lse_base_on_e | bool | If True, LSE is base e; if False, base 2 | True |
Returns:
| Type | Description |
|---|---|
Tensor | tuple[Tensor, Tensor] | Combined output [B, H, D], and optionally global LSE [B, H] |
Source code in vllm/v1/attention/ops/dcp_alltoall.py
dcp_a2a_lse_reduce ¶
dcp_a2a_lse_reduce(
cp_attn_out: Tensor,
cp_attn_lse: Tensor,
cp_group: GroupCoordinator,
ctx: CPTritonContext | None = None,
return_lse: bool = False,
is_lse_base_on_e: bool = True,
) -> Tensor | tuple[Tensor, Tensor]
Combine partial attention outputs across DCP ranks using All-to-All.
Each rank holds attention output for all heads but only a local shard of the KV cache. This function: 1. Exchanges partial outputs across ranks via All-to-All 2. Exchanges LSE values via All-to-All 3. Combines them with exact LSE-weighted reduction (Triton kernel)
Tensor flow
Input: cp_attn_out [B, H, D] - all heads, local KV shard Reshape: [N, B, H/N, D] - split heads across ranks A2A: Two all_to_all_single calls (output and LSE) Combine: recv [N, B, H/N, D] + lse [N, B, H/N] -> [B, H/N, D]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cp_attn_out | Tensor | [B, H, D] where B=num_tokens, H=total_heads, D=head_dim | required |
cp_attn_lse | Tensor | [B, H] log-sum-exp values (fp32) | required |
cp_group | GroupCoordinator | GroupCoordinator for DCP communication | required |
ctx | CPTritonContext | None | CPTritonContext (unused, for signature compatibility) | None |
return_lse | bool | If True, also return the combined global LSE | False |
is_lse_base_on_e | bool | If True, LSE is base e; if False, base 2 | True |
Returns:
| Type | Description |
|---|---|
Tensor | tuple[Tensor, Tensor] | Combined output [B, H/N, D] (head-scattered) |
Tensor | tuple[Tensor, Tensor] | If return_lse=True, also returns global_lse [B, H/N] |
Source code in vllm/v1/attention/ops/dcp_alltoall.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
dcp_lse_combine_triton ¶
dcp_lse_combine_triton(
recv_output: Tensor,
recv_lse: Tensor,
return_lse: bool = False,
is_lse_base_on_e: bool = True,
) -> Tensor | tuple[Tensor, Tensor]
Triton-accelerated LSE-weighted combination for DCP A2A.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recv_output | Tensor | [N, B, H_local, D] - partial outputs from all KV shards | required |
recv_lse | Tensor | [N, B, H_local] - partial LSEs from all KV shards | required |
return_lse | bool | If True, also return the global LSE | False |
is_lse_base_on_e | bool | If True, LSE is base e; if False, base 2 | True |
Returns:
| Type | Description |
|---|---|
Tensor | tuple[Tensor, Tensor] | Combined output [B, H_local, D] |
Tensor | tuple[Tensor, Tensor] | If return_lse=True, also returns global_lse [B, H_local] |