Problem
Decoders that require a float additive attention bias — Gemma-4's bidirectional vision-block overlay, and sliding-window / custom-mask models — cannot use com.microsoft.GroupQueryAttention (it accepts only causal/local masking, not an arbitrary attention_bias). mobius therefore emits them with the standard ONNX Attention op, is_causal=0, over an internal dynamic past/present KV cache. With a bias present this routes ORT to the internal-cache MEA path, which the kernel's own source note calls ~15-30% slower than contrib GQA's in-place decode. Today these models give up the decode fast-path entirely.
ORT supports a faster alternative on the SAME standard Attention op: the opset-24 external KV cache (nonpad_kv_seqlen + TensorScatter). On the MEA path it combines additive bias + GQA + external cache and reaches near-contrib-GQA performance — letting a single standard-Attention graph carry the bias during prefill AND hit a near-GQA decode (Flash is precluded by any bias, so MEA-external ≈ GQA is the ceiling).
Mobius-side deliverable (this issue — contract-independent, ORT-testable now)
mobius already emits the maskless external-KV static-cache graph (sibling work #345) and already builds the causal+sliding+Gemma-4 block-overlay bias (create_attention_bias). This issue wires the two together:
- Thread an optional float bias into the shared static-cache
Attention path (_apply_attention), pairing bias-present with is_causal=0 (maskless is_causal=1 stays the default).
- Add an external-cache bias builder producing a
(B,1,S_q,max_seq) additive bias keyed on absolute query positions with KV validity slot < nonpad_kv_seqlen, reusing the proven causal/sliding/block-overlay/padding logic.
- Flag-gated (
MOBIUS_STATIC_CACHE_BIAS, default off).
- An ORT manual-feed parity test (CPU MEA, no genai, no Flash) vs a dense-attention reference for a prefill chunk and a decode step.
The bias geometry is a pure function of model semantics + cache layout — independent of how the runtime drives it — so this slice is safe to land before the genai consumer exists.
Acceptance criteria
Explicitly out of scope (separate follow-ups)
Re-emitting Gemma-4's own decoder task/model on the static path, genai_config.json wiring, single-graph vs prefill/decode-split packaging, and e2e generation/decode profiling.
Relationships
Problem
Decoders that require a float additive attention bias — Gemma-4's bidirectional vision-block overlay, and sliding-window / custom-mask models — cannot use
com.microsoft.GroupQueryAttention(it accepts only causal/local masking, not an arbitraryattention_bias). mobius therefore emits them with the standard ONNXAttentionop,is_causal=0, over an internal dynamicpast/presentKV cache. With a bias present this routes ORT to the internal-cache MEA path, which the kernel's own source note calls ~15-30% slower than contrib GQA's in-place decode. Today these models give up the decode fast-path entirely.ORT supports a faster alternative on the SAME standard
Attentionop: the opset-24 external KV cache (nonpad_kv_seqlen+TensorScatter). On the MEA path it combines additive bias + GQA + external cache and reaches near-contrib-GQA performance — letting a single standard-Attentiongraph carry the bias during prefill AND hit a near-GQA decode (Flash is precluded by any bias, so MEA-external ≈ GQA is the ceiling).Mobius-side deliverable (this issue — contract-independent, ORT-testable now)
mobius already emits the maskless external-KV static-cache graph (sibling work #345) and already builds the causal+sliding+Gemma-4 block-overlay bias (
create_attention_bias). This issue wires the two together:Attentionpath (_apply_attention), pairing bias-present withis_causal=0(masklessis_causal=1stays the default).(B,1,S_q,max_seq)additive bias keyed on absolute query positions with KV validityslot < nonpad_kv_seqlen, reusing the proven causal/sliding/block-overlay/padding logic.MOBIUS_STATIC_CACHE_BIAS, default off).The bias geometry is a pure function of model semantics + cache layout — independent of how the runtime drives it — so this slice is safe to land before the genai consumer exists.
Acceptance criteria
Attentionpath honours an optional float bias withis_causal=0; maskless default unchanged.create_static_cache_attention_biasemits the(B,1,S_q,max_seq),slot<nonpadbias (causal + sliding + block-overlay + padding).Explicitly out of scope (separate follow-ups)
Re-emitting Gemma-4's own decoder task/model on the static path,
genai_config.jsonwiring, single-graph vs prefill/decode-split packaging, and e2e generation/decode profiling.Relationships
is_causal=1static-cache graph) — shares the TensorScatter +nonpad_kv_seqlenprimitive; this issue adds the bias variant.