1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// src/granite_conformer/shaw_attn.h - shared Shaw block-local attention.
//
// Reused by both `src/arch/granite/encoder.cpp` (AR audio-LLM) and
// `src/arch/granite_nar/encoder.cpp` (NAR editor). The two families
// share an audio encoder up to the projector; this is the only
// Granite-specific Conformer op without an analog in `src/conformer/`.
//
// Mirrors `GraniteSpeechConformerAttention.forward`:
//
// h = pre_norm(x) # at T_enc
// if remainder > 0: h = F.pad(h, (0, 0, 0, pad)) # zero-pad to T_pad
// q = to_q(h); kv = to_kv(h); k, v = kv.chunk(2, dim=-1)
// ... block-local attention with Shaw bias + last-block pad mask ...
// out = out.reshape(..., T_pad, inner_dim)
// out = to_out(out[:, :num_features, :]) # slice back to T_enc
// return out # at T_enc
//
// The slice happens BEFORE to_out (upstream order), so the following
// conv module's depthwise kernel never pulls pad-row garbage into
// valid frames near the tail.
namespace transcribe::granite_conformer // namespace transcribe::granite_conformer