Files
opencv-MIRROR/modules
Rahul Kumar 7a3dd65ae1 dnn: fix com.microsoft Attention with a mask_index or without a bias, and Add(mask, scores) fusion 🤖🤖🤖 (#30930)
* dnn: fix masked Attention ONNX import and commutative mask-Add fusion

ONNXImporter2::parseAttention required every input after X to be constant before populating params.blobs, leaving blobs empty for dynamic masks, pushing constant masks into blobs[2], and failing on omitted or trailing empty optional inputs. AttentionLayerImpl also read bias from blobs.back() instead of blobs[1], and ModelFusionAttention::isMaskAdd hardcoded inputs[1] so Add(mask, scores) bound Attention's mask to the removed score node. Fold constant weight and bias into blobs[0..1], keep any 4th mask input on layer->inputs[1], and match score_arg in isMaskAdd.

* dnn(onnx): lower the Attention int32 mask_index with addKeyPaddingMaskBias

mask_index is an int32 0/1 padding mask, not an additive bias. Turn it
into the additive mask the layer applies, the same way
parseMultiHeadAttention does, saving and restoring node_inputs and
node_outputs around the helper.

The test loads its models from opencv_extra (same branch name) with
testONNXModels() instead of building them and the reference in code;
the first three cases now use the spec's int32 [B, S] mask.

* dnn: keep AttentionLayerImpl's blob access as on 5.x

parseAttention now always gives the layer exactly two blobs, the weight
and the bias, and the fusion passes do the same, so blobs.front() and
blobs.back() already pick them. The blobs[0]/blobs[1] change is not
needed.
2026-11-24 13:38:53 +05:30
..
2026-07-09 12:17:24 +03:00