nemo_automodel.components.models.qwen3_8_flash_next.cp
nemo_automodel.components.models.qwen3_8_flash_next.cp
Contiguous context parallelism for the language-only Qwen3.8-Flash-Next model.
Module Contents
Classes
Functions
Data
API
Per-forward metadata for Qwen3.8-Flash-Next’s contiguous CP sequence shard.
Return the padded global physical sequence length.
Return logical right-padded lengths as int64 [batch].
Return the exclusive global end of this rank’s sequence shard.
Validate the replicated metadata and contiguous rank mapping.
Right-pad a rank-two token tensor to length.
Parameters:
Tensor of shape [batch, sequence].
Requested output sequence length, no shorter than sequence.
Scalar fill value for appended positions.
Returns: torch.Tensor
Tensor of shape [batch, length]. The input is returned unchanged
Validate and normalize a full-sequence token-validity mask.
Parameters:
Binary validity tensor of shape [batch, global_sequence].
Raw IDs of shape [batch, global_sequence] whose axes
establish the expected mask shape and device.
Returns: torch.Tensor
Boolean validity tensor of shape [batch, global_sequence] on the
Convert loader seq_lens metadata to physical document boundaries.
The THD packer concatenates documents contiguously and pads only the pack
tail, so physical boundaries follow the REAL lengths (seq_lens); the
loader’s seq_lens_padded is TE-specific virtual-layout metadata and
must not be used for physical offsets. When total_tokens exceeds the
packed length, the trailing pack padding becomes its own segment so pad
tokens never join a real document.
Parameters:
Real per-document lengths [num_docs] or [1, num_docs].
Physical row length including trailing pack padding.
Filler value marking unused length slots.
Returns: torch.Tensor
int64 boundaries [num_docs (+1 pad segment) + 1] starting at zero.
Gather equal contiguous sequence shards in global rank order.
Parameters:
Local tensor whose sequence_dim axis has length
context.local_sequence_length (or a fixed compressed fraction
of it shared by every rank). All non-sequence axes are replicated
in shape across the CP group.
Qwen3.8-Flash-Next contiguous CP metadata.
Axis on which rank-ordered parts are concatenated.
Use PyTorch’s autograd-aware collective. Set False
only for frozen routing values or integer metadata.
Returns: torch.Tensor
Tensor with the same axis order as tensor and a sequence_dim
Collect only the preceding causal boundary needed by a local operator.
Every rank contributes at most history trailing tokens. Autograd-aware
All-Gather routes gradients from a later rank’s halo use back to the rank
that owns those tokens. Rank zero and globally short prefixes are zero
padded on the left.
Parameters:
Local sequence tensor of shape [batch, local_sequence, channels] using contiguous rank order.
Qwen3.8-Flash-Next contiguous CP metadata.
Number of immediately preceding global tokens required.
Returns: torch.Tensor
Left context of shape [batch, history, channels]. The result does
Validate, pad, and contiguously shard a Qwen3.8-Flash-Next text batch.
Parameters:
One-dimensional CP device mesh. Rank r owns the contiguous
global interval [r * local_sequence, (r + 1) * local_sequence).
Optional TP device mesh. Qwen3.8-Flash-Next CP requires this mesh to be absent or size one.
Mutable full-sequence batch. input_ids, labels, and
optional attention_mask/padding_mask have shape [batch, global_sequence]; position_ids has shape [batch, global_sequence]. A packed THD row uses batch size one plus
cu_seqlens or loader seq_lens document boundaries; packed
attention and padding masks remain unsupported.
Optional tensor of shape [batch, global_sequence] used
by the shared sharder when labels are absent.
Raw token ID appended for CP divisibility.
Required multiple of every rank’s local sequence length. QSA requires its compression ratio, four for the released model.
Returns: Callable[[], contextlib.AbstractContextManager[Any]]
A null context factory, the mutated batch containing local token