HaiwangYu commited on
Commit
0ac8d54
·
verified ·
1 Parent(s): a209d8a

Upload README.md

Browse files
Files changed (1) hide show
  1. dnn-roi/pdvd/20260615/README.md +214 -0
dnn-roi/pdvd/20260615/README.md ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # PDVD DNN-ROI TorchScript models
2
+
3
+ TorchScript (`.ts`) models loaded by the wire-cell-toolkit DNN-ROI node
4
+ `DNNROIFinding` (single-plane, per-plane sequential) for ProtoDUNE Vertical
5
+ Drift. All are exported with `DNN_ROI_SP/scripts/to_torchscript.py` from the
6
+ full-corpus 6-channel SDCC training campaign (DAGMan 287, 2026-05-20/21) and
7
+ output `sigmoid` probabilities in `[0, 1]` (no extra sigmoid needed in
8
+ Wire-Cell).
9
+
10
+ > **2026-05-23 retrace.** The shipped `.ts` files were originally traced at
11
+ > the stacked-plane shape `(1, 6, 952, 1600)` and crashed when fed the
12
+ > per-plane shape `(1, 6, 476, 1600)` that the deployed `DNNROIFinding`
13
+ > chain actually produces (119-vs-120 cat mismatch in `mobilenetv3_unet`'s
14
+ > decoder skip at H=476). All five `.ts` files have been re-traced from
15
+ > the same canonical checkpoints at the per-plane input shape; the trace
16
+ > now records the model's runtime `F.interpolate` size-fixup at the
17
+ > failing decoder layer (an aligned 120→119 bilinear, identity on
18
+ > matched layers). Standalone replay through the re-traced
19
+ > `pipe_distill_nestedunet_6ch.ts` reproduces the toolkit output to
20
+ > max-abs `~5×10⁻⁷` on all 8 anodes × 2 induction planes for run 039324
21
+ > evt 0 (`DNN_ROI_SP/scripts/verify_wirecell_dnn.py`).
22
+
23
+ ## Production deployables
24
+
25
+ The three files actively wired by the toolkit. The current default in
26
+ `simulation/toolkit/pdvd/wct-nf-sp-dnnroi.jsonnet` is the INT8 primary
27
+ (`pipe_qat_nestedunet_6ch_ep0_int8.ts`); flip `dnnroi_model` to a different
28
+ row to swap.
29
+
30
+ | file | input ch | precision | size | role | run with |
31
+ |---|---|---|---|---|---|
32
+ | `pipe_base_mbv3_6ch.ts` | 6 | FP32 | 20.4 MB | FP32 baseline (no KD) | `run_nf_sp_dnnroi_evt.sh -M dnnroi/pdvd/pipe_base_mbv3_6ch.ts` |
33
+ | `pipe_distill_nestedunet_6ch.ts` | 6 | FP32 | 20.4 MB | FP32 best KD | `run_nf_sp_dnnroi_evt.sh -M dnnroi/pdvd/pipe_distill_nestedunet_6ch.ts` |
34
+ | `pipe_qat_nestedunet_6ch_ep0_int8.ts`| 6 | INT8 (QAT) | 10.8 MB | **INT8 primary (default)** | `run_nf_sp_dnnroi_evt.sh -D cpu -M dnnroi/pdvd/pipe_qat_nestedunet_6ch_ep0_int8.ts` |
35
+
36
+ ## Staged / diagnostic
37
+
38
+ Not wired by default; kept so the user can re-run the §11 / §12.4
39
+ comparisons without re-exporting from checkpoints. Both originate from the
40
+ Transformer-teacher chain of DAGMan 287 — kept as a reference companion to
41
+ the production NestedUNet-teacher chain above.
42
+
43
+ | file | input ch | precision | size | role |
44
+ |---|---|---|---|---|
45
+ | `pipe_distill_transformer_6ch.ts` | 6 | FP32 | 20.4 MB | FP32 KD-Tx, used in §11 as a same-architecture FP32 reference for INT8-Tx |
46
+ | `pipe_qat_transformer_6ch_ep3_int8.ts` | 6 | INT8 (QAT) | 10.8 MB | Tx INT8 candidate at epoch 3; narrows the §11 top-CRP regression but did not clear the strict §12.4 ≤10 % nzpx gate (an5 12.57 %). Held back from production pending an explicit decision; not the canonical Tx INT8. |
47
+
48
+ (The previous canonical Tx INT8, `pipe_qat_transformer_6ch_int8.ts`, was
49
+ derived from epoch 19 — the last-epoch fakequant that the un-patched
50
+ `scripts/qat_kd_finetune.py` shipped by default. Per
51
+ `DNN_ROI_SP/docs/qat_deployable_diagnostic_2026-05-21.md`, that ep19 ckpt
52
+ was strictly dominated by ep3 on labeled Dice (0.7550 vs 0.7772) **and** on
53
+ top-CRP over-emission. The ep19 `.ts` was removed in the 2026-05-21
54
+ cleanup; if the user ever wants it back for a controlled comparison,
55
+ re-export from `checkpoints/pdvd_qat_transformer_6ch/qat_int8_state.pth.ep19`
56
+ on wcgpu1.)
57
+
58
+ ## Provenance
59
+
60
+ All exports trace back to DAGMan cluster **287** on SDCC
61
+ (`sgpu0004`, 2× L40S, 2026-05-20 22:12 → 2026-05-21 06:51 EDT,
62
+ ~8 h 40 min wall total). The training corpus is the 6-channel PDVD
63
+ mix (1 000 train + 200 val + 400 held-out test, 125/25/50 events per
64
+ anode × 8 anodes, `pdvd_anode{0..7}_6ch_th150_pad3.h5`).
65
+
66
+ ### Production deployables
67
+
68
+ | field | `pipe_base_mbv3_6ch` | `pipe_distill_nestedunet_6ch` | `pipe_qat_nestedunet_6ch_ep0_int8` |
69
+ |---|---|---|---|
70
+ | Architecture | MobileNetV3-large UNet | MobileNetV3-large UNet | QuantizableMobileNetV3-UNet, INT8 |
71
+ | Run-id | `pdvd_mobilenetv3_all_6ch` | `pdvd_distill_nestedunet_6ch` | `pdvd_qat_nestedunet_6ch` |
72
+ | Checkpoint | `CP97.pth` (best-val ep 97) | `CP35.pth` (best-val ep 35) | `qat_int8_state.pth.ep0` (best-by-post-convert) |
73
+ | Training | 6-ch baseline, no KD, 100 ep | NestedUNet teacher + feature-map KD, 100 ep | QAT-KD INT8, 20 ep, warm-started from KD-NU (`pdvd_distill_nestedunet_6ch`) |
74
+ | TorchScript mode | trace | trace | trace |
75
+ | Held-out test (400 ev) Dice | 0.7538 | **0.7816** | 0.7797 |
76
+ | Held-out test eff_roi / pur_roi | 0.7135 / 0.8594 | 0.7520 / 0.8537 | 0.7533 / 0.8490 |
77
+
78
+ The KD-NestedUNet student (`pdvd_distill_nestedunet_6ch`) is the strongest
79
+ FP32 model on test (Dice 0.7816, eff_roi 0.7520 — both #1 of the 5 FP32
80
+ runs). The INT8 primary (`pdvd_qat_nestedunet_6ch` epoch 0) keeps 99.7 % of
81
+ that FP32 Dice (0.7797 = −0.27 % vs FP32 KD parent) and clears the toolkit
82
+ §12.4 ≤10 % nzpx gate on all 8 anodes (worst case 9.34 % on anode 5). The
83
+ direct-MBV3 baseline is shipped as the no-KD reference.
84
+
85
+ The INT8 primary's epoch choice (ep 0) is governed by post-convert dice
86
+ peaking early in QAT, not the trainer's fakequant `val_dice`. See
87
+ `DNN_ROI_SP/docs/qat_deployable_diagnostic_2026-05-21.md` for the full
88
+ diagnostic and `DNN_ROI_SP/scripts/qat_kd_finetune.py`'s
89
+ best-by-post-convert tracking that lands canonically going forward.
90
+
91
+ ### Staged / diagnostic
92
+
93
+ | field | `pipe_distill_transformer_6ch` | `pipe_qat_transformer_6ch_ep3_int8` |
94
+ |---|---|---|
95
+ | Architecture | MobileNetV3-large UNet | QuantizableMobileNetV3-UNet, INT8 |
96
+ | Run-id | `pdvd_distill_transformer_6ch` | `pdvd_qat_transformer_6ch` |
97
+ | Checkpoint | `CP99.pth` (best-val ep 99) | `qat_int8_state.pth.ep3` |
98
+ | Held-out test Dice | 0.7680 | 0.7772 |
99
+ | Notes | Diagnostic FP32 anchor for §11 / §12.4 same-arch INT8 comparison. Not the shipped FP32 deployable. | Tx-chain INT8 candidate. +1.20 % vs FP32 KD-Tx parent on labeled test Dice. Narrows the §11 top-CRP regression (an4 11.27 %→7.60 %, an5 17.63 %→12.57 %) but an5 still exceeds the §12.4 10 % strict gate; ep19 was deleted as superseded but no Tx INT8 .ts is wired as canonical until the residual is resolved (see `DNN_ROI_SP/memory/pdvd_int8_top_crp_oversegmentation.md`). |
100
+
101
+ `to_torchscript.py` falls back to `torch.jit.trace` (the encoder `break`
102
+ and the INT8 graph cannot be scripted); each export is verified by an
103
+ eager-vs-TorchScript `allclose` (max abs diff 0.00e+00 for all five files).
104
+
105
+ ## Input layout
106
+
107
+ C++ tensor order is `(batch=1, ntags, nchannels, nticks)`:
108
+
109
+ - `ntags` = **6**.
110
+ - `nchannels` = **476** per plane. The two induction planes U and V are
111
+ processed sequentially by two `DNNROIFinding` nodes per anode (sharing a
112
+ single TorchService); the W collection plane is not consumed (passed
113
+ through from standard SP gauss). See
114
+ `cfg/pgrapher/experiment/protodunevd/dnnroi_pp.jsonnet`.
115
+ - `nticks` = **1600**, from PDVD's raw `6400` ticks after `tick_per_slice=4`
116
+ downsampling inside the C++ node.
117
+
118
+ The toolkit input per call is `(1, 6, 476, 1600)`. The PDVD students were
119
+ trained on **stacked U+V at (1, 6, 952, 1600)**; per-plane deployment is
120
+ structurally compatible (MobileNetV3-large is fully convolutional on the
121
+ channel axis), and the re-traced `.ts` files include the runtime
122
+ size-fixup the U-Net needs at this shape (see top-of-file note).
123
+
124
+ **6-channel input** — `ntags=6`, trace tags in order:
125
+
126
+ ```
127
+ loose_lf{A}, mp2_roi{A}, mp3_roi{A}, tight_lf{A}, decon_charge{A}, gauss{A}
128
+ ```
129
+
130
+ The two new tags relative to the previous 4-ch deployment (`tight_lf` and
131
+ `decon_charge`) must be emitted by PDVD's `OmnibusSigProc` chain in debug +
132
+ multi-plane-protection mode — the same way PDHD 6-ch deployment works. The
133
+ order matches the PDHD 6-ch sibling exactly.
134
+
135
+ ## Per-channel normalization
136
+
137
+ The 6-ch models are trained on inputs divided by **per-channel** z-scales.
138
+ Wire-Cell's `DNNROIFinding` applies one scalar `input_scale`, so the
139
+ per-channel division is baked into each `.ts` as a fixed normalization layer;
140
+ the models run with `input_scale = 1.0` (set by
141
+ `protodunevd/dnnroi_pp.jsonnet`).
142
+
143
+ A single set is baked into all `.ts` files — the **cross-anode mean**:
144
+
145
+ ```
146
+ [766.1332, 4000.0, 4000.0, 762.4834, 1679.252, 11827.907]
147
+ (loose_lf, mp2_roi, mp3_roi, tight_lf, decon_charge, gauss)
148
+ ```
149
+
150
+ The per-anode z-scales differ — z[0] runs ~50 % higher on the top CRP
151
+ (anodes 4-7) than the bottom CRP (anodes 0-3). The cross-anode mean is an
152
+ approximation; the unified vs split study
153
+ (`DNN_ROI_SP/docs/pdvd_unified_vs_split_study.md`) shows one mixed model
154
+ matches the per-half specialists, so a single set is shipped.
155
+
156
+ ## Tick padding
157
+
158
+ The C++ node rebins the time axis by `tick_per_slice=4` before inference;
159
+ the PDVD MobileNetV3-large UNet was trained at post-rebin width
160
+ **1600** (= `6400/4`), and 1600 = 64·25 has five spare factors of 2, so
161
+ the deployed `.ts` has **5 stride-2 down/up levels** in the tick axis
162
+ post-rebin. To survive that cascade the post-rebin width must be
163
+ divisible by 2⁵ = 32, i.e. the input `nticks` must be a multiple of
164
+ `tick_per_slice · 32 = 4·32 = 128`.
165
+
166
+ `cfg/pgrapher/experiment/protodunevd/dnnroi_pp.jsonnet` sets
167
+ `tick_pad_multiple=128` by default; the C++ `DNNROIFinding` node then
168
+ pads the input ticks up to the next 128-multiple before inference and
169
+ crops the output back to the original `input_ticks`.
170
+
171
+ | input `nticks` | padded `model_ticks` | output cropped to |
172
+ |---|---|---|
173
+ | 6000 | 6016 (= 47·128) | 6000 |
174
+ | 6400 | 6400 (already 50·128) | 6400 |
175
+ | 8000 | 8064 (= 63·128) | 8000 |
176
+
177
+ A mismatch surfaces as a tensor-shape error inside the model at runtime,
178
+ not as a toolkit-side check, so do not lower `tick_pad_multiple` for
179
+ these models.
180
+
181
+ ## Consumer
182
+
183
+ Loaded by the toolkit C++ node `DNNROIFinding` (per-plane sequential:
184
+ U and V each run their own forward call sharing one TorchService —
185
+ analogous to the PDHD pp wiring). Wired by
186
+ `cfg/pgrapher/experiment/protodunevd/dnnroi_pp.jsonnet`; driven by
187
+ `toolkit/pdvd/run_nf_sp_dnnroi_evt.sh` and
188
+ `wcp-porting-img/pdvd/run_nf_sp_dnnroi_evt.sh` (`-M <model>` selects the
189
+ `.ts`).
190
+
191
+ The C++ `DNNROIFinding` node honors `debugfile` (set via the chain's
192
+ `-X <basename>` flag) and writes one `{basename}_anode{N}_{plane}_call0.pt`
193
+ per call containing `(input, output, meta)` — loadable with
194
+ `DNN_ROI_SP/scripts/verify_wirecell_dnn.py` for offline 1:1 replay
195
+ against the same `.ts`.
196
+
197
+ ## Limitations
198
+
199
+ - Trained on **all 8 PDVD anodes** (bottom CRP = anodes 0-3, top CRP =
200
+ anodes 4-7) — the previous 4-channel deployment's "anodes 4-7
201
+ out-of-domain" caveat no longer applies. See
202
+ `DNN_ROI_SP/docs/pdvd_unified_vs_split_study.md` for evidence one model
203
+ handles both halves.
204
+ - The W collection plane is not processed; the toolkit jsonnet routes it
205
+ through a `PlaneSelector` passthrough of standard SP gauss.
206
+ - INT8 QAT models run on **CPU only** (x86 quantized backend); they cannot
207
+ be placed on a GPU device.
208
+ - The INT8 primary (NU ep0) is the result of a deployable-selection patch
209
+ (best-by-post-convert dice). For runs that pre-date the patch, the
210
+ trainer's last-epoch `qat_int8_state.pth` should not be assumed to be
211
+ the best post-convert deployable — see the §12.6 follow-up in
212
+ `DNN_ROI_SP/docs/sdcc_full_training_campaign.md` for details.
213
+ - Cross-anode-mean z-scales are an approximation — see
214
+ *Per-channel normalization* above.