nemo_automodel.components.models.qwen3_8_flash_next.engram
nemo_automodel.components.models.qwen3_8_flash_next.engram
Qwen3.8-Flash-Next raw-token Engram N-gram Embedding lookup (ple in the checkpoint config).
Module Contents
Classes
Functions
Data
QWEN3_8_FLASH_NEXT_LAYER_MULTIPLIERS
QWEN3_8_FLASH_NEXT_NGRAM_HEAD_OFFSETS
QWEN3_8_FLASH_NEXT_NGRAM_HEAD_VOCAB_SIZES
QWEN3_8_FLASH_NEXT_NGRAM_PADDED_ROWS
API
Declarative shape and initialization settings for the PLE embedding table.
Parameters:
Globally padded number of table rows. It must be divisible by the owner process-group size.
Number of values stored in each row.
Standard deviation for checkpoint-free normal initialization.
Build a local or row-owner-sharded embedding table.
Parameters:
Runtime owner group. Explicitly pass None only
for a single-rank reference table containing all global rows.
Omitting this argument is intentionally an error, preventing a
full 102.4 GB table from being allocated accidentally.
Device on which the rank-local weight of shape
[local_rows, embedding_dim] is allocated.
Data type of the rank-local weight tensor.
Returns: Qwen3_8_FlashNextOwnerShardedEmbedding
An embedding whose input has shape [...] and whose output has
Bases: Module
Hash raw token IDs into the packed Qwen3.8-Flash-Next PLE table.
The first heads_per_ngram heads hash bigrams, the next group hashes
trigrams, and so on. Previous-token context resets after an EOS token.
Hashing intentionally uses signed int64 overflow, positive remainders, and
the checkpoint-provided global head offsets. It does not canonicalize or
compress tokenizer IDs as the original DeepSeek Engram implementation does.
Parameters:
Lookup module accepting global row IDs of shape
[batch, sequence, ngram_heads] and returning values of shape
[batch, sequence, ngram_heads, head_dim].
Largest n-gram order, including the current token.
Number of hash heads for every order from two through
ngram_size.
Raw tokenizer ID that terminates the preceding segment.
Signed int64 multipliers of shape [ngram_size].
Prime modulus for each hash head, shape
[(ngram_size - 1) * heads_per_ngram].
Global packed-table row offset for each hash head,
with the same shape as ngram_heads_vocab_sizes.
Hash a complete raw sequence, then look up only one local slice.
Parameters:
Replicated raw IDs of shape [batch, global_sequence]. Hashing the full tensor preserves the two
preceding raw tokens and EOS resets at a CP boundary.
Inclusive global position of the requested shard.
Exclusive global position of the requested shard.
Returns: torch.Tensor
Local PLE values of shape “[batch, local_sequence,
Compute packed global table rows for every n-gram head.
Parameters:
Raw integer tokenizer IDs of shape [batch, sequence].
Returns: torch.Tensor
Global table IDs of shape [batch, sequence, ngram_heads]. Heads
Look up precomputed packed n-gram table rows.
Parameters:
Global table row IDs of shape [batch, sequence, ngram_heads].
Returns: torch.Tensor
Concatenated head values of shape “[batch, sequence,
Read an earlier token without crossing an EOS boundary.
Parameters:
Raw tokenizer IDs of shape [batch, sequence].
Number of preceding positions to read.
Returns: torch.Tensor
Raw IDs of shape [batch, sequence]. Positions lacking valid
Return concatenated PLE table values for raw token IDs.
Parameters:
Raw integer tokenizer IDs of shape [batch, sequence].
Returns: torch.Tensor
Tensor of shape [batch, sequence, ngram_heads * head_dim]. The
Bases: Module
Trainable contiguous row-owner embedding with bidirectional All-to-All.
Rank r owns rows [r * local_rows, (r + 1) * local_rows). Each
request rank groups global row IDs by owner and sends them in the first
All-to-All. Owners perform a local embedding lookup. An autograd-aware
second All-to-All returns values to request ranks and reverses direction in
backward, so only the owner accumulates and updates a row’s gradient.
Parameters:
Global table shape and initialization settings.
Runtime owner group. None stores the complete table
locally and performs no collectives.
Device for the local weight of shape
[num_embeddings / owner_world_size, embedding_dim].
Data type of the local weight tensor.
Send global row IDs to their contiguous row owners.
Parameters:
Tensor of shape [request_rows] grouped by
destination owner rank.
Tensor of shape [owner_world_size] containing the
number of IDs sent to each owner.
Returns: torch.Tensor
A tuple containing owner-local received IDs of shape
Validate IDs symmetrically before any variable-sized collective.
Parameters:
Integer tensor of shape [...] containing global,
packed-table row IDs.
Collectively validate that routed IDs belong to this row owner.
Every rank first contributes its local bad-ID count to an AllReduce. Consequently, all ranks take the same success or failure branch even when only one owner received a misrouted ID. On failure, a compact fixed-size diagnostic from every owner is gathered before raising, so the exception identifies the failing owner rank(s) without leaving peers to enter the value-return All-to-All.
Parameters:
Global row IDs received from request ranks, with
shape [owned_requests].
Number of received IDs from each source owner group rank, in source-rank order.
Raises:
RuntimeError: If any owner received an ID outside its contiguous global row range.
Symmetrically verify compact destination segments before routing.
Parameters:
Tensor of shape [request_rows] containing
global IDs grouped by contiguous owner rank.
Tensor of shape [owner_world_size] containing one
request count per destination owner.
Raises:
RuntimeError: If any request rank’s segment contains an ID owned by a different destination rank.
Look up arbitrary global rows while keeping weights on row owners.
Parameters:
Integer tensor of shape [...] containing global row
IDs in the packed multi-head table.
Returns: torch.Tensor
Tensor of shape [..., embedding_dim] in the original request
Stamp the model-owned contract on the current weight.
Meta materialization and dtype casting can replace the Parameter object, and custom tensor attributes do not survive that replacement, so the top-level model calls this again afterwards. The single-rank reference table (plain Parameter, no process group) needs no contract.
Represent the already-local owner shard as one global DTensor.
The local storage is already the final contiguous row shard, so this
method uses :meth:DTensor.from_local rather than redistributing or
slicing it again. It runs before FSDP records its ignored parameters;
the returned parameter identity must be passed unchanged to every FSDP
unit containing the table.
Parameters:
One-dimensional FSDP shard/CP mesh. Its rank order must exactly match the PLE owner process group.
Returns: nn.Parameter
The registered global [num_embeddings, embedding_dim] DTensor
Initialize the rank-local weight with a finite normal distribution.
Bases: Module
Contextualize Qwen3.8-Flash-Next n-gram values and return an HC-sized delta.
Parameters:
Raw-token n-gram embedding whose output has shape
[batch, sequence, ple_embed_dim].
Width of one HyperConnection branch.
Number of persistent HyperConnection branches.
Concatenated n-gram embedding width.
Backend configuration for the key and value projections.
Explicit parameter dtype resolved from the model configuration.
Kernel width of the causal depthwise convolution.
Variance epsilon for branch-local Gemma RMS norms.
Apply a flattened grouped norm while retaining explicit HC branches.
Parameters:
Grouped normalization module with a learned weight of shape
[hc_count * hidden_size].
Tensor of shape
[batch, sequence, hc_count, hidden_size].
Returns: torch.Tensor
Branch-normalized tensor of shape
Apply the PLE causal depthwise convolution with left zero history.
Parameters:
Branch-flattened tensor of shape
[batch, sequence, hc_count * hidden_size].
Optional contiguous CP metadata. Under CP, sequence
is local and the method exchanges only the preceding nine-token
boundary required by the released dilation/kernel settings.
Returns: torch.Tensor
Tensor of shape [batch, sequence, hc_count * hidden_size].
Compute the PLE delta injected before the layer’s attention HC read.
Parameters:
True HyperConnection state of shape
[batch, sequence, hc_count * hidden_size].
Raw integer tokenizer IDs of shape [batch, sequence].
Optional contiguous CP metadata. Its replicated
global_input_ids and global_padding_mask fields have
shape [batch, global_sequence]; hidden_states and
input_ids remain local [batch, sequence, ...] tensors.
Returns: torch.Tensor
PLE delta of shape
Initialize PLE projections and the zero-start causal convolution.
Parameters:
Standard deviation for projection weights.
Bases: Function
Autograd-aware equal-split All-to-All for compact routed values.
Route output gradients back to the ranks that supplied the rows.
Parameters:
PyTorch autograd context populated by :meth:forward.
Tensor of shape [output_rows, ...] with the same
source-rank segmentation as the forward output.
Returns: torch.Tensor
A gradient tensor of shape [input_rows, ...] followed by four
Exchange compact rows through fixed-capacity peer segments.
Parameters:
PyTorch autograd context.
Tensor of shape [input_rows, ...]. Axis 0 contains
contiguous per-destination segments described by
input_split_sizes; arbitrary trailing dimensions are kept.
Number of rows sent to every destination rank.
Number of rows received from every source rank.
Global maximum peer-segment row count.
Process group whose rank order defines both split tuples.
Returns: torch.Tensor
Tensor of shape [output_rows, ...], where
Exchange compact rank segments through an equal-split All-to-All.
Padding every peer segment to one globally agreed capacity removes backend-specific uneven-split behavior and gives forward and backward the same symmetric exchange metadata. The compact, source-ordered result expected by the owner lookup is restored after the collective. Transport provider selection remains an independent runtime concern.
Parameters:
Compact tensor of shape [sum(input_split_sizes), ...]
whose axis-0 segments are ordered by destination rank.
Number of rows sent to every destination rank.
Number of rows received from every source rank.
Globally agreed maximum of every source/destination count.
Process group whose rank order defines both count tuples.
Value used for padded and initially untouched output rows.
Returns: torch.Tensor
A compact tensor of shape [sum(output_split_sizes), ...] whose