transformers
5dbcff4c - Use the shared attention interface in encoder-decoder attention blocks

Commit
92 days ago
Use the shared attention interface in encoder-decoder attention blocks Route 16 hand-written `*Attention` forwards through `ALL_ATTENTION_FUNCTIONS` / `eager_attention_forward` so they pick up the sdpa and flash backends instead of computing scores with `torch.bmm`: mvp, trocr, xglm, led (decoder), prophetnet (`ProphetNetAttention`), fsmt, table_transformer, dab_detr (both blocks), tvp, mask2former, oneformer, omdet_turbo, zoedepth, grounding_dino, mm_grounding_dino (regenerated). Forward bodies only, no weight renames. Every block explicitly sets `is_causal`, since `sdpa_attention_forward` otherwise defaults it to True and would silently apply a causal mask to bidirectional attention. Mask shapes are adapted where they differed: fsmt merges its separate causal `attn_mask` and boolean `key_padding_mask` into one additive mask, and mask2former/oneformer unflatten their `(batch * heads, tgt, src)` mask. Verified per class against a saved state_dict and forward outputs from a fixed seed: mvp, trocr, led, fsmt, omdet_turbo and zoedepth are bit-exact. The rest differ only at float32 rounding scale (<= 8.4e-07), each confirmed to come solely from reordering the scale, `bmm` -> `matmul`, or `/sqrt(d)` -> `*d**-0.5`, by restoring the old arithmetic and re-checking. ProphetNet's `encoder_attentions`/`cross_attentions` change deliberately: they were raw pre-softmax logits holding -3.4e38 (rows summing to -inf) because the weights were captured before the softmax. They are now probabilities; all non-attention outputs stay bit-exact. Skipped, as they are not scaled dot-product attention: - `AutoformerAttention` computes AutoCorrelation (rfft/irfft plus top-k time-delay aggregation). - `GroundingDinoBiMultiHeadAttention` and its mm_grounding_dino twin are a bidirectional shared-score fusion: a single QK^T reused transposed for the text direction with no text-side query projection, plus a global-max subtraction and a +/-50000 clamp the interface cannot express. - `OneFormerTextMapperAttention` is unreachable dead code (it and its two wrappers have no references), so it is in no checkpoint.
Author
Parents
Loading