Skip to content

Add SDPA and Flash Attention support for OWL-ViT#44159

Open
samuelleecong wants to merge 2 commits intohuggingface:mainfrom
samuelleecong:add-sdpa-owlvit
Open

Add SDPA and Flash Attention support for OWL-ViT#44159
samuelleecong wants to merge 2 commits intohuggingface:mainfrom
samuelleecong:add-sdpa-owlvit

Conversation

@samuelleecong
Copy link
Copy Markdown

Summary

Closes #28103

  • Refactor OwlViTAttention to use ALL_ATTENTION_FUNCTIONS for dynamic attention backend dispatch (same pattern as CLIP)
  • Add eager_attention_forward standalone function with the standardized interface
  • Reshape Q/K/V from 3D (batch * heads, seq, head_dim) to 4D (batch, heads, seq, head_dim) for SDPA/Flash compatibility
  • Set _supports_sdpa, _supports_flash_attn, and _supports_attention_backend flags on OwlViTPreTrainedModel

Test plan

  • pytest tests/models/owlvit/ -v — 327 passed, 288 skipped, 0 failed
  • pytest tests/models/owlvit/ -v -k "sdpa" — all SDPA-specific tests pass
  • Direct numerical comparison: eager vs SDPA outputs match within atol=1e-5 across all model outputs (text embeds, image embeds, hidden states, logits)

🤖 Generated with Claude Code

Refactor OwlViTAttention to use ALL_ATTENTION_FUNCTIONS for dynamic
attention backend dispatch, enabling SDPA and Flash Attention 2 support.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: owlvit

@vasqu
Copy link
Copy Markdown
Contributor

vasqu commented Feb 24, 2026

#42136 already started this effort so I'd like to focus on one PR. Maybe you can sync on that PR instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OWL-VIT Vision Foundation Model deployment in the edge cases - Need SDPA support for OWL-ViT Model optimization for Edge Deployment

2 participants