nemo_automodel.components.models.hy_v4_flash.engram
nemo_automodel.components.models.hy_v4_flash.engram
Hy4-flash Engram: hashed bigram / trigram memory added to the hyper-connection streams.
The hash, the per-head norms and the gate follow the transformers reference (HYV4FlashEngramLayer); the table is
the shared row-owner-sharded embedding of Qwen3.8-Flash-Next (one ~32 GB table per layer, sharded by rows across the
owner group, lookups by all-to-all). Parameters keep the reference’s names; the forward stacks the per-head weights
so each norm and projection runs as one kernel.
Precision: the weighted norms are evaluated as the reference’s nn.RMSNorm. The gate, and the sum of the gated
signal and the per-stream branch, are evaluated in fp32 and cast back, where the reference stays in BF16; in fp32
the two are identical.
Module Contents
Classes
Functions
API
Bases: Module
One Engram block (decoder layer layer_idx, one-based id layer_idx + 1).
Parameters:
Text configuration.
Zero-based decoder layer index; must satisfy layer_idx + 1 in config.engram_layer_ids.
Row-owner group of the table; None builds the whole table locally (tests, tiny configs).
Parameter dtype.
Identity of the current lookup-table contents without reading them: storage address and version counter.
Any way a checkpoint can reach the buffer changes one of the two: an in-place write (load_state_dict,
copy_) bumps the version, a replaced or moved buffer has a new address. Weight initialization runs
before the checkpoint is loaded, so multipliers drawn at initialization must not be kept once the frozen
vocabulary map arrives; comparing this state on every forward costs no device read.
Return the update to add to streams [batch, sequence, hc_mult, hidden] (same shape and dtype).
ngram_tokens is an integer tensor [batch, sequence, max_ngram_size]; positions where engram_mask
[batch, sequence] is False (image / padding) get zero.
Mix shifted token ids into one global table row per hash head.
Parameters:
Integer tensor of shape [batch, sequence, max_ngram_size], newest token first.
Returns: torch.Tensor
int64 tensor of shape [batch, sequence, num_heads] of rows of the layer’s flat table, n-gram-order major.
Initialize as the reference does and refresh the hash state.
unified_pre_gamma is 1 and the per-stream scales are drawn from N(0, 0.006).
Re-draw the hash multipliers from the loaded lookup table.
The multipliers are bounded by the number of distinct compressed ids, which is max(lookup_table) + 1
of the checkpoint’s frozen vocabulary map (the reference draws them after loading for the same reason).
Bases: Module
Holder of an RMSNorm weight whose epsilon is the dtype epsilon (nn.RMSNorm(eps=None) semantics).
Stack each token with the max_ngram_size - 1 tokens before it.
Positions that reach before the start of their document read pad_id; the document start is where the
leading (time) position plane restarts, so n-grams never span two packed documents.
Parameters:
Integer tensor of shape [batch, sequence].
Integer tensor of shape [batch, sequence], the time plane of the position ids.
Longest n-gram order.
Id used for missing history.
Returns: torch.Tensor
Integer tensor of shape [batch, sequence, max_ngram_size], newest token first.
Odd multipliers an n-gram is mixed with, drawn as the memory was built.
NumPy’s default generator seeded with seed + 10007 * layer_id (layer_id is the one-based id used in the
config) draws max_ngram_size values bounded so a product with any compressed id stays within int64.
Returns: torch.Tensor
int64 tensor of shape [max_ngram_size].
Apply one weighted RMSNorm per slice of the second-to-last axis, as torch.nn.RMSNorm evaluates it.
The normalization and the multiplication by the weight both run in fp32 and the result is cast once (for a
BF16 input F.rms_norm(x) * weight would round before the weight is applied).
Parameters:
Tensor of shape […, slices, features].
slices modules, each holding a weight of shape [features].
Returns: torch.Tensor
Tensor of the shape and dtype of x.