Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
99d5517
Add Engram contrib op schemas
Copilot Aug 25, 2026
b44523f
Add CPU Engram contrib kernels
Copilot Aug 25, 2026
819e695
Add CUDA Engram contrib kernels
Copilot Aug 25, 2026
608c54f
Add WebGPU Engram contrib kernels
Copilot Aug 25, 2026
3ad3490
Add Engram contrib op tests
Copilot Aug 25, 2026
3fd904b
Fix Engram CPU threadpool usage
Copilot Aug 25, 2026
1c82a47
Split Engram ops into standalone files
Copilot Aug 25, 2026
b8a41e7
Add CPU FP16 Engram kernels, shared EP helpers, and docs
Copilot Aug 25, 2026
fcb7ca0
Rename NgramHashMapping to NGramHashMapping
Copilot Aug 25, 2026
2ddc306
Address PR review: shared-gate/RMS passes and sign(0) fix for Engram ops
Copilot Aug 25, 2026
e22b5c8
Fix CI failures: CUDA GetComputeStream, WebGPU namespace, test skip trap
Copilot Aug 26, 2026
aaad3f7
Address review: preprojected EngramGate inputs, cross-invocation stat…
Copilot Aug 27, 2026
4c54142
Add WebGPU state kernels, equivalence tests, and regenerated contrib …
Copilot Aug 27, 2026
913a4f4
Write present_state on the empty-sequence path in all ShortConv EPs
Copilot Aug 27, 2026
0cd1275
Update OperatorKernels.md for the new Engram op signatures
Copilot Aug 27, 2026
fb32151
Address review: raw ShortConv state, engram_helper rename, exact mult…
Copilot Aug 28, 2026
8e89bcf
Remove unused chunk_config local in ShortConv chunked test (-Werror fix)
Copilot Aug 28, 2026
3749862
Vectorize WebGPU Engram shaders and cover int32 chunked n-gram path
Copilot Aug 31, 2026
ec7bcd6
Address review: validate vocab_sizes, temp allocator + loop hoisting,…
Copilot Sep 1, 2026
b907fdf
Remove ShortConv op; use CausalConvWithState instead
Copilot Sep 1, 2026
fe54d5c
Clarify multipliers/vocab_sizes descriptions as conventions, not cons…
Copilot Sep 1, 2026
c70e9d0
Add dilation attribute to CausalConvWithState schema and CPU kernel
Copilot Sep 1, 2026
772561e
Add dilation support to CausalConvWithState CUDA/WebGPU kernels, test…
Copilot Sep 1, 2026
a6d194e
Changes before error encountered
Copilot Sep 1, 2026
8d512ca
Add channels_last support to CausalConvWithState CPU/CUDA/WebGPU kernels
Copilot Sep 1, 2026
45de634
Add dilation support to VarlenCausalConvWithState CUDA kernels
Copilot Sep 1, 2026
3b15c9c
Add CUDA EP coverage, channels_last and varlen dilation tests, and up…
Copilot Sep 1, 2026
7fff3ae
Document why the varlen state shift is one sample regardless of dilation
Copilot Sep 1, 2026
698dbf7
Merge remote-tracking branch 'origin/main' into copilot/add-op-suppor…
Copilot Sep 1, 2026
608d15f
Define the missing MakeRamp test helper in engram_ops_test.cc
Copilot Sep 1, 2026
b90057d
Make NGramHashMapping past/present aliasing safe; fix CPU/WGSL review…
Copilot Sep 1, 2026
9cfee6b
Add channels-last CUDA prefill kernel and close review coverage gaps
Copilot Sep 1, 2026
a30e067
Close the 9cfee6b review round: WebGPU MayInplace + bounds guard, in-…
Copilot Sep 2, 2026
b81719f
Remove now-unused MakeRamp test helper
Copilot Sep 2, 2026
6e766f9
Get libuuid from vcpkg for the Linux CoreML EP build
Copilot Sep 2, 2026
d443828
Skip the WebGPU in-place test when the provider is unavailable
Copilot Sep 2, 2026
fb18029
Read aliased NGram history through the present_ids binding on WebGPU
Copilot Sep 2, 2026
68f3a4b
Run the lint jobs on a Python version cached on the runner pool
Copilot Sep 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 197 additions & 0 deletions docs/ContribOperators.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Do not modify directly.*
* <a href="#com.microsoft.DynamicTimeWarping">com.microsoft.DynamicTimeWarping</a>
* <a href="#com.microsoft.EPContext">com.microsoft.EPContext</a>
* <a href="#com.microsoft.EmbedLayerNormalization">com.microsoft.EmbedLayerNormalization</a>
* <a href="#com.microsoft.EngramGate">com.microsoft.EngramGate</a>
* <a href="#com.microsoft.ExpandDims">com.microsoft.ExpandDims</a>
* <a href="#com.microsoft.FastGelu">com.microsoft.FastGelu</a>
* <a href="#com.microsoft.FusedConv">com.microsoft.FusedConv</a>
Expand Down Expand Up @@ -70,6 +71,7 @@ Do not modify directly.*
* <a href="#com.microsoft.MulInteger">com.microsoft.MulInteger</a>
* <a href="#com.microsoft.MultiHeadAttention">com.microsoft.MultiHeadAttention</a>
* <a href="#com.microsoft.MurmurHash3">com.microsoft.MurmurHash3</a>
* <a href="#com.microsoft.NGramHashMapping">com.microsoft.NGramHashMapping</a>
* <a href="#com.microsoft.NGramRepeatBlock">com.microsoft.NGramRepeatBlock</a>
* <a href="#com.microsoft.NhwcConv">com.microsoft.NhwcConv</a>
* <a href="#com.microsoft.NhwcFusedConv">com.microsoft.NhwcFusedConv</a>
Expand Down Expand Up @@ -110,6 +112,7 @@ Do not modify directly.*
* <a href="#com.microsoft.RotaryEmbedding">com.microsoft.RotaryEmbedding</a>
* <a href="#com.microsoft.SampleOp">com.microsoft.SampleOp</a>
* <a href="#com.microsoft.Sampling">com.microsoft.Sampling</a>
* <a href="#com.microsoft.ShortConv">com.microsoft.ShortConv</a>
* <a href="#com.microsoft.SkipGroupNorm">com.microsoft.SkipGroupNorm</a>
* <a href="#com.microsoft.SkipLayerNormalization">com.microsoft.SkipLayerNormalization</a>
* <a href="#com.microsoft.SkipSimplifiedLayerNormalization">com.microsoft.SkipSimplifiedLayerNormalization</a>
Expand Down Expand Up @@ -1771,6 +1774,66 @@ This version of the operator has been available since version 1 of the 'com.micr
</dl>


