nemo_automodel.components.models.mistral_large4.context_parallel
nemo_automodel.components.models.mistral_large4.context_parallel
Contiguous CP batch preparation and differentiable key transport for Large 4.
Module Contents
Functions
Data
API
Gather [local_tokens, …] tensors to [CP * local_tokens, …] in rank order.
Local token counts must agree. Differentiable transport sums remote-query contributions back to each key owner; parameter averaging remains FSDP-owned.
Prepare contiguous CP shards with positions computed before partitioning.
Parameters:
Global BSHD token tensors [batch, sequence, …] and optional complete image tensors [channels, height, width]. THD uses one packed row per microbatch, with seq_lens/seq_lens_padded document lengths.
Positive number of PP microbatches along the batch axis.
Whether to shard IDs/embeddings here. False keeps them global for image splicing and per-microbatch sharding in forward.
Returns: dict[str, ContextParallelSharder]
Mapping containing the model-owned ContextParallelSharder. Labels,
Preserve packed documents while preparing contiguous model-owned CP.
Parameters:
Global IDs/labels/positions [chunks, sequence], document lengths [chunks, documents], and optional complete images [channels, height, width]. Exactly one packed row belongs to each PP microbatch.
Positive number of independent pipeline microbatches; one without PP.
False retains global IDs until complete-image splicing and/or stage-zero embedding; True shards text IDs here.
Returns: dict[str, ContextParallelSharder]
Sharder yielding local IDs/labels/positions/padding/document IDs
Compute HF shifted CE across shard boundaries, scaled for FSDP CP averaging.
Parameters:
FP32 capped logits [batch, local_sequence, vocab].
Integer unshifted labels [batch, local_sequence].
Boolean flattened local [batch * local_sequence] keep mask.
CP mesh; peers must hold shards of the same padded global batch.
Returns: torch.Tensor
Local loss sum times CP / global valid-target count, a differentiable