IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).

Python function

combine_partial_attention

combine_partial_attention()​

max.nn.common_layers.context_parallel.combine_partial_attention(out, lse, dcp)

source

Merges each rank’s partial attention and returns its own heads.

Every rank attended all H heads of its DCP group over its own keys, producing out ([T, H, D]) and the per-head base-2 LSE lse ([T, H], float32). The merged output of head h is sum_r w_r * out_r with w_r = 2^(lse_r - log2(sum_s 2^lse_s)), exactly attention over the union of the ranks’ keys. Each rank sends every other rank of its group its partials for that rank’s heads in one all-to-all and merges what it receives (_combine_a2a()).

Parameters:

  • out (Tensor) – Each rank’s partial attention output, [T, H, D], over its group’s H heads: all of them when dcp is the size of the tp axis, else the group’s run of them (dcp_group_heads()).
  • lse (Tensor) – Each rank’s base-2 log-sum-exp per token and head, [T, H].
  • dcp (int) – The DCP group size, a divisor of the tp axis’s size.

Returns:

The merged output on out’s mesh, sharded over its head axis along the tp axis: each rank holds its H / dcp heads of its group’s, which are its tensor-parallel heads, ready for a head-sharded output projection. Other mesh axes keep out’s placements: each data-parallel replica merges only its own ranks.

Return type:

Tensor