kernel
triton
lee-futo commited on
Commit
480f425
·
verified ·
1 Parent(s): cd8840e

v2: bucketed autotune key next_pow2(T) (v1 re-autotuned per length, 30x slow on variable-length ASR); numerically identical, parity vs eager 5 shapes rel<1e-6

Browse files
README.md CHANGED
@@ -28,11 +28,17 @@ the projections that produce its inputs; the caller passes `a_logits` and `v`.
28
  ```python
29
  from kernels import get_kernel
30
 
31
- k = get_kernel("futo-org/ldsa", version=1)
32
  out = k.ldsa_local_attention(a_logits, v, left, right) # [B,H,Dh,T]; contiguous, any float
33
  ```
34
 
35
- `version=1` pins the `v1` build; omit to track `main` (latest).
 
 
 
 
 
 
36
 
37
  ## What LDSA is
38
 
 
28
  ```python
29
  from kernels import get_kernel
30
 
31
+ k = get_kernel("futo-org/ldsa", version=2)
32
  out = k.ldsa_local_attention(a_logits, v, left, right) # [B,H,Dh,T]; contiguous, any float
33
  ```
34
 
35
+ `version=2` pins the `v2` build; omit to track `main` (latest).
36
+
37
+ > **v2 (2026-09-02):** the autotune cache key is bucketed on `next_power_of_2(T)` instead of
38
+ > raw `T`. On variable-length inference (e.g. real ASR batches) the raw-`T` key of v1 caused a
39
+ > cache miss and full re-autotune on every new sequence length — measured 30x slower than
40
+ > eager on the Open ASR harness. Numerically identical to v1 (same kernel body). **v1 is kept
41
+ > for reproducibility; new users should pin `version=2`.**
42
 
43
  ## What LDSA is
44
 
build/torch-cuda/__init__.py CHANGED
@@ -12,7 +12,7 @@ than from query-key dot products (Synthesizer, arXiv 2005.00743). The kernel fus
12
  value/output projections — the caller supplies `a_logits` and `v`.
13
 
14
  from kernels import get_kernel
15
- k = get_kernel("futo-org/ldsa", version=1)
16
  out = k.ldsa_local_attention(a_logits, v, left, right) # [B,H,Dh,T]; contiguous, any float
17
 
18
  Inference kernel (no backward): the Triton path runs only on CUDA under `torch.no_grad()`;
@@ -52,13 +52,20 @@ def _configs():
52
  return [triton.Config({"BLOCK_T": bt}, num_warps=nw) for bt in (64, 128, 256) for nw in (4, 8)]
53
 
54
 
55
- @triton.autotune(configs=_configs(), key=["T", "Dh", "W"])
 
 
 
 
 
 
56
  @triton.jit
57
  def _ldsa_kernel(
58
  a_ptr,
59
  v_ptr,
60
  out_ptr,
61
  T,
 
62
  Dh,
63
  left,
64
  stride_a_bh,
@@ -116,6 +123,7 @@ def _triton_ldsa(a_logits: torch.Tensor, v: torch.Tensor, left: int) -> torch.Te
116
  v_c,
117
  out,
118
  t,
 
119
  dh,
120
  left,
121
  w * t,
 
12
  value/output projections — the caller supplies `a_logits` and `v`.
13
 
14
  from kernels import get_kernel
15
+ k = get_kernel("futo-org/ldsa", version=2) # v2: bucketed autotune key (v1 re-tunes per length)
16
  out = k.ldsa_local_attention(a_logits, v, left, right) # [B,H,Dh,T]; contiguous, any float
17
 
18
  Inference kernel (no backward): the Triton path runs only on CUDA under `torch.no_grad()`;
 
52
  return [triton.Config({"BLOCK_T": bt}, num_warps=nw) for bt in (64, 128, 256) for nw in (4, 8)]
53
 
54
 
55
+ # KEY ON next_pow2(T), NEVER ON RAW T. `key` is the autotune cache key: a miss re-benchmarks every
56
+ # config (6 launches x warmup) before the real call. Keyed on raw T, every new utterance length
57
+ # in a variable-length batch stream is a miss -- measured on the Open ASR harness: the encoder
58
+ # re-autotuned inside the timed loop and the model ran 30x slower than eager. v1 of this kernel
59
+ # shipped that bug. T_BUCKET = next_pow2(T) gives ~10 buckets over any realistic length; the
60
+ # body never reads it.
61
+ @triton.autotune(configs=_configs(), key=["T_BUCKET", "Dh", "W"])
62
  @triton.jit
63
  def _ldsa_kernel(
64
  a_ptr,
65
  v_ptr,
66
  out_ptr,
67
  T,
68
+ T_BUCKET, # autotune key only -- unused in the body; see the note above
69
  Dh,
70
  left,
71
  stride_a_bh,
 
123
  v_c,
124
  out,
125
  t,
126
+ triton.next_power_of_2(t), # T_BUCKET -- bounds the autotune key's cardinality
127
  dh,
128
  left,
129
  w * t,
build/torch-cuda/metadata.json CHANGED
@@ -1,7 +1,7 @@
1
  {
2
  "name": "ldsa",
3
  "id": "_ldsa_cuda_9763df8",
4
- "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
7
  "backend": {
@@ -10,7 +10,7 @@
10
  "digest": {
11
  "algorithm": "sha256",
12
  "files": {
13
- "__init__.py": "NEgktlyHTKkRCwaMYX8w/ekaSbpjqLPHVmWtBTlDe6Q=",
14
  "_ops.py": "KddM++gF3qGbBFs9PMP3HLS6KFeK8NEJWiwEH4aX15Y=",
15
  "ldsa/__init__.py": "DFYPlrhXwYjEqCl/8n0SmWGZV8NFml5DPhMjKfv98GY="
16
  }
@@ -23,7 +23,8 @@
23
  },
24
  "kernel": {
25
  "sha": "9763df80731b1bd5b031b311793df01d91f59554",
26
- "dirty": false
27
- }
 
28
  }
29
  }
 
1
  {
2
  "name": "ldsa",
3
  "id": "_ldsa_cuda_9763df8",
4
+ "version": 2,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
7
  "backend": {
 
10
  "digest": {
11
  "algorithm": "sha256",
12
  "files": {
13
+ "__init__.py": "sYWp9WmouskvyG8G5BHnCsFjZpclgFq9sQ28p3BBkQc=",
14
  "_ops.py": "KddM++gF3qGbBFs9PMP3HLS6KFeK8NEJWiwEH4aX15Y=",
15
  "ldsa/__init__.py": "DFYPlrhXwYjEqCl/8n0SmWGZV8NFml5DPhMjKfv98GY="
16
  }
 
23
  },
24
  "kernel": {
25
  "sha": "9763df80731b1bd5b031b311793df01d91f59554",
26
+ "dirty": true
27
+ },
28
+ "note": "v2: autotune key bucketed on next_power_of_2(T); hand-published from futo-asr kernels/ldsa (parity vs eager_ldsa 5 shapes, rel<1e-6)"
29
  }
30
  }