vllm.model_executor.models.transformers.sequence_parallel
¶
Sequence parallelism and async TP for the Transformers modeling backend.
The residual stream is sharded across TP ranks along the token dimension between the first and last decoder layer of each pipeline stage. Each child of a decoder layer that reduces across TP (attention, MLP, MoE, etc.) is a region that all-gathers its input and reduce-scatters its output instead of all-reducing it. Everything inside a region sees every token, and everything outside (norms, residual adds) only sees this rank's tokens.
With async TP, a region whose input feeds unquantized column parallel linears, or whose output is an unquantized row parallel linear, fuses the collective into those GEMMs using symmetric memory.
Classes:
-
AsyncTPAllGatherMatmul–Returns the output its region computed in
fused_all_gather_matmul. -
AsyncTPMatmulReduceScatter–GEMM and reduce-scatter the tokens in one overlapped op.
-
Region–A child of a decoder layer that reduces across TP, so sees every token.
Functions:
-
pad_tokens–Pad
xalongdimso that its size is a multiple ofmultiple. -
warn_if_mixing_tokens–Warn if
layermay mix tokens outside its regions, where they are sharded.
_ADDITIVE_OPS = frozenset({'add', 'add_', 'iadd', 'sub', 'sub_', 'isub', 'cat', 'stack'})
module-attribute
¶
Ops whose output is a partial sum if all their tensor inputs are.
_PASSTHROUGH_OPS = frozenset({'reshape', 'view', 'contiguous', 'transpose', 'permute', 'flatten', 'squeeze', 'unsqueeze', 'expand', 'clone', 'neg', 'getitem', 'split', 'chunk', 'dropout', 'to', 'float', 'half', 'bfloat16', 'type_as'})
module-attribute
¶
Ops whose output is a partial sum if their first input is.
_SCALING_OPS = frozenset({'mul', 'mul_', 'imul', 'truediv', 'div', 'div_'})
module-attribute
¶
Ops whose output is a partial sum if exactly one input is (the numerator).
AsyncTPAllGatherMatmul
¶
Bases: UnquantizedLinearMethod
Returns the output its region computed in fused_all_gather_matmul.
Attributes:
-
pending(Tensor | None) –The output computed from the region's input, which is this linear's input.
Source code in vllm/model_executor/models/transformers/sequence_parallel.py
pending = None
class-attribute
instance-attribute
¶
The output computed from the region's input, which is this linear's input.
AsyncTPMatmulReduceScatter
¶
Bases: UnquantizedLinearMethod
GEMM and reduce-scatter the tokens in one overlapped op.
Source code in vllm/model_executor/models/transformers/sequence_parallel.py
Region
¶
A child of a decoder layer that reduces across TP, so sees every token.
Attributes:
-
gather_linears(list[ColumnParallelLinear]) –Column parallel linears fused with the input all-gather.
-
scatter_linear(RowParallelLinear | None) –Row parallel linear fused with the output reduce-scatter.
Source code in vllm/model_executor/models/transformers/sequence_parallel.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 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 | |
_check_partial_output(module, reducers)
¶
Check that module returns the sum of its reducers' partial outputs.
Reducers skip their TP all-reduce under sequence parallelism, so only ops that commute with the sum across ranks may act on their outputs before the region's reduce-scatter.
Raises:
-
ValueError–If an op that does not commute with the sum is applied.
-
_Unverifiable–If
modulecould not be traced completely.
Source code in vllm/model_executor/models/transformers/sequence_parallel.py
_map_input(args, kwargs, fn)
¶
Apply fn to a module's first input, the hidden states.
Source code in vllm/model_executor/models/transformers/sequence_parallel.py
_map_output(output, fn)
¶
Apply fn to a module's first output, the hidden states.
_returned_module(graph, module)
¶
The submodule whose output module returns, if returned unmodified.
Source code in vllm/model_executor/models/transformers/sequence_parallel.py
pad_tokens(x, dim, multiple)
¶
Pad x along dim so that its size is a multiple of multiple.
Source code in vllm/model_executor/models/transformers/sequence_parallel.py
warn_if_mixing_tokens(layer, is_region)
¶
Warn if layer may mix tokens outside its regions, where they are sharded.