Spaces:
Running on Zero
Running on Zero
Remove pipeline/sdpa_patch.py (replaced by the flashrefocus package)
Browse files- pipeline/sdpa_patch.py +0 -28
pipeline/sdpa_patch.py
DELETED
|
@@ -1,28 +0,0 @@
|
|
| 1 |
-
"""Route the Depth Anything V2 (DINOv2) attention through torch.nn.functional.scaled_dot_product_attention (SDPA).
|
| 2 |
-
|
| 3 |
-
apply() replaces Attention.forward at runtime, without editing the submodule: plain softmax attention -> SDPA
|
| 4 |
-
(Flash / memory-efficient kernels), 4.2x faster at 1536x1536 with the same result up to floating-point reordering.
|
| 5 |
-
The renderer keeps its own attention: its short axial rows with a float bias run slower through SDPA."""
|
| 6 |
-
import sys
|
| 7 |
-
from pathlib import Path
|
| 8 |
-
|
| 9 |
-
import torch
|
| 10 |
-
import torch.nn.functional as F
|
| 11 |
-
|
| 12 |
-
sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # repository root
|
| 13 |
-
import paths # noqa: E402
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def _da2_forward(self, x, attn_bias=None):
|
| 17 |
-
assert attn_bias is None
|
| 18 |
-
B, N, C = x.shape
|
| 19 |
-
q, k, v = self.qkv(x).reshape(B, N, 3, self.num_heads, C // self.num_heads).permute(2, 0, 3, 1, 4)
|
| 20 |
-
x = F.scaled_dot_product_attention(q, k, v, scale=self.scale).transpose(1, 2).reshape(B, N, C)
|
| 21 |
-
return self.proj_drop(self.proj(x))
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
def apply():
|
| 25 |
-
paths.add_to_path()
|
| 26 |
-
from depth_anything_v2.dinov2_layers import attention as da2_attn
|
| 27 |
-
da2_attn.Attention.forward = _da2_forward
|
| 28 |
-
da2_attn.MemEffAttention.forward = _da2_forward
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|