### <a name="com.microsoft.EngramGate"></a><a name="com.microsoft.engramgate">**com.microsoft.EngramGate**</a>

Fuses the Engram gate.

The op consumes already projected keys in (batch_size, sequence_length, hc_mult, hidden_size) layout,
the hidden-state queries in the same layout, an already projected value in
(batch_size, sequence_length, hidden_size) layout that is shared by every hyper-connection, and the two
RMSNorm scales. The key and value projections stay outside the op so they can run on the execution
provider's tuned MatMul (weight prepacking, tensor cores, quantized weights) and so the value
projection is computed once per token instead of once per hyper-connection.

It computes the Engram gate:

gate = sigmoid(sign(dot) * sqrt(max(abs(dot), 1e-6))) where
dot = sum(RMSNorm(key) * RMSNorm(query)) / sqrt(hidden_size).

The output is gate * value, broadcast across the hyper-connections. A following ShortConv plus Add
represents the final Engram residual value + short_conv(value).

#### Version

This version of the operator has been available since version 1 of the 'com.microsoft' operator set.

#### Attributes

<dl>
<dt><tt>epsilon</tt> : float</dt>
<dd>Epsilon used by both RMS normalization steps. Default is 1e-5.</dd>
</dl>

#### Inputs

<dl>
<dt><tt>key</tt> : T</dt>
<dd>Projected Engram keys with shape (batch_size, sequence_length, hc_mult, hidden_size).</dd>
<dt><tt>query</tt> : T</dt>
<dd>Hidden-state queries with shape (batch_size, sequence_length, hc_mult, hidden_size).</dd>
<dt><tt>value</tt> : T</dt>
<dd>Projected Engram value shared by every hyper-connection, with shape (batch_size, sequence_length, hidden_size).</dd>
<dt><tt>key_norm_scale</tt> : T</dt>
<dd>RMSNorm scale for keys with shape (hc_mult, hidden_size).</dd>
<dt><tt>query_norm_scale</tt> : T</dt>
<dd>RMSNorm scale for queries with shape (hc_mult, hidden_size).</dd>
</dl>

#### Outputs

<dl>
<dt><tt>output</tt> : T</dt>
<dd>Gated value tensor with shape (batch_size, sequence_length, hc_mult, hidden_size).</dd>
</dl>

#### Type Constraints

<dl>
<dt><tt>T</tt> : tensor(float), tensor(float16), tensor(bfloat16)</dt>
<dd>Constrain input and output types to float tensors.</dd>
</dl>


### <a name="com.microsoft.ExpandDims"></a><a name="com.microsoft.expanddims">**com.microsoft.ExpandDims**</a>

ExpandDims echo operator.
Expand Down Expand Up @@ -4037,6 +4100,70 @@ This version of the operator has been available since version 1 of the 'com.micr
</dl>


### <a name="com.microsoft.NGramHashMapping"></a><a name="com.microsoft.ngramhashmapping">**com.microsoft.NGramHashMapping**</a>

Computes Engram n-gram hash ids from pre-compressed tokenizer ids.

For n in [2, max_ngram_size], the op creates causal shifts of input_ids, padding positions before the
sequence with pad_id, and computes
mix = shifted_0 * multipliers[0] xor ... xor shifted_(n-1) * multipliers[n-1].
For every head of that n-gram order it emits mix modulo the corresponding head vocabulary size.
The output layout is (batch_size, sequence_length, (max_ngram_size - 1) * n_head_per_ngram), with
heads for n=2 first, then n=3, and so on.

An n-gram window reaches max_ngram_size - 1 positions before the current token. To keep the op causal
across invocations (chunked prefill or autoregressive decode), the optional past_ids input carries
those preceding ids and present_ids returns the ids to pass to the next call. Both have shape
(batch_size, max_ngram_size - 1) and are right-aligned, so the last slot is the most recent id.
Positions before the start of the whole sequence use pad_id. Running the op once over a full sequence
and running it over consecutive chunks while threading present_ids into past_ids produce identical
hash ids. When past_ids is omitted the missing history is pad_id, which matches a fresh sequence.

#### Version

This version of the operator has been available since version 1 of the 'com.microsoft' operator set.

#### Attributes

<dl>
<dt><tt>max_ngram_size</tt> : int (required)</dt>
<dd>Maximum n-gram order. Must be at least 2.</dd>
<dt><tt>n_head_per_ngram</tt> : int (required)</dt>
<dd>Number of hash heads emitted for each n-gram order.</dd>
<dt><tt>pad_id</tt> : int (required)</dt>
<dd>Compressed tokenizer id used to pad causal shifts before the beginning of a sequence.</dd>
</dl>

#### Inputs (3 - 4)

<dl>
<dt><tt>input_ids</tt> : M</dt>
<dd>Compressed tokenizer ids with shape (batch_size, sequence_length).</dd>
<dt><tt>multipliers</tt> : M</dt>
<dd>Per-shift odd multipliers with shape (max_ngram_size).</dd>
<dt><tt>vocab_sizes</tt> : M</dt>
<dd>Per-output-head prime vocabulary sizes with shape ((max_ngram_size - 1) * n_head_per_ngram).</dd>
<dt><tt>past_ids</tt> (optional) : M</dt>
<dd>Optional compressed tokenizer ids for the max_ngram_size - 1 positions that precede this call, with shape (batch_size, max_ngram_size - 1). Right-aligned, so the last slot is the most recent id. If omitted the history is pad_id.</dd>
</dl>

#### Outputs (1 - 2)

<dl>
<dt><tt>hash_ids</tt> : M</dt>
<dd>Hash ids with shape (batch_size, sequence_length, (max_ngram_size - 1) * n_head_per_ngram).</dd>
<dt><tt>present_ids</tt> (optional) : M</dt>
<dd>Trailing max_ngram_size - 1 ids of past_ids followed by input_ids, with shape (batch_size, max_ngram_size - 1). Feed this back as past_ids on the next call.</dd>
</dl>

#### Type Constraints

<dl>
<dt><tt>M</tt> : tensor(int32), tensor(int64)</dt>
<dd>Constrain ids, multipliers, vocabulary sizes, and output ids to integer tensors.</dd>
</dl>


### <a name="com.microsoft.NGramRepeatBlock"></a><a name="com.microsoft.ngramrepeatblock">**com.microsoft.NGramRepeatBlock**</a>

Enforce no repetition of n-grams. Scores are set to `-inf` for tokens that form a repeated n-gram if added to the back of the input_ids.
Expand Down Expand Up @@ -6354,6 +6481,76 @@ This version of the operator has been available since version 1 of the 'com.micr
</dl>


### <a name="com.microsoft.ShortConv"></a><a name="com.microsoft.shortconv">**com.microsoft.ShortConv**</a>

Fuses the Engram ShortConv block over input shape (batch_size, sequence_length, hc_mult, hidden_size).

For each (batch, token, hyper-connection) row, the op first applies RMS normalization over hidden_size:
normed = input * norm_scale * rsqrt(mean(input * input) + epsilon).

It then flattens hc_mult and hidden_size into depthwise convolution channels and applies a causal
1D convolution with optional dilation along the sequence axis. The output is cropped to sequence_length,
optionally passed through SiLU/Swish, and returned in (batch_size, sequence_length, hc_mult, hidden_size)
layout. The convolution weight layout is (hc_mult * hidden_size, 1, kernel_size).

The convolution receptive field spans state_length = (kernel_size - 1) * dilation positions before the
current token. To keep the op causal across invocations (chunked prefill or autoregressive decode), the
optional past_state input carries the raw (un-normalized) input values of those positions from the
preceding call and present_state returns them for the next call. Both have shape
(batch_size, state_length, hc_mult, hidden_size) and are right-aligned: slot state_length - 1 holds the
most recent position. Slots that correspond to positions before the start of the whole sequence are
zero. Because the state is un-normalized, the RMS reduction is recomputed from the same values a
full-sequence run would use, so running the op once over a full sequence and running it over consecutive
chunks while threading present_state into past_state produce identical outputs for every element type.
When past_state is omitted the missing history is treated as zeros, which matches a fresh sequence.

#### Version

This version of the operator has been available since version 1 of the 'com.microsoft' operator set.

#### Attributes

<dl>
<dt><tt>activation</tt> : string</dt>
<dd>Fused activation function. One of: 'silu', 'swish', 'none'. Default is 'silu'.</dd>
<dt><tt>dilation</tt> : int</dt>
<dd>Causal convolution dilation along the sequence axis. Default is 1.</dd>
<dt><tt>epsilon</tt> : float</dt>
<dd>Epsilon used by the per-hyper-connection RMS normalization. Default is 1e-5.</dd>
</dl>

#### Inputs (3 - 5)

<dl>
<dt><tt>input</tt> : T</dt>
<dd>Input tensor with shape (batch_size, sequence_length, hc_mult, hidden_size).</dd>
<dt><tt>weight</tt> : T</dt>
<dd>Depthwise convolution kernel with shape (hc_mult * hidden_size, 1, kernel_size).</dd>
<dt><tt>norm_scale</tt> : T</dt>
<dd>RMSNorm scale with shape (hc_mult, hidden_size).</dd>
<dt><tt>bias</tt> (optional) : T</dt>
<dd>Optional convolution bias with shape (hc_mult * hidden_size).</dd>
<dt><tt>past_state</tt> (optional) : T</dt>
<dd>Optional raw (un-normalized) input for the (kernel_size - 1) * dilation positions that precede this call, with shape (batch_size, (kernel_size - 1) * dilation, hc_mult, hidden_size). Right-aligned, so the last slot is the most recent position. If omitted the history is treated as zeros.</dd>
</dl>

#### Outputs (1 - 2)

<dl>
<dt><tt>output</tt> : T</dt>
<dd>Output tensor with the same shape as input.</dd>
<dt><tt>present_state</tt> (optional) : T</dt>
<dd>Raw (un-normalized) input for the trailing (kernel_size - 1) * dilation positions of past_state followed by input, with shape (batch_size, (kernel_size - 1) * dilation, hc_mult, hidden_size). Feed this back as past_state on the next call.</dd>
</dl>

#### Type Constraints

<dl>
<dt><tt>T</tt> : tensor(float), tensor(float16), tensor(bfloat16)</dt>
<dd>Constrain input and output types to float tensors.</dd>
</dl>


### <a name="com.microsoft.SkipGroupNorm"></a><a name="com.microsoft.skipgroupnorm">**com.microsoft.SkipGroupNorm**</a>

This operator element-wise adds x, skip and bias, then apply group normalization and optional activation.
Expand Down
Loading
Loading