Skip to content

Commit 0bf018f

Browse files
authored
Add Yolo26 to matrix of tested models on RISC-V (#19741)
### Summary It relates to #18833. It doesn't add Yolo on baremetal, but it at least makes sure that it works using Portable Kernels and XNNPACK backends. ### Test plan It's only adding a model to CI, so the CI is the test plan.
1 parent a89f1b4 commit 0bf018f

4 files changed

Lines changed: 54 additions & 16 deletions

File tree

.github/workflows/riscv64.yml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,22 @@ jobs:
2828
strategy:
2929
fail-fast: false
3030
matrix:
31-
include:
32-
- { model: add, xnnpack: false, quantize: false }
33-
- { model: add, xnnpack: true, quantize: false }
34-
- { model: mv2, xnnpack: false, quantize: false }
35-
- { model: mv2, xnnpack: true, quantize: false }
36-
- { model: mv2, xnnpack: true, quantize: true }
37-
- { model: mobilebert, xnnpack: false, quantize: false }
38-
- { model: mobilebert, xnnpack: true, quantize: false }
39-
- { model: mobilebert, xnnpack: true, quantize: true }
40-
- { model: llama2, xnnpack: false, quantize: false }
41-
- { model: llama2, xnnpack: true, quantize: false }
42-
- { model: llama2, xnnpack: true, quantize: true }
43-
- { model: resnet18, xnnpack: false, quantize: false }
44-
- { model: resnet18, xnnpack: true, quantize: false }
45-
- { model: resnet18, xnnpack: true, quantize: true }
31+
model:
32+
- add
33+
- mv2
34+
- mobilebert
35+
- llama2
36+
- resnet18
37+
- yolo26
38+
xnnpack: [true, false]
39+
quantize: [true, false]
40+
exclude:
41+
# We only enable quantization with XNNPACK
42+
- xnnpack: false
43+
quantize: true
44+
# We don't test quantization for Yolo26
45+
- model: yolo26
46+
quantize: true
4647
permissions:
4748
id-token: write
4849
contents: read

examples/riscv/aot_riscv.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,45 @@ def build_resnet18():
114114
return model, example_inputs, test_inputs, False
115115

116116

117+
def build_yolo26():
118+
# Mirrors examples/models/yolo26/export_and_validate.py: predict() once
119+
# to materialise the predictor state Ultralytics expects pre-export.
120+
import numpy as np
121+
from ultralytics import YOLO
122+
123+
input_h, input_w = 320, 320
124+
yolo = YOLO("yolo26n")
125+
yolo.predict(
126+
np.ones((input_h, input_w, 3)),
127+
imgsz=(input_h, input_w),
128+
device="cpu",
129+
)
130+
131+
class Wrapper(torch.nn.Module):
132+
def __init__(self):
133+
super().__init__()
134+
self.model = yolo.model.to(torch.device("cpu")).eval()
135+
136+
def forward(self, x):
137+
# yolo.model emits (predictions, feature_maps) in eval; keep the
138+
# predictions tensor so BundledIO sees a single tensor output.
139+
out = self.model(x)
140+
return out[0] if isinstance(out, (tuple, list)) else out
141+
142+
model = Wrapper().eval()
143+
torch.manual_seed(0)
144+
example_inputs = (torch.randn(1, 3, input_h, input_w),)
145+
test_inputs = [example_inputs]
146+
return model, example_inputs, test_inputs, False
147+
148+
117149
MODELS = {
118150
"add": build_add,
119151
"mv2": build_mv2,
120152
"mobilebert": build_mobilebert,
121153
"llama2": build_llama2,
122154
"resnet18": build_resnet18,
155+
"yolo26": build_yolo26,
123156
}
124157

125158

examples/riscv/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
torchvision
22
transformers
3+
ultralytics

examples/riscv/setup.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ ${SUDO} apt-get install -y --no-install-recommends \
3333
cmake \
3434
file \
3535
ca-certificates \
36-
qemu-user-static
36+
qemu-user-static \
37+
libglib2.0-0t64 \
38+
libxcb1 \
39+
libgl1
3740

3841
if [[ -n "${GCC_VERSION+x}" ]]; then
3942
${SUDO} update-alternatives --install /usr/bin/riscv64-linux-gnu-gcc riscv64-linux-gnu-gcc /usr/bin/riscv64-linux-gnu-gcc${GCC_VERSION:+-${GCC_VERSION}} 100

0 commit comments

Comments
 (0)