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
// arch/granite/projector.h - Granite Speech projector (BLIP-2 Q-Former).
//
// Reference: GraniteSpeechEncoderProjector +
// Blip2QFormerModel/Encoder/Layer in transformers/models/blip_2/.
//
// Forward shape:
//
// in : [hidden_enc, T_enc] (encoder.out for 1b/2b; for -plus
// this is the cat of block[3] and block[N-1] hidden along
// the channel axis, doubling hidden_enc)
// pad : zero-pad along T_enc → nblocks * window_size where
// nblocks = ceil(T_enc / window_size).
// window : view as [hidden_enc, window_size, nblocks]
// query : [hidden, num_queries=3, 1] broadcast → [hidden, 3, nblocks]
// for layer in [0, n_layers):
// q = LN(self_attn.out(self_attn(q, q, q)) + q)
// q = LN(cross_attn.out(cross_attn(q, window, window)) + q)
// q = LN(ffn.down(GELU(ffn.up(q))) + q)
// q = LN(final_norm)(q) # proj.qformer.out [hidden, 3, nblocks]
// out = linear(q.reshape(nblocks*3, hidden)) # proj.out [text_hidden, nblocks*3]
//
// BERT/BLIP-2 layer style: residual + LN happens AFTER each output
// projection ("post-LN" — different from the granite encoder's pre-LN
// macaron / pre-LN attention pattern).
//
// This header is INTERNAL to src/arch/granite/.
;
;
;
namespace transcribe::granite // namespace transcribe::granite