File size: 57,021 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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
// Fixed backbone partitions from the P4 feature level through the P5 attention
// block. Reserved values reproduce XNNPACK's performance-sensitive declaration
// inventory but intentionally do not participate in data flow.

// Completes the model.6 P4 block, downsamples through model.7, and begins the
// model.8 P5 block. The schedule supplies the two halves of the P4 entry.
bool BuildBackboneP4ToP5(const GraphContext& context) {
  FixedGraphBuilder graph(context, GraphId::kBackboneP4ToP5, BackboneP4ToP5Bindings::kCount);
  if (!graph.Begin()) return false;
  const GraphValue main_input = graph.DefineInput(
      ValueType::kFp16, {Constant(1), Constant(64), ResolutionDivided(16), ResolutionDivided(16)},
      BackboneP4ToP5Bindings::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)},
      BackboneP4ToP5Bindings::kSkipInput);
  const GraphValue transpose_2_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(64)});
  const GraphValue model6_m0_cv1_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(32), Constant(1), Constant(1), Constant(64)},
                         WeightSlot::kModel6M0Cv1ConvWeight);
  [[maybe_unused]] const GraphValue reserved_value_5 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model6_m0_cv1_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(32)}, WeightSlot::kModel6M0Cv1ConvBias);
  const GraphValue model6_m0_cv2_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(32), Constant(1), Constant(1), Constant(64)},
                         WeightSlot::kModel6M0Cv2ConvWeight);
  [[maybe_unused]] const GraphValue reserved_value_8 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model6_m0_cv2_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(32)}, WeightSlot::kModel6M0Cv2ConvBias);
  [[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 model6_m0_cv1_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model6_m0_cv2_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model6_m0_m0_cv1_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(32), Constant(3), Constant(3), Constant(32)},
                         WeightSlot::kModel6M0M0Cv1ConvWeight);
  const GraphValue model6_m0_m0_cv1_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model6_m0_m0_cv1_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(32)}, WeightSlot::kModel6M0M0Cv1ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_17 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model6_m0_m0_cv1_conv_activation = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model6_m0_m0_cv2_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(32), Constant(3), Constant(3), Constant(32)},
                         WeightSlot::kModel6M0M0Cv2ConvWeight);
  const GraphValue model6_m0_m0_cv2_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model6_m0_m0_cv2_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(32)}, WeightSlot::kModel6M0M0Cv2ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_22 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model6_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 model6_m0_m1_cv1_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(32), Constant(3), Constant(3), Constant(32)},
                         WeightSlot::kModel6M0M1Cv1ConvWeight);
  const GraphValue model6_m0_m1_cv1_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model6_m0_m1_cv1_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(32)}, WeightSlot::kModel6M0M1Cv1ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_28 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model6_m0_m1_cv1_conv_activation = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model6_m0_m1_cv2_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(32), Constant(3), Constant(3), Constant(32)},
                         WeightSlot::kModel6M0M1Cv2ConvWeight);
  const GraphValue model6_m0_m1_cv2_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model6_m0_m1_cv2_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(32)}, WeightSlot::kModel6M0M1Cv2ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_33 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(32)});
  const GraphValue model6_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 model6_m0_cv3_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(64), Constant(1), Constant(1), Constant(64)},
                         WeightSlot::kModel6M0Cv3ConvWeight);
  [[maybe_unused]] const GraphValue reserved_value_38 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(64)});
  const GraphValue model6_m0_cv3_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(64)}, WeightSlot::kModel6M0Cv3ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_40 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(64)});
  const GraphValue model6_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 model6_cv2_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(128), Constant(1), Constant(1), Constant(192)},
                         WeightSlot::kModel6Cv2ConvWeight);
  [[maybe_unused]] const GraphValue reserved_value_44 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(128)});
  const GraphValue model6_cv2_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(128)}, WeightSlot::kModel6Cv2ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_46 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(128)});
  const GraphValue model6_cv2_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(16), ResolutionDivided(16), Constant(128)});
  const GraphValue p4_output = graph.DefineOutput(
      ValueType::kFp16, {Constant(1), Constant(128), ResolutionDivided(16), ResolutionDivided(16)},
      BackboneP4ToP5Bindings::kP4Output);
  const GraphValue model7_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(256), Constant(3), Constant(3), Constant(128)},
                         WeightSlot::kModel7ConvWeight);
  const GraphValue model7_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue model7_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(256)}, WeightSlot::kModel7ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_52 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue model7_conv_activation = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue model8_cv1_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(256), Constant(1), Constant(1), Constant(256)},
                         WeightSlot::kModel8Cv1ConvWeight);
  [[maybe_unused]] const GraphValue reserved_value_55 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue model8_cv1_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(256)}, WeightSlot::kModel8Cv1ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_57 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue model8_cv1_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue p5_entry_output = graph.DefineOutput(
      ValueType::kFp16, {Constant(1), Constant(256), ResolutionDivided(32), ResolutionDivided(32)},
      BackboneP4ToP5Bindings::kP5EntryOutput);
  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, model6_m0_cv1_conv_weight, model6_m0_cv1_conv_bias,
          model6_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, model6_m0_cv2_conv_weight, model6_m0_cv2_conv_bias,
          model6_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(
          model6_m0_cv1_conv_output, model6_m0_m0_cv1_conv_weight, model6_m0_m0_cv1_conv_bias,
          model6_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(model6_m0_m0_cv1_conv_output, model6_m0_m0_cv1_conv_activation, 0)) return false;
  if (!graph.Convolution(model6_m0_m0_cv1_conv_activation, model6_m0_m0_cv2_conv_weight,
                         model6_m0_m0_cv2_conv_bias, model6_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(model6_m0_m0_cv2_conv_output, model6_m0_m0_cv2_conv_activation, 0)) return false;
  if (!graph.Add(model6_m0_cv1_conv_output, model6_m0_m0_cv2_conv_activation, residual_sum_1, 0))
    return false;
  if (!graph.Convolution(
          residual_sum_1, model6_m0_m1_cv1_conv_weight, model6_m0_m1_cv1_conv_bias,
          model6_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(model6_m0_m1_cv1_conv_output, model6_m0_m1_cv1_conv_activation, 0)) return false;
  if (!graph.Convolution(model6_m0_m1_cv1_conv_activation, model6_m0_m1_cv2_conv_weight,
                         model6_m0_m1_cv2_conv_bias, model6_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(model6_m0_m1_cv2_conv_output, model6_m0_m1_cv2_conv_activation, 0)) return false;
  if (!graph.Add(residual_sum_1, model6_m0_m1_cv2_conv_activation, residual_sum_2, 0)) return false;
  if (!graph.Concatenate({residual_sum_2, model6_m0_cv2_conv_output}, concatenation_1, Constant(3),
                         0))
    return false;
  if (!graph.Convolution(
          concatenation_1, model6_m0_cv3_conv_weight, model6_m0_cv3_conv_bias,
          model6_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, model6_m0_cv3_conv_output},
                         concatenation_2, Constant(3), 0))
    return false;
  if (!graph.Convolution(
          concatenation_2, model6_cv2_conv_weight, model6_cv2_conv_bias, model6_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(model6_cv2_conv_output, p4_output,
                       {Constant(0), Constant(3), Constant(1), Constant(2)}, 0))
    return false;
  if (!graph.Convolution(
          model6_cv2_conv_output, model7_conv_weight, model7_conv_bias, model7_conv_output,
          Padding{Constant(1), Constant(1), Constant(1), Constant(1)},
          Kernel{Constant(3), Constant(3)}, Stride{Constant(2), Constant(2)},
          Dilation{Constant(1), Constant(1)}, Groups{Constant(1), Constant(128), Constant(256)}, 0))
    return false;
  if (!graph.Silu(model7_conv_output, model7_conv_activation, 0)) return false;
  if (!graph.Convolution(
          model7_conv_activation, model8_cv1_conv_weight, model8_cv1_conv_bias,
          model8_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(256), Constant(256)},
          XNN_FLAG_YOLO26_GEMM_SILU_FINAL_STORE))
    return false;
  if (!graph.Transpose(model8_cv1_conv_output, p5_entry_output,
                       {Constant(0), Constant(3), Constant(1), Constant(2)}, 0))
    return false;
  return graph.Finish();
}

// Completes model.8 and model.10.cv1, producing the bypass and residual inputs
// consumed by the P5 attention partitions.
bool BuildBackboneP5ToAttention(const GraphContext& context) {
  FixedGraphBuilder graph(context, GraphId::kBackboneP5ToAttention,
                          BackboneP5ToAttentionBindings::kCount);
  if (!graph.Begin()) return false;
  const GraphValue main_input = graph.DefineInput(
      ValueType::kFp16, {Constant(1), Constant(128), ResolutionDivided(32), ResolutionDivided(32)},
      BackboneP5ToAttentionBindings::kMainInput);
  const GraphValue transpose_1_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue skip_input = graph.DefineInput(
      ValueType::kFp16, {Constant(1), Constant(128), ResolutionDivided(32), ResolutionDivided(32)},
      BackboneP5ToAttentionBindings::kSkipInput);
  const GraphValue transpose_2_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue model8_m0_cv1_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(64), Constant(1), Constant(1), Constant(128)},
                         WeightSlot::kModel8M0Cv1ConvWeight);
  [[maybe_unused]] const GraphValue reserved_value_5 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(64)});
  const GraphValue model8_m0_cv1_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(64)}, WeightSlot::kModel8M0Cv1ConvBias);
  const GraphValue model8_m0_cv2_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(64), Constant(1), Constant(1), Constant(128)},
                         WeightSlot::kModel8M0Cv2ConvWeight);
  [[maybe_unused]] const GraphValue reserved_value_8 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(64)});
  const GraphValue model8_m0_cv2_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(64)}, WeightSlot::kModel8M0Cv2ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_10 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(64)});
  [[maybe_unused]] const GraphValue reserved_value_11 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(64)});
  const GraphValue model8_m0_cv1_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(64)});
  const GraphValue model8_m0_cv2_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(64)});
  const GraphValue model8_m0_m0_cv1_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(64), Constant(3), Constant(3), Constant(64)},
                         WeightSlot::kModel8M0M0Cv1ConvWeight);
  const GraphValue model8_m0_m0_cv1_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(64)});
  const GraphValue model8_m0_m0_cv1_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(64)}, WeightSlot::kModel8M0M0Cv1ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_17 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(64)});
  const GraphValue model8_m0_m0_cv1_conv_activation = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(64)});
  const GraphValue model8_m0_m0_cv2_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(64), Constant(3), Constant(3), Constant(64)},
                         WeightSlot::kModel8M0M0Cv2ConvWeight);
  const GraphValue model8_m0_m0_cv2_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(64)});
  const GraphValue model8_m0_m0_cv2_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(64)}, WeightSlot::kModel8M0M0Cv2ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_22 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(64)});
  const GraphValue model8_m0_m0_cv2_conv_activation = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(64)});
  const GraphValue residual_sum_1 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(64)});
  const GraphValue model8_m0_m1_cv1_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(64), Constant(3), Constant(3), Constant(64)},
                         WeightSlot::kModel8M0M1Cv1ConvWeight);
  const GraphValue model8_m0_m1_cv1_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(64)});
  const GraphValue model8_m0_m1_cv1_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(64)}, WeightSlot::kModel8M0M1Cv1ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_28 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(64)});
  const GraphValue model8_m0_m1_cv1_conv_activation = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(64)});
  const GraphValue model8_m0_m1_cv2_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(64), Constant(3), Constant(3), Constant(64)},
                         WeightSlot::kModel8M0M1Cv2ConvWeight);
  const GraphValue model8_m0_m1_cv2_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(64)});
  const GraphValue model8_m0_m1_cv2_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(64)}, WeightSlot::kModel8M0M1Cv2ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_33 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(64)});
  const GraphValue model8_m0_m1_cv2_conv_activation = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(64)});
  const GraphValue residual_sum_2 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(64)});
  const GraphValue concatenation_1 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue model8_m0_cv3_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(128), Constant(1), Constant(1), Constant(128)},
                         WeightSlot::kModel8M0Cv3ConvWeight);
  [[maybe_unused]] const GraphValue reserved_value_38 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue model8_m0_cv3_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(128)}, WeightSlot::kModel8M0Cv3ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_40 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue model8_m0_cv3_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue concatenation_2 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(384)});
  const GraphValue model8_cv2_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(256), Constant(1), Constant(1), Constant(384)},
                         WeightSlot::kModel8Cv2ConvWeight);
  [[maybe_unused]] const GraphValue reserved_value_44 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue model8_cv2_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(256)}, WeightSlot::kModel8Cv2ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_46 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue model8_cv2_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue model9_cv1_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(128), Constant(1), Constant(1), Constant(256)},
                         WeightSlot::kModel9Cv1ConvWeight);
  const GraphValue model9_cv1_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue model9_cv1_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(128)}, WeightSlot::kModel9Cv1ConvBias);
  const GraphValue max_pool_1_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue max_pool_2_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue max_pool_3_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue concatenation_3 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(512)});
  const GraphValue model9_cv2_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(256), Constant(1), Constant(1), Constant(512)},
                         WeightSlot::kModel9Cv2ConvWeight);
  [[maybe_unused]] const GraphValue reserved_value_56 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue model9_cv2_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(256)}, WeightSlot::kModel9Cv2ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_58 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue model9_cv2_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue residual_sum_3 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue model10_cv1_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(256), Constant(1), Constant(1), Constant(256)},
                         WeightSlot::kModel10Cv1ConvWeight);
  [[maybe_unused]] const GraphValue reserved_value_62 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue model10_cv1_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(256)}, WeightSlot::kModel10Cv1ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_64 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue model10_cv1_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue attention_entry_output = graph.DefineOutput(
      ValueType::kFp16, {Constant(1), Constant(256), ResolutionDivided(32), ResolutionDivided(32)},
      BackboneP5ToAttentionBindings::kAttentionEntryOutput);
  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, model8_m0_cv1_conv_weight, model8_m0_cv1_conv_bias,
          model8_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(128), Constant(64)},
          XNN_FLAG_YOLO26_GEMM_SILU_FINAL_STORE))
    return false;
  if (!graph.Convolution(
          transpose_1_output, model8_m0_cv2_conv_weight, model8_m0_cv2_conv_bias,
          model8_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(128), Constant(64)},
          XNN_FLAG_YOLO26_GEMM_SILU_FINAL_STORE))
    return false;
  if (!graph.Convolution(
          model8_m0_cv1_conv_output, model8_m0_m0_cv1_conv_weight, model8_m0_m0_cv1_conv_bias,
          model8_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(64), Constant(64)}, 0))
    return false;
  if (!graph.Silu(model8_m0_m0_cv1_conv_output, model8_m0_m0_cv1_conv_activation, 0)) return false;
  if (!graph.Convolution(model8_m0_m0_cv1_conv_activation, model8_m0_m0_cv2_conv_weight,
                         model8_m0_m0_cv2_conv_bias, model8_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(64), Constant(64)}, 0))
    return false;
  if (!graph.Silu(model8_m0_m0_cv2_conv_output, model8_m0_m0_cv2_conv_activation, 0)) return false;
  if (!graph.Add(model8_m0_cv1_conv_output, model8_m0_m0_cv2_conv_activation, residual_sum_1, 0))
    return false;
  if (!graph.Convolution(
          residual_sum_1, model8_m0_m1_cv1_conv_weight, model8_m0_m1_cv1_conv_bias,
          model8_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(64), Constant(64)}, 0))
    return false;
  if (!graph.Silu(model8_m0_m1_cv1_conv_output, model8_m0_m1_cv1_conv_activation, 0)) return false;
  if (!graph.Convolution(model8_m0_m1_cv1_conv_activation, model8_m0_m1_cv2_conv_weight,
                         model8_m0_m1_cv2_conv_bias, model8_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(64), Constant(64)}, 0))
    return false;
  if (!graph.Silu(model8_m0_m1_cv2_conv_output, model8_m0_m1_cv2_conv_activation, 0)) return false;
  if (!graph.Add(residual_sum_1, model8_m0_m1_cv2_conv_activation, residual_sum_2, 0)) return false;
  if (!graph.Concatenate({residual_sum_2, model8_m0_cv2_conv_output}, concatenation_1, Constant(3),
                         0))
    return false;
  if (!graph.Convolution(
          concatenation_1, model8_m0_cv3_conv_weight, model8_m0_cv3_conv_bias,
          model8_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(128), Constant(128)},
          XNN_FLAG_YOLO26_GEMM_SILU_FINAL_STORE))
    return false;
  if (!graph.Concatenate({transpose_2_output, transpose_1_output, model8_m0_cv3_conv_output},
                         concatenation_2, Constant(3), 0))
    return false;
  if (!graph.Convolution(
          concatenation_2, model8_cv2_conv_weight, model8_cv2_conv_bias, model8_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(384), Constant(256)},
          XNN_FLAG_YOLO26_GEMM_SILU_FINAL_STORE))
    return false;
  if (!graph.Convolution(
          model8_cv2_conv_output, model9_cv1_conv_weight, model9_cv1_conv_bias,
          model9_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(256), Constant(128)}, 0))
    return false;
  if (!graph.MaxPool(model9_cv1_conv_output, max_pool_1_output,
                     Padding{Constant(2), Constant(2), Constant(2), Constant(2)},
                     Kernel{Constant(5), Constant(5)}, Stride{Constant(1), Constant(1)},
                     Dilation{Constant(1), Constant(1)}, 64U))
    return false;
  if (!graph.MaxPool(max_pool_1_output, max_pool_2_output,
                     Padding{Constant(2), Constant(2), Constant(2), Constant(2)},
                     Kernel{Constant(5), Constant(5)}, Stride{Constant(1), Constant(1)},
                     Dilation{Constant(1), Constant(1)}, 64U))
    return false;
  if (!graph.MaxPool(max_pool_2_output, max_pool_3_output,
                     Padding{Constant(2), Constant(2), Constant(2), Constant(2)},
                     Kernel{Constant(5), Constant(5)}, Stride{Constant(1), Constant(1)},
                     Dilation{Constant(1), Constant(1)}, 64U))
    return false;
  if (!graph.Concatenate(
          {model9_cv1_conv_output, max_pool_1_output, max_pool_2_output, max_pool_3_output},
          concatenation_3, Constant(3), 0))
    return false;
  if (!graph.Convolution(
          concatenation_3, model9_cv2_conv_weight, model9_cv2_conv_bias, model9_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(512), Constant(256)},
          XNN_FLAG_YOLO26_GEMM_SILU_FINAL_STORE))
    return false;
  if (!graph.Add(model9_cv2_conv_output, model8_cv2_conv_output, residual_sum_3, 0)) return false;
  if (!graph.Convolution(
          residual_sum_3, model10_cv1_conv_weight, model10_cv1_conv_bias, model10_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(256), Constant(256)},
          XNN_FLAG_YOLO26_GEMM_SILU_FINAL_STORE))
    return false;
  if (!graph.Transpose(model10_cv1_conv_output, attention_entry_output,
                       {Constant(0), Constant(3), Constant(1), Constant(2)}, 0))
    return false;
  return graph.Finish();
}

// Projects the P5 residual branch into two attention heads containing query,
// key, and value channels; the schedule performs the channel split.
bool BuildBackboneAttentionQkv(const GraphContext& context) {
  FixedGraphBuilder graph(context, GraphId::kBackboneAttentionQkv,
                          BackboneAttentionQkvBindings::kCount);
  if (!graph.Begin()) return false;
  const GraphValue residual_input = graph.DefineInput(
      ValueType::kFp16, {Constant(1), Constant(128), ResolutionDivided(32), ResolutionDivided(32)},
      BackboneAttentionQkvBindings::kResidualInput);
  const GraphValue transpose_1_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue model10_m0_attn_qkv_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(256), Constant(1), Constant(1), Constant(128)},
                         WeightSlot::kModel10M0AttnQkvConvWeight);
  const GraphValue model10_m0_attn_qkv_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue model10_m0_attn_qkv_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(256)}, WeightSlot::kModel10M0AttnQkvConvBias);
  const GraphValue transpose_2_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), Constant(256), ResolutionDivided(32), ResolutionDivided(32)});
  const GraphValue qkv_output = graph.DefineOutput(
      ValueType::kFp16, {Constant(1), Constant(2), Constant(128), ResolutionDividedSquared(32)},
      BackboneAttentionQkvBindings::kQkvOutput);
  if (!graph.DefinitionsValid()) return false;
  if (!graph.Transpose(residual_input, transpose_1_output,
                       {Constant(0), Constant(2), Constant(3), Constant(1)}, 0))
    return false;
  if (!graph.Convolution(transpose_1_output, model10_m0_attn_qkv_conv_weight,
                         model10_m0_attn_qkv_conv_bias, model10_m0_attn_qkv_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(128), Constant(256)}, 0))
    return false;
  if (!graph.Transpose(model10_m0_attn_qkv_conv_output, transpose_2_output,
                       {Constant(0), Constant(3), Constant(1), Constant(2)}, 0))
    return false;
  if (!graph.Reshape(transpose_2_output, qkv_output,
                     {Constant(1), Constant(2), Constant(128), ResolutionDividedSquared(32)}, 0))
    return false;
  return graph.Finish();
}

// Scales each query by 1 / sqrt(head width) and transposes it for QK matrix
// multiplication.
bool BuildBackboneAttentionScale(const GraphContext& context) {
  FixedGraphBuilder graph(context, GraphId::kBackboneAttentionScale,
                          BackboneAttentionScaleBindings::kCount);
  if (!graph.Begin()) return false;
  const GraphValue query_input = graph.DefineInput(
      ValueType::kFp16, {Constant(1), Constant(2), Constant(32), ResolutionDividedSquared(32)},
      BackboneAttentionScaleBindings::kQueryInput);
  const GraphValue scale_input = graph.DefineInput(ValueType::kFp16, {Constant(1)},
                                                   BackboneAttentionScaleBindings::kScaleInput);
  const GraphValue product_1 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), Constant(2), Constant(32), ResolutionDividedSquared(32)});
  const GraphValue scaled_query_output = graph.DefineOutput(
      ValueType::kFp16, {Constant(1), Constant(2), ResolutionDividedSquared(32), Constant(32)},
      BackboneAttentionScaleBindings::kScaledQueryOutput);
  if (!graph.DefinitionsValid()) return false;
  if (!graph.Multiply(query_input, scale_input, product_1, 0)) return false;
  if (!graph.Transpose(product_1, scaled_query_output,
                       {Constant(0), Constant(1), Constant(3), Constant(2)}, 0))
    return false;
  return graph.Finish();
}

// Computes and normalizes the two P5 attention matrices. Copies at the
// partition boundary are owned by the schedule.
bool BuildBackboneAttentionMatrix(const GraphContext& context) {
  FixedGraphBuilder graph(context, GraphId::kBackboneAttentionMatrix,
                          BackboneAttentionMatrixBindings::kCount);
  if (!graph.Begin()) return false;
  const GraphValue reshape_1_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(2), Constant(32), ResolutionDividedSquared(32)});
  const GraphValue key_input = graph.DefineInput(
      ValueType::kFp16, {Constant(1), Constant(2), Constant(32), ResolutionDividedSquared(32)},
      BackboneAttentionMatrixBindings::kKeyInput);
  const GraphValue reshape_2_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(2), ResolutionDividedSquared(32), Constant(32)});
  const GraphValue query_input = graph.DefineInput(
      ValueType::kFp16, {Constant(1), Constant(2), ResolutionDividedSquared(32), Constant(32)},
      BackboneAttentionMatrixBindings::kQueryInput);
  const GraphValue matrix_product_1 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(2), ResolutionDividedSquared(32), ResolutionDividedSquared(32)});
  const GraphValue reshape_3_output = graph.DefineIntermediate(
      ValueType::kFp16,
      {Constant(1), Constant(2), ResolutionDividedSquared(32), ResolutionDividedSquared(32)});
  const GraphValue softmax_1_output = graph.DefineIntermediate(
      ValueType::kFp16,
      {Constant(1), Constant(2), ResolutionDividedSquared(32), ResolutionDividedSquared(32)});
  const GraphValue matrix_output = graph.DefineOutput(
      ValueType::kFp16,
      {Constant(1), Constant(2), ResolutionDividedSquared(32), ResolutionDividedSquared(32)},
      BackboneAttentionMatrixBindings::kMatrixOutput);
  if (!graph.DefinitionsValid()) return false;
  if (!graph.Reshape(key_input, reshape_1_output,
                     {Constant(2), Constant(32), ResolutionDividedSquared(32)}, 0))
    return false;
  if (!graph.Reshape(query_input, reshape_2_output,
                     {Constant(2), ResolutionDividedSquared(32), Constant(32)}, 0))
    return false;
  if (!graph.BatchMatrixMultiply(reshape_2_output, reshape_1_output, matrix_product_1, 0))
    return false;
  if (!graph.Reshape(
          matrix_product_1, reshape_3_output,
          {Constant(1), Constant(2), ResolutionDividedSquared(32), ResolutionDividedSquared(32)},
          0))
    return false;
  if (!graph.Softmax(reshape_3_output, softmax_1_output, 0)) return false;
  if (!graph.Transpose(softmax_1_output, matrix_output,
                       {Constant(0), Constant(1), Constant(3), Constant(2)}, 0))
    return false;
  return graph.Finish();
}

// Applies attention to the values, adds positional encoding and residual/FFN
// paths, rejoins the model.10 bypass, and emits both P5 and its neck projection.
bool BuildBackboneAttentionOutput(const GraphContext& context) {
  FixedGraphBuilder graph(context, GraphId::kBackboneAttentionOutput,
                          BackboneAttentionOutputBindings::kCount);
  if (!graph.Begin()) return false;
  const GraphValue residual_input = graph.DefineInput(
      ValueType::kFp16, {Constant(1), Constant(128), ResolutionDivided(32), ResolutionDivided(32)},
      BackboneAttentionOutputBindings::kResidualInput);
  const GraphValue transpose_1_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue bypass_input = graph.DefineInput(
      ValueType::kFp16, {Constant(1), Constant(128), ResolutionDivided(32), ResolutionDivided(32)},
      BackboneAttentionOutputBindings::kBypassInput);
  const GraphValue transpose_2_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue reshape_1_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(2), Constant(64), ResolutionDividedSquared(32)});
  const GraphValue value_input = graph.DefineInput(
      ValueType::kFp16, {Constant(1), Constant(2), Constant(64), ResolutionDividedSquared(32)},
      BackboneAttentionOutputBindings::kValueInput);
  const GraphValue reshape_2_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), Constant(128), ResolutionDivided(32), ResolutionDivided(32)});
  const GraphValue positional_input = graph.DefineInput(
      ValueType::kFp16, {Constant(1), Constant(2), Constant(64), ResolutionDividedSquared(32)},
      BackboneAttentionOutputBindings::kPositionalInput);
  const GraphValue transpose_3_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue model10_m0_attn_pe_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(1), Constant(3), Constant(3), Constant(128)},
                         WeightSlot::kModel10M0AttnPeConvWeight);
  const GraphValue model10_m0_attn_pe_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue model10_m0_attn_pe_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(128)}, WeightSlot::kModel10M0AttnPeConvBias);
  const GraphValue reshape_3_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(2), ResolutionDividedSquared(32), ResolutionDividedSquared(32)});
  const GraphValue matrix_input = graph.DefineInput(
      ValueType::kFp16,
      {Constant(1), Constant(2), ResolutionDividedSquared(32), ResolutionDividedSquared(32)},
      BackboneAttentionOutputBindings::kMatrixInput);
  const GraphValue matrix_product_1 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(2), Constant(64), ResolutionDividedSquared(32)});
  const GraphValue reshape_4_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), Constant(2), Constant(64), ResolutionDividedSquared(32)});
  const GraphValue reshape_5_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), Constant(128), ResolutionDivided(32), ResolutionDivided(32)});
  const GraphValue transpose_4_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue residual_sum_1 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue model10_m0_attn_proj_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(128), Constant(1), Constant(1), Constant(128)},
                         WeightSlot::kModel10M0AttnProjConvWeight);
  const GraphValue model10_m0_attn_proj_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue model10_m0_attn_proj_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(128)}, WeightSlot::kModel10M0AttnProjConvBias);
  const GraphValue residual_sum_2 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue model10_m0_ffn0_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(256), Constant(1), Constant(1), Constant(128)},
                         WeightSlot::kModel10M0Ffn0ConvWeight);
  [[maybe_unused]] const GraphValue reserved_value_24 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue model10_m0_ffn0_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(256)}, WeightSlot::kModel10M0Ffn0ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_26 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue model10_m0_ffn0_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue model10_m0_ffn1_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(128), Constant(1), Constant(1), Constant(256)},
                         WeightSlot::kModel10M0Ffn1ConvWeight);
  const GraphValue model10_m0_ffn1_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue model10_m0_ffn1_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(128)}, WeightSlot::kModel10M0Ffn1ConvBias);
  const GraphValue residual_sum_3 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)});
  const GraphValue concatenation_1 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue model10_cv2_conv_weight =
      graph.DefineWeight(ValueType::kFp32, {Constant(256), Constant(1), Constant(1), Constant(256)},
                         WeightSlot::kModel10Cv2ConvWeight);
  [[maybe_unused]] const GraphValue reserved_value_34 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue model10_cv2_conv_bias =
      graph.DefineWeight(ValueType::kFp32, {Constant(256)}, WeightSlot::kModel10Cv2ConvBias);
  [[maybe_unused]] const GraphValue reserved_value_36 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue model10_cv2_conv_output = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(256)});
  const GraphValue backbone_output = graph.DefineOutput(
      ValueType::kFp16, {Constant(1), Constant(256), ResolutionDivided(32), ResolutionDivided(32)},
      BackboneAttentionOutputBindings::kBackboneOutput);
  const GraphValue model13_cv1_conv_weight_input0256 =
      graph.DefineWeight(ValueType::kFp32, {Constant(128), Constant(1), Constant(1), Constant(256)},
                         WeightSlot::kModel13Cv1ConvWeightInput0256);
  const GraphValue projection_zero_bias128 =
      graph.DefineWeight(ValueType::kFp32, {Constant(128)}, WeightSlot::kProjectionZeroBias128);
  const GraphValue p5_projection_output = graph.DefineOutput(
      ValueType::kFp16, {Constant(1), ResolutionDivided(32), ResolutionDivided(32), Constant(128)},
      BackboneAttentionOutputBindings::kP5ProjectionOutput);
  [[maybe_unused]] const GraphValue reserved_value_42 = graph.DefineIntermediate(
      ValueType::kFp16, {Constant(1), Constant(128), ResolutionDivided(32), ResolutionDivided(32)});
  if (!graph.DefinitionsValid()) return false;
  if (!graph.Transpose(residual_input, transpose_1_output,
                       {Constant(0), Constant(2), Constant(3), Constant(1)}, 0))
    return false;
  if (!graph.Transpose(bypass_input, transpose_2_output,
                       {Constant(0), Constant(2), Constant(3), Constant(1)}, 0))
    return false;
  if (!graph.Reshape(value_input, reshape_1_output,
                     {Constant(2), Constant(64), ResolutionDividedSquared(32)}, 0))
    return false;
  if (!graph.Reshape(positional_input, reshape_2_output,
                     {Constant(1), Constant(128), ResolutionDivided(32), ResolutionDivided(32)}, 0))
    return false;
  if (!graph.Transpose(reshape_2_output, transpose_3_output,
                       {Constant(0), Constant(2), Constant(3), Constant(1)}, 0))
    return false;
  if (!graph.DepthwiseConvolution(
          transpose_3_output, model10_m0_attn_pe_conv_weight, model10_m0_attn_pe_conv_bias,
          model10_m0_attn_pe_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(128), Constant(1), Constant(1)}, 0))
    return false;
  if (!graph.Reshape(matrix_input, reshape_3_output,
                     {Constant(2), ResolutionDividedSquared(32), ResolutionDividedSquared(32)}, 0))
    return false;
  if (!graph.BatchMatrixMultiply(reshape_1_output, reshape_3_output, matrix_product_1, 0))
    return false;
  if (!graph.Reshape(matrix_product_1, reshape_4_output,
                     {Constant(1), Constant(2), Constant(64), ResolutionDividedSquared(32)}, 0))
    return false;
  if (!graph.Reshape(reshape_4_output, reshape_5_output,
                     {Constant(1), Constant(128), ResolutionDivided(32), ResolutionDivided(32)}, 0))
    return false;
  if (!graph.Transpose(reshape_5_output, transpose_4_output,
                       {Constant(0), Constant(2), Constant(3), Constant(1)}, 0))
    return false;
  if (!graph.Add(transpose_4_output, model10_m0_attn_pe_conv_output, residual_sum_1, 0))
    return false;
  if (!graph.Convolution(residual_sum_1, model10_m0_attn_proj_conv_weight,
                         model10_m0_attn_proj_conv_bias, model10_m0_attn_proj_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(128), Constant(128)}, 0))
    return false;
  if (!graph.Add(transpose_1_output, model10_m0_attn_proj_conv_output, residual_sum_2, 0))
    return false;
  if (!graph.Convolution(
          residual_sum_2, model10_m0_ffn0_conv_weight, model10_m0_ffn0_conv_bias,
          model10_m0_ffn0_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(128), Constant(256)},
          XNN_FLAG_YOLO26_GEMM_SILU_FINAL_STORE))
    return false;
  if (!graph.Convolution(
          model10_m0_ffn0_conv_output, model10_m0_ffn1_conv_weight, model10_m0_ffn1_conv_bias,
          model10_m0_ffn1_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(256), Constant(128)}, 0))
    return false;
  if (!graph.Add(residual_sum_2, model10_m0_ffn1_conv_output, residual_sum_3, 0)) return false;
  if (!graph.Concatenate({transpose_2_output, residual_sum_3}, concatenation_1, Constant(3), 0))
    return false;
  if (!graph.Convolution(
          concatenation_1, model10_cv2_conv_weight, model10_cv2_conv_bias, model10_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(256), Constant(256)},
          XNN_FLAG_YOLO26_GEMM_SILU_FINAL_STORE))
    return false;
  if (!graph.Transpose(model10_cv2_conv_output, backbone_output,
                       {Constant(0), Constant(3), Constant(1), Constant(2)}, 0))
    return false;
  if (!graph.Convolution(
          model10_cv2_conv_output, model13_cv1_conv_weight_input0256, projection_zero_bias128,
          p5_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(256), Constant(128)}, 0))
    return false;
  return graph.Finish();
}