From ff7d00883837f8bb3356f5e0ce4217b29e20e523 Mon Sep 17 00:00:00 2001 From: Md Kashif Ali Date: Sat, 16 May 2026 17:34:14 +0530 Subject: [PATCH] Fix: Allow SDPA backend fallback in decoder.py; fix README typo 1. decoder.py: Allow fallback to EFFICIENT_ATTENTION and MATH backends when Flash Attention is unavailable (e.g., Windows/PyTorch without FA compiled). This aligns decoder.py with the existing pattern in vl_combiner.py (line 150-155). Fixes #523. 2. README.md: Fix typo 'Demonsterates' -> 'Demonstrates'. --- README.md | 2 +- sam3/model/decoder.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9aad5341b..8744ea7d1 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,7 @@ various types of prompts: further interactive refinements with points. - [`sam3_image_batched_inference.ipynb`](examples/sam3_image_batched_inference.ipynb) : Demonstrates how to run batched inference with SAM 3 on images. -- [`sam3_agent.ipynb`](examples/sam3_agent.ipynb): Demonsterates the use of SAM +- [`sam3_agent.ipynb`](examples/sam3_agent.ipynb): Demonstrates the use of SAM 3 Agent to segment complex text prompt on images. - [`saco_gold_silver_vis_example.ipynb`](examples/saco_gold_silver_vis_example.ipynb) : Shows a few examples from SA-Co image evaluation set. diff --git a/sam3/model/decoder.py b/sam3/model/decoder.py index b90e55f5c..df9b8696b 100644 --- a/sam3/model/decoder.py +++ b/sam3/model/decoder.py @@ -1011,7 +1011,13 @@ def functional_attention( assert dropout == 0.0 out = flash_attn_func(q.transpose(1, 2), k.transpose(1, 2), v.transpose(1, 2)) else: - with sdpa_kernel(SDPBackend.FLASH_ATTENTION): + with sdpa_kernel( + [ + SDPBackend.FLASH_ATTENTION, + SDPBackend.EFFICIENT_ATTENTION, + SDPBackend.MATH, + ] + ): out = torchF.scaled_dot_product_attention(q, k, v, dropout_p=dropout) out = out.transpose(1, 2) # B * n * n_heads * (cv // num_heads)