nemo_automodel.components.models.glm5_next.cp
nemo_automodel.components.models.glm5_next.cp
Contiguous packed context parallelism for GLM-5.3-Flash.
Kimi Delta Attention carries recurrent and short-convolution state from left to right, so the generic load-balanced CP permutation is not valid. This module keeps one contiguous token interval per CP rank and one global document-id map that both KDA and KPool-DSA consume.
Module Contents
Classes
Functions
Data
API
Global packed-document layout for one model step.
Return whether the sequence is split across more than one rank.
Return document ids [batch, local_sequence] for this rank.
Return the padded local sequence length.
Return device/CPU segment boundaries for one packed batch row.
Bases: Function
Return zero while retaining a backward edge to a gathered tensor.
Bases: Function
Autograd-aware all-gather of equal contiguous sequence shards.
Resolve the global document map before removing packing metadata.
Restore the placeholder batch axis used by THD VLM collaters.
Create a zero-valued dependency that keeps gather backward collective-safe.
Gather a sequence-sharded tensor while preserving K/V gradient flow.
Build FLA’s KDA context for one batch row.
Parameters:
Global document layout.
Batch row being executed.
Context-parallel process group.
Short-convolution width used for the left halo.
Returns:
FLA FLACPContext carrying segment and process-group metadata.
Convert cumulative document boundaries to ids [1, sequence].
Convert per-document lengths [batch, documents] to ids [batch, sequence].
Return boundaries for consecutive document-id runs covering the full row.
Contiguously shard packed GLM-5.3 token streams.
The top-level VLM uses shard_primary=False: image features must be
spliced into the full embedding sequence inside forward before that
differentiable primary stream is sliced. Labels and other no-grad token
streams are still sharded here.
Parameters:
One-dimensional CP mesh or None.
Unused tensor-parallel mesh, accepted by the sharder protocol.
Batch containing token tensors with shape [batch, sequence].
Optional loss mask [batch, sequence].
Fill value for padded token ids.
Whether to shard input_ids in this function.
Returns:
Context factory, mutated local batch, and the global shard layout.