Commit a1c3bbf
committed
[tmva][sofie] Generate ONNX models and refs instead of binaries in repo
The SOFIE ONNX unit tests relied on 145 binary .onnx files checked into
tmva/sofie/test/input_models, plus ~108 frozen reference headers
(input_models/references/*.ref.hxx) whose expected outputs were computed
once from the exact weights inside those binaries. This made it impossible
to tell from the repository what the models contain, and impossible to
regenerate them (some were exported with pytorch versions as old as 1.5).
Replace both with a single script, tmva/sofie/test/generate_input_models.py:
* Each model is built with the onnx helper API in a make_<Name>()
function, so graph structure, attributes, shapes and initializers are
readable and reviewable. Large weight tensors that used to be opaque
random blobs are seeded-random via _random_tensor(), with pytorch-like
1/sqrt(fan_in) scaling.
* The inputs for the value-based tests are defined in TEST_INPUTS, and
the expected outputs are computed with onnx's ReferenceEvaluator and
written to references/<Name>.ref next to the generated models. Where
the evaluator is wrong or unimplemented (MaxPool with asymmetric
padding, Mean with multidirectional broadcasting, bidirectional or
batchwise RNN/LSTM/GRU), numpy fallbacks implement the ONNX operator
definitions directly.
* The script runs as the new SofieGenerateModels_ONNX ctest, which the
other SOFIE ONNX tests require as a fixture. CMake gets the model list
at configure time from `generate_input_models.py --list`, which works
without the onnx module.
TestCustomModelsFromONNX.cxx and TestCladAutodiff.cxx read the inputs and
expected outputs at runtime through a small reader in test_helpers.h
instead of including frozen headers. SOFIE's results are thus checked
against an independent implementation instead of a snapshot of its own
past output.
While migrating, all computed references were validated to reproduce the
frozen .ref.hxx values with the original weights before switching to
seeded-random weights.
The ONNX model tests now require the onnx python package; they are
disabled with a warning if it is missing or has the broken version 1.19.0.
The TMVA_SOFIE_ONNX.C tutorial input is likewise generated at configure
time instead of being copied from the test sources.
🤖 Done with the help of AI.1 parent 61e7135 commit a1c3bbf
259 files changed
Lines changed: 6086 additions & 4508 deletions
File tree
- tmva/sofie/test
- input_models
- references
- tutorials
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
13 | 33 | | |
14 | | - | |
| 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 | + | |
15 | 59 | | |
16 | 60 | | |
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 | | - | |
| 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 | + | |
51 | 95 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | 96 | | |
56 | | - | |
57 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
58 | 100 | | |
59 | 101 | | |
60 | | - | |
61 | | - | |
| 102 | + | |
| 103 | + | |
62 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
63 | 114 | | |
64 | 115 | | |
65 | 116 | | |
| |||
70 | 121 | | |
71 | 122 | | |
72 | 123 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | 124 | | |
90 | 125 | | |
91 | 126 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | 5 | | |
8 | 6 | | |
9 | 7 | | |
| |||
12 | 10 | | |
13 | 11 | | |
14 | 12 | | |
15 | | - | |
16 | | - | |
17 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
| |||
135 | 133 | | |
136 | 134 | | |
137 | 135 | | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
| 136 | + | |
147 | 137 | | |
0 commit comments