File size: 23,129 Bytes
9422383
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
// Fixed top-down neck partitions. Reserved values reproduce XNNPACK's
// performance-sensitive declaration inventory but are not part of data flow.

// Projects the backbone P4 feature and adds the upsampled P5 projection to form
// the model.13 fusion input.
bool BuildNeckP4Fusion(const GraphContext& context) {
  FixedGraphBuilder graph(context, GraphId::kNeckP4Fusion, NeckP4FusionBindings::kCount);
  if (!graph.Begin()) return false;
  const GraphValue upsampled_p5_input = graph.DefineInput(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(128)},
      NeckP4FusionBindings::kUpsampledP5Input);
  const GraphValue backbone_p4_input = graph.DefineInput(
      ValueType::kFp16, {Constant(1), Constant(128), ResolutionDivided(16), ResolutionDivided(16)},
      NeckP4FusionBindings::kBackboneP4Input);
  [[maybe_unused]] const GraphValue reserved_value_2 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(128)});
  const GraphValue transpose_1_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(128)});
  const GraphValue model13_cv1_conv_weight_input256384 =
      graph.DefineWeight(ValueType::kFp32, {Constant(128), Constant(1), Constant(1), Constant(128)},
                         WeightSlot::kModel13Cv1ConvWeightInput256384);
  [[maybe_unused]] const GraphValue reserved_value_5 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(128)});
  const GraphValue model13_cv1_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(128)}, WeightSlot::kModel13Cv1ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_7 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(128)});
  const GraphValue model13_cv1_conv_weight_input256384_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(128)});
  const GraphValue fusion_output = graph.DefineOutput(
      ValueType::kFp16, {Constant(1), Constant(128), ResolutionDivided(16), ResolutionDivided(16)},
      NeckP4FusionBindings::kFusionOutput);
  const GraphValue residual_sum_1 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(128)});
  const GraphValue residual_sum_1_activation = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(128)});
  if (!graph.DefinitionsValid()) return false;
  if (!graph.Transpose(backbone_p4_input, transpose_1_output,
                       {Constant(0), Constant(2), Constant(3), Constant(1)}, 0))
    return false;
  if (!graph.Convolution(transpose_1_output, model13_cv1_conv_weight_input256384,
                         model13_cv1_conv_bias, model13_cv1_conv_weight_input256384_output,
                         Padding{Constant(0), Constant(0), Constant(0), Constant(0)},
                         Kernel{Constant(1), Constant(1)}, Stride{Constant(1), Constant(1)},
                         Dilation{Constant(1), Constant(1)},
                         Groups{Constant(1), Constant(128), Constant(128)}, 0))
    return false;
  if (!graph.Add(upsampled_p5_input, model13_cv1_conv_weight_input256384_output, residual_sum_1, 0))
    return false;
  if (!graph.Silu(residual_sum_1, residual_sum_1_activation, 0)) return false;
  if (!graph.Transpose(residual_sum_1_activation, fusion_output,
                       {Constant(0), Constant(3), Constant(1), Constant(2)}, 0))
    return false;
  return graph.Finish();
}

// Runs the model.13 C2f block and emits both the fused P4 feature and the
// narrower projection that the schedule upsamples toward P3.
bool BuildNeckP4Block(const GraphContext& context) {
  FixedGraphBuilder graph(context, GraphId::kNeckP4Block, NeckP4BlockBindings::kCount);
  if (!graph.Begin()) return false;
  const GraphValue main_input = graph.DefineInput(
      ValueType::kFp16, {Constant(1), Constant(64), ResolutionDivided(16), ResolutionDivided(16)},
      NeckP4BlockBindings::kMainInput);
  const GraphValue transpose_1_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(64)});
  const GraphValue skip_input = graph.DefineInput(
      ValueType::kFp16, {Constant(1), Constant(64), ResolutionDivided(16), ResolutionDivided(16)},
      NeckP4BlockBindings::kSkipInput);
  const GraphValue transpose_2_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(64)});
  const GraphValue model13_m0_cv1_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(32), Constant(1), Constant(1), Constant(64)},
                         WeightSlot::kModel13M0Cv1ConvWeight);
  [[maybe_unused]] const GraphValue reserved_value_5 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model13_m0_cv1_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(32)}, WeightSlot::kModel13M0Cv1ConvBias);
  const GraphValue model13_m0_cv2_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(32), Constant(1), Constant(1), Constant(64)},
                         WeightSlot::kModel13M0Cv2ConvWeight);
  [[maybe_unused]] const GraphValue reserved_value_8 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model13_m0_cv2_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(32)}, WeightSlot::kModel13M0Cv2ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_10 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  [[maybe_unused]] const GraphValue reserved_value_11 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model13_m0_cv1_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model13_m0_cv2_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model13_m0_m0_cv1_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(32), Constant(3), Constant(3), Constant(32)},
                         WeightSlot::kModel13M0M0Cv1ConvWeight);
  const GraphValue model13_m0_m0_cv1_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model13_m0_m0_cv1_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(32)}, WeightSlot::kModel13M0M0Cv1ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_17 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model13_m0_m0_cv1_conv_activation = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model13_m0_m0_cv2_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(32), Constant(3), Constant(3), Constant(32)},
                         WeightSlot::kModel13M0M0Cv2ConvWeight);
  const GraphValue model13_m0_m0_cv2_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model13_m0_m0_cv2_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(32)}, WeightSlot::kModel13M0M0Cv2ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_22 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model13_m0_m0_cv2_conv_activation = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue residual_sum_1 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model13_m0_m1_cv1_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(32), Constant(3), Constant(3), Constant(32)},
                         WeightSlot::kModel13M0M1Cv1ConvWeight);
  const GraphValue model13_m0_m1_cv1_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model13_m0_m1_cv1_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(32)}, WeightSlot::kModel13M0M1Cv1ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_28 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model13_m0_m1_cv1_conv_activation = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model13_m0_m1_cv2_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(32), Constant(3), Constant(3), Constant(32)},
                         WeightSlot::kModel13M0M1Cv2ConvWeight);
  const GraphValue model13_m0_m1_cv2_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model13_m0_m1_cv2_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(32)}, WeightSlot::kModel13M0M1Cv2ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_33 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model13_m0_m1_cv2_conv_activation = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue residual_sum_2 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue concatenation_1 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(64)});
  const GraphValue model13_m0_cv3_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(64), Constant(1), Constant(1), Constant(64)},
                         WeightSlot::kModel13M0Cv3ConvWeight);
  [[maybe_unused]] const GraphValue reserved_value_38 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(64)});
  const GraphValue model13_m0_cv3_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(64)}, WeightSlot::kModel13M0Cv3ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_40 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(64)});
  const GraphValue model13_m0_cv3_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(64)});
  const GraphValue concatenation_2 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(192)});
  const GraphValue model13_cv2_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(128), Constant(1), Constant(1), Constant(192)},
                         WeightSlot::kModel13Cv2ConvWeight);
  [[maybe_unused]] const GraphValue reserved_value_44 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(128)});
  const GraphValue model13_cv2_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(128)}, WeightSlot::kModel13Cv2ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_46 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(128)});
  const GraphValue model13_cv2_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(128)});
  const GraphValue neck_p4_output = graph.DefineOutput(
      ValueType::kFp16, {Constant(1), Constant(128), ResolutionDivided(16), ResolutionDivided(16)},
      NeckP4BlockBindings::kNeckP4Output);
  const GraphValue model16_cv1_conv_weight_input0128 =
      graph.DefineWeight(ValueType::kFp32, {Constant(64), Constant(1), Constant(1), Constant(128)},
                         WeightSlot::kModel16Cv1ConvWeightInput0128);
  const GraphValue projection_zero_bias64 =
      graph.DefineWeight(ValueType::kFp32, {Constant(64)}, WeightSlot::kProjectionZeroBias64);
  const GraphValue p4_projection_output = graph.DefineOutput(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(64)},
      NeckP4BlockBindings::kP4ProjectionOutput);
  [[maybe_unused]] const GraphValue reserved_value_52 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), Constant(64), ResolutionDivided(16), ResolutionDivided(16)});
  if (!graph.DefinitionsValid()) return false;
  if (!graph.Transpose(main_input, transpose_1_output,
                       {Constant(0), Constant(2), Constant(3), Constant(1)}, 0))
    return false;
  if (!graph.Transpose(skip_input, transpose_2_output,
                       {Constant(0), Constant(2), Constant(3), Constant(1)}, 0))
    return false;
  if (!graph.Convolution(
          transpose_1_output, model13_m0_cv1_conv_weight, model13_m0_cv1_conv_bias,
          model13_m0_cv1_conv_output, Padding{Constant(0), Constant(0), Constant(0), Constant(0)},
          Kernel{Constant(1), Constant(1)}, Stride{Constant(1), Constant(1)},
          Dilation{Constant(1), Constant(1)}, Groups{Constant(1), Constant(64), Constant(32)},
          XNN_FLAG_YOLO26_GEMM_SILU_FINAL_STORE))
    return false;
  if (!graph.Convolution(
          transpose_1_output, model13_m0_cv2_conv_weight, model13_m0_cv2_conv_bias,
          model13_m0_cv2_conv_output, Padding{Constant(0), Constant(0), Constant(0), Constant(0)},
          Kernel{Constant(1), Constant(1)}, Stride{Constant(1), Constant(1)},
          Dilation{Constant(1), Constant(1)}, Groups{Constant(1), Constant(64), Constant(32)},
          XNN_FLAG_YOLO26_GEMM_SILU_FINAL_STORE))
    return false;
  if (!graph.Convolution(model13_m0_cv1_conv_output, model13_m0_m0_cv1_conv_weight,
                         model13_m0_m0_cv1_conv_bias, model13_m0_m0_cv1_conv_output,
                         Padding{Constant(1), Constant(1), Constant(1), Constant(1)},
                         Kernel{Constant(3), Constant(3)}, Stride{Constant(1), Constant(1)},
                         Dilation{Constant(1), Constant(1)},
                         Groups{Constant(1), Constant(32), Constant(32)}, 0))
    return false;
  if (!graph.Silu(model13_m0_m0_cv1_conv_output, model13_m0_m0_cv1_conv_activation, 0))
    return false;
  if (!graph.Convolution(model13_m0_m0_cv1_conv_activation, model13_m0_m0_cv2_conv_weight,
                         model13_m0_m0_cv2_conv_bias, model13_m0_m0_cv2_conv_output,
                         Padding{Constant(1), Constant(1), Constant(1), Constant(1)},
                         Kernel{Constant(3), Constant(3)}, Stride{Constant(1), Constant(1)},
                         Dilation{Constant(1), Constant(1)},
                         Groups{Constant(1), Constant(32), Constant(32)}, 0))
    return false;
  if (!graph.Silu(model13_m0_m0_cv2_conv_output, model13_m0_m0_cv2_conv_activation, 0))
    return false;
  if (!graph.Add(model13_m0_cv1_conv_output, model13_m0_m0_cv2_conv_activation, residual_sum_1, 0))
    return false;
  if (!graph.Convolution(residual_sum_1, model13_m0_m1_cv1_conv_weight, model13_m0_m1_cv1_conv_bias,
                         model13_m0_m1_cv1_conv_output,
                         Padding{Constant(1), Constant(1), Constant(1), Constant(1)},
                         Kernel{Constant(3), Constant(3)}, Stride{Constant(1), Constant(1)},
                         Dilation{Constant(1), Constant(1)},
                         Groups{Constant(1), Constant(32), Constant(32)}, 0))
    return false;
  if (!graph.Silu(model13_m0_m1_cv1_conv_output, model13_m0_m1_cv1_conv_activation, 0))
    return false;
  if (!graph.Convolution(model13_m0_m1_cv1_conv_activation, model13_m0_m1_cv2_conv_weight,
                         model13_m0_m1_cv2_conv_bias, model13_m0_m1_cv2_conv_output,
                         Padding{Constant(1), Constant(1), Constant(1), Constant(1)},
                         Kernel{Constant(3), Constant(3)}, Stride{Constant(1), Constant(1)},
                         Dilation{Constant(1), Constant(1)},
                         Groups{Constant(1), Constant(32), Constant(32)}, 0))
    return false;
  if (!graph.Silu(model13_m0_m1_cv2_conv_output, model13_m0_m1_cv2_conv_activation, 0))
    return false;
  if (!graph.Add(residual_sum_1, model13_m0_m1_cv2_conv_activation, residual_sum_2, 0))
    return false;
  if (!graph.Concatenate({residual_sum_2, model13_m0_cv2_conv_output}, concatenation_1, Constant(3),
                         0))
    return false;
  if (!graph.Convolution(
          concatenation_1, model13_m0_cv3_conv_weight, model13_m0_cv3_conv_bias,
          model13_m0_cv3_conv_output, Padding{Constant(0), Constant(0), Constant(0), Constant(0)},
          Kernel{Constant(1), Constant(1)}, Stride{Constant(1), Constant(1)},
          Dilation{Constant(1), Constant(1)}, Groups{Constant(1), Constant(64), Constant(64)},
          XNN_FLAG_YOLO26_GEMM_SILU_FINAL_STORE))
    return false;
  if (!graph.Concatenate({transpose_2_output, transpose_1_output, model13_m0_cv3_conv_output},
                         concatenation_2, Constant(3), 0))
    return false;
  if (!graph.Convolution(
          concatenation_2, model13_cv2_conv_weight, model13_cv2_conv_bias, model13_cv2_conv_output,
          Padding{Constant(0), Constant(0), Constant(0), Constant(0)},
          Kernel{Constant(1), Constant(1)}, Stride{Constant(1), Constant(1)},
          Dilation{Constant(1), Constant(1)}, Groups{Constant(1), Constant(192), Constant(128)},
          XNN_FLAG_YOLO26_GEMM_SILU_FINAL_STORE))
    return false;
  if (!graph.Transpose(model13_cv2_conv_output, neck_p4_output,
                       {Constant(0), Constant(3), Constant(1), Constant(2)}, 0))
    return false;
  if (!graph.Convolution(
          model13_cv2_conv_output, model16_cv1_conv_weight_input0128, projection_zero_bias64,
          p4_projection_output, Padding{Constant(0), Constant(0), Constant(0), Constant(0)},
          Kernel{Constant(1), Constant(1)}, Stride{Constant(1), Constant(1)},
          Dilation{Constant(1), Constant(1)}, Groups{Constant(1), Constant(128), Constant(64)}, 0))
    return false;
  return graph.Finish();
}

// Projects the backbone P3 feature and adds the upsampled P4 projection. The
// schedule splits the result into the two model.16 branches.
bool BuildNeckP3Fusion(const GraphContext& context) {
  FixedGraphBuilder graph(context, GraphId::kNeckP3Fusion, NeckP3FusionBindings::kCount);
  if (!graph.Begin()) return false;
  [[maybe_unused]] const GraphValue reserved_value_0 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), Constant(128), ResolutionDivided(8), ResolutionDivided(8)});
  [[maybe_unused]] const GraphValue reserved_value_1 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), Constant(128), ResolutionDivided(8), ResolutionDivided(8)});
  [[maybe_unused]] const GraphValue reserved_value_2 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), Constant(256), ResolutionDivided(8), ResolutionDivided(8)});
  const GraphValue upsampled_p4_input = graph.DefineInput(
      ValueType::kFp16, {Constant(1), ResolutionDivided(8), ResolutionDivided(8), Constant(64)},
      NeckP3FusionBindings::kUpsampledP4Input);
  const GraphValue model16_cv1_conv_weight_input128256 =
      graph.DefineWeight(ValueType::kFp32, {Constant(64), Constant(1), Constant(1), Constant(128)},
                         WeightSlot::kModel16Cv1ConvWeightInput128256);
  [[maybe_unused]] const GraphValue reserved_value_5 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(8), ResolutionDivided(8), Constant(64)});
  const GraphValue model16_cv1_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(64)}, WeightSlot::kModel16Cv1ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_7 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(8), ResolutionDivided(8), Constant(64)});
  const GraphValue model16_cv1_conv_weight_input128256_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(8), ResolutionDivided(8), Constant(64)});
  [[maybe_unused]] const GraphValue reserved_value_9 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), Constant(64), ResolutionDivided(8), ResolutionDivided(8)});
  [[maybe_unused]] const GraphValue reserved_value_10 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(8), ResolutionDivided(8), Constant(64)});
  const GraphValue fusion_output = graph.DefineInput(
      ValueType::kFp16, {Constant(1), ResolutionDivided(8), ResolutionDivided(8), Constant(128)},
      NeckP3FusionBindings::kFusionOutput);
  [[maybe_unused]] const GraphValue reserved_value_12 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(8), ResolutionDivided(8), Constant(128)});
  const GraphValue residual_sum_1 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(8), ResolutionDivided(8), Constant(64)});
  const GraphValue backbone_p3_input = graph.DefineOutput(
      ValueType::kFp16, {Constant(1), ResolutionDivided(8), ResolutionDivided(8), Constant(64)},
      NeckP3FusionBindings::kBackboneP3Input);
  if (!graph.DefinitionsValid()) return false;
  if (!graph.Convolution(fusion_output, model16_cv1_conv_weight_input128256, model16_cv1_conv_bias,
                         model16_cv1_conv_weight_input128256_output,
                         Padding{Constant(0), Constant(0), Constant(0), Constant(0)},
                         Kernel{Constant(1), Constant(1)}, Stride{Constant(1), Constant(1)},
                         Dilation{Constant(1), Constant(1)},
                         Groups{Constant(1), Constant(128), Constant(64)}, 0))
    return false;
  if (!graph.Add(upsampled_p4_input, model16_cv1_conv_weight_input128256_output, residual_sum_1, 0))
    return false;
  if (!graph.Silu(residual_sum_1, backbone_p3_input, 0)) return false;
  return graph.Finish();
}