Mike0021 commited on
Commit
4278535
·
verified ·
1 Parent(s): 7dfb205

functional BHSD fix

Browse files
Files changed (1) hide show
  1. aoti_attention.py +5 -6
aoti_attention.py CHANGED
@@ -82,18 +82,17 @@ def sparse_attention_functional(
82
  untiling, then the compression branch scaled by the trained per-row gate. `gate` is
83
  `[B, H, S_real, D]` (the eager path's `gate.transpose(1, 2)`), applied after untililing.
84
  """
85
- batch, heads, padded_len, dim = query.shape
86
  n_tiles = variable_block_sizes.numel()
87
- n_real = untile_index.numel()
88
- num_q_video = n_tiles - num_prefix_tiles
89
 
90
  # Tile: scatter the packed rows into the kernels' `[B, H, S_pad, D]` layout, pad slots zero.
91
  query_tiled = torch.zeros((batch, heads, padded_len, dim), dtype=query.dtype, device=query.device)
92
- query_tiled.index_copy_(2, untile_index, query.transpose(1, 2))
93
  key_tiled = torch.zeros_like(query_tiled)
94
- key_tiled.index_copy_(2, untile_index, key.transpose(1, 2))
95
  value_tiled = torch.zeros_like(query_tiled)
96
- value_tiled.index_copy_(2, untile_index, value.transpose(1, 2))
97
 
98
  # Per-head fp32 pooled tile scores.
99
  q_pool = query_tiled.view(batch, heads, n_tiles, 64, dim).sum(dim=3, dtype=torch.float32) / tile_divisor
 
82
  untiling, then the compression branch scaled by the trained per-row gate. `gate` is
83
  `[B, H, S_real, D]` (the eager path's `gate.transpose(1, 2)`), applied after untililing.
84
  """
85
+ batch, heads, seq_len, dim = query.shape # inputs are `[B, H, S_real, D]` (BHSD)
86
  n_tiles = variable_block_sizes.numel()
87
+ padded_len = n_tiles * 64
 
88
 
89
  # Tile: scatter the packed rows into the kernels' `[B, H, S_pad, D]` layout, pad slots zero.
90
  query_tiled = torch.zeros((batch, heads, padded_len, dim), dtype=query.dtype, device=query.device)
91
+ query_tiled.index_copy_(2, untile_index, query)
92
  key_tiled = torch.zeros_like(query_tiled)
93
+ key_tiled.index_copy_(2, untile_index, key)
94
  value_tiled = torch.zeros_like(query_tiled)
95
+ value_tiled.index_copy_(2, untile_index, value)
96
 
97
  # Per-head fp32 pooled tile scores.
98
  q_pool = query_tiled.view(batch, heads, n_tiles, 64, dim).sum(dim=3, dtype=torch.float32) / tile_divisor