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)
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’sHheads: all of them whendcpis the size of thetpaxis, 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
tpaxis’s size.
- out (Tensor) – Each rank’s partial attention output,
-
Returns:
-
The merged output on
out’s mesh, sharded over its head axis along thetpaxis: each rank holds itsH / dcpheads of its group’s, which are its tensor-parallel heads, ready for a head-sharded output projection. Other mesh axes keepout’s placements: each data-parallel replica merges only its own ranks. -
Return type: