-
Notifications
You must be signed in to change notification settings - Fork 0
163 lines (144 loc) · 6.25 KB
/
Copy pathhost-validation.yml
File metadata and controls
163 lines (144 loc) · 6.25 KB
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
name: Host validation
# Hardware-free by design: no board access or cross compiler is required.
# Host CMSIS parity uses only immutable, full-SHA source checkouts.
on:
push:
pull_request:
permissions:
contents: read
concurrency:
group: host-validation-${{ github.ref }}
cancel-in-progress: true
jobs:
validate:
runs-on: ubuntu-latest
timeout-minutes: 10
env:
PIP_DISABLE_PIP_VERSION_CHECK: "1"
PYTHONDONTWRITEBYTECODE: "1"
steps:
- name: Check out source
uses: actions/checkout@v4
with:
# Provenance validation resolves the historical commit recorded by
# each result artifact and compares its Git blobs byte-for-byte.
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
cache-dependency-path: .github/requirements-host-validation.txt
- name: Install host validation dependencies
run: python -m pip install -r .github/requirements-host-validation.txt
- name: Run ESP32 result and accuracy fixtures
run: >-
python -W error -m unittest discover
-s tflm-esp32s3/tests -v
- name: Run provenance mutation tests
run: >-
python -W error -m unittest discover
-s tests -p 'test_*.py' -v
- name: Check benchmark shell syntax
shell: bash
run: |
set -euo pipefail
while IFS= read -r script; do
echo "bash -n $script"
bash -n "$script"
done < <(git ls-files '*.sh' | sort)
- name: Validate tracked JSON artifacts
run: python -W error tests/validate_tracked_json.py
- name: Validate exact TiGrIS core pins
run: python -W error scripts/check_core_versions.py --manifest-only
- name: Validate tracked Cortex-M output parity
working-directory: cortex-m-deployability
run: >-
python -W error scripts/validate_accuracy.py
results/summary.json
- name: Build and run host CMSIS-NN parity
shell: bash
run: |
set -euo pipefail
host_root="$RUNNER_TEMP/tigris-host-validation"
compiler_revision="$(python -c \
'import json; print(json.load(open("core-versions.json"))["compiler"]["commit"])')"
runtime_revision="$(python -c \
'import json; print(json.load(open("core-versions.json"))["runtime"]["commit"])')"
cmsis_revision="$(python -c \
'import json; print(json.load(open("cortex-m-deployability/results/summary.json"))["provenance"]["common"]["dependencies"]["CMSIS-NN"])')"
checkout_revision() {
local repository="$1" destination="$2" revision="$3"
git init "$destination"
git -C "$destination" remote add origin "$repository"
git -C "$destination" fetch --depth=1 origin "$revision"
git -C "$destination" checkout --detach FETCH_HEAD
test "$(git -C "$destination" rev-parse HEAD)" = "$revision"
}
checkout_revision https://github.com/raws-labs/tigris.git \
"$host_root/compiler" "$compiler_revision"
checkout_revision https://github.com/raws-labs/tigris-runtime.git \
"$host_root/runtime" "$runtime_revision"
checkout_revision https://github.com/ARM-software/CMSIS-NN.git \
"$host_root/CMSIS-NN" "$cmsis_revision"
python -m pip install --no-deps "$host_root/compiler"
HOST_ROOT="$host_root" python - <<'PY'
import os
from pathlib import Path
import numpy as np
import onnx
from onnx import TensorProto, helper, numpy_helper
root = Path(os.environ["HOST_ROOT"])
scalar_f32 = lambda name, value: numpy_helper.from_array(
np.array([value], dtype=np.float32), name)
scalar_i8 = lambda name: numpy_helper.from_array(
np.array([0], dtype=np.int8), name)
inputs = helper.make_tensor_value_info(
"input", TensorProto.FLOAT, [1, 1, 4, 4])
outputs = helper.make_tensor_value_info(
"output", TensorProto.FLOAT, [1, 1, 4, 4])
initializers = [
scalar_f32("input_scale", 0.25), scalar_i8("input_zp"),
numpy_helper.from_array(
np.array([[[[2]]]], dtype=np.int8), "weight"),
scalar_f32("weight_scale", 0.25), scalar_i8("weight_zp"),
scalar_f32("output_scale", 0.25), scalar_i8("output_zp"),
]
nodes = [
helper.make_node(
"QuantizeLinear", ["input", "input_scale", "input_zp"],
["input_q"]),
helper.make_node(
"DequantizeLinear", ["input_q", "input_scale", "input_zp"],
["input_dq"]),
helper.make_node(
"DequantizeLinear", ["weight", "weight_scale", "weight_zp"],
["weight_dq"]),
helper.make_node("Conv", ["input_dq", "weight_dq"], ["raw"]),
helper.make_node(
"QuantizeLinear", ["raw", "output_scale", "output_zp"],
["output_q"]),
helper.make_node(
"DequantizeLinear", ["output_q", "output_scale", "output_zp"],
["output"]),
]
model = helper.make_model(
helper.make_graph(
nodes, "host_cmsis_conv", [inputs], [outputs], initializers),
opset_imports=[helper.make_opsetid("", 13)],
)
model.ir_version = 8
onnx.checker.check_model(model)
onnx.save(model, root / "host_cmsis_conv.onnx")
PY
tigris compile "$host_root/host_cmsis_conv.onnx" \
--mem 4K --output "$host_root/host_cmsis_conv.tgrs"
cmake -S cortex-m-deployability -B "$host_root/build" \
-DCMAKE_BUILD_TYPE=Release \
-DTIGRIS_HOST_VALIDATION=ON \
-DTIGRIS_RUNTIME_ROOT="$host_root/runtime" \
-DCMSIS_NN_DIR="$host_root/CMSIS-NN"
cmake --build "$host_root/build" \
--target host_cmsis_validate --parallel 2
"$host_root/build/host_cmsis_validate" \
"$host_root/host_cmsis_conv.tgrs"