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
//! Ground-truth introspection of `chordai/wav2vec2-base960h-aligner-coreml`
//! (design spec §3 Candidate A) — the CTC acoustic encoder alignkit's
//! forced-aligner wraps. Every claim below comes from loading the real
//! `.mlmodelc` via `coremlit::Model::load` + `.description()`, or from
//! actually running it (`Model::predict`); the model card's own claims are a
//! HYPOTHESIS re-verified here, not trusted blind.
//!
//! # Artifact (`Models/alignkit/`, gitignored, fetched dev-time)
//!
//! Source: <https://huggingface.co/chordai/wav2vec2-base960h-aligner-coreml>,
//! revision (commit SHA) `a7b796f23585b48af9f21977412953680291f27d` — pinned
//! at download time; `hf api`'s `sha` field and `git ls-remote HEAD` agree.
//!
//! | File | Role |
//! |---|---|
//! | `base960h_aligner.mlpackage/Data/com.apple.CoreML/model.mlmodel` | model graph (downloaded) |
//! | `base960h_aligner.mlpackage/Data/com.apple.CoreML/weights/weight.bin` | weights, fp16 (downloaded) |
//! | `base960h_aligner.mlpackage/Manifest.json` | mlpackage manifest (downloaded) |
//! | `base960h_dict.json` | 29-entry CTC vocab, consumed by Task B2 (downloaded) |
//! | `base960h_aligner.mlmodelc/` | **targeted** — compiled from the `.mlpackage` row above via `xcrun coremlcompiler compile`; not itself downloaded (`coremlit::Model::load` only accepts a compiled `.mlmodelc`; see `tests/common::model_path`) |
//!
//! # License
//!
//! HuggingFace `cardData.license` = `apache-2.0` (also tagged
//! `license:apache-2.0`). The repo's own README states the weights are
//! converted from `torchaudio.pipelines.WAV2VEC2_ASR_BASE_960H` ("Facebook/
//! Meta wav2vec2-base fine-tuned on LibriSpeech 960h; Apache-2.0 lineage").
//! Apache-2.0 requires preserving notices, not a specific attribution
//! string; this record (repo id, revision, license) is that preservation.
//!
//! # Per-file SHA-256 (downloaded artifacts only)
//!
//! `base960h_aligner.mlmodelc` is a local `coremlcompiler` output, not a
//! downloaded artifact, so it is deliberately NOT pinned here — a different
//! Xcode/`coremlcompiler` version could legitimately re-emit different
//! compiled bytes for the same source `.mlpackage`; see
//! `source_artifacts_match_pinned_sha256` for what this test suite actually
//! checks against drift/corruption.
//!
//! | File | SHA-256 |
//! |---|---|
//! | `base960h_aligner.mlpackage/Data/com.apple.CoreML/model.mlmodel` | `25e58f76ec1de033c7ae52d20e5bc8a468657b1a7800e2340f2e5b962da8dfbb` |
//! | `base960h_aligner.mlpackage/Data/com.apple.CoreML/weights/weight.bin` | `de51193fe73fb3aad085f9c794f08bfde1b939fc12f92e0834edcd4cb712e642` |
//! | `base960h_aligner.mlpackage/Manifest.json` | `58650570fbd6fe8e011f9134847da2fc7b5f1e867305e70354aa342c5b6aef93` |
//! | `base960h_dict.json` | `ef41495ab958d4416ad2f81ea51a77d4a3c79cace96e92e978c443c7bfbdd2e5` |
//!
//! # DECISION
//!
//! - **Target: `base960h_aligner.mlmodelc`** (spec §3 Candidate A — the only
//! candidate this task downloads; Candidate B, an in-house
//! coremltools conversion, is the documented STOP fallback if Candidate A
//! later fails a parity gate, spec §3/§10, not evaluated here).
//! - **Representation:** see `emissions_are_log_probs_not_raw_logits`
//! below — the graph-truth investigation this task exists to pin.
//!
//! # Spec-vs-reality
//!
//! Confirmed exactly against the design spec §3's stated contract and the
//! model card: `waveform [1, 960000]` f32 -> `emissions [1, 2999, 29]` f32,
//! 20 ms/frame (stride 320 samples @ 16 kHz). No deltas found.
use ;
/// Numerically-stable per-frame logsumexp over one frame's vocab logits (or
/// log-probs — that's exactly the question this module answers), accumulated
/// in `f64` so the measurement reflects the MODEL's behavior rather than
/// this test's own summation error.
/// Runs `waveform` (must be exactly 960,000 samples) through the live model
/// and returns the flat `[2999 * 29]` emissions row-major buffer.
/// **THE GRAPH-TRUTH TEST** (design spec §7 data flow, evaluation item 2 —
/// the blocking input to Task B3's encoder wrapper design). Determines
/// empirically whether `emissions` is raw CTC logits or already
/// log-softmaxed log-probabilities, via the one property that tells them
/// apart: a proper log-probability distribution sums to 1 in probability
/// space, so `logsumexp` over the 29-entry vocab axis is `ln(1) = 0`; raw
/// logits carry no such constraint, and `logsumexp` instead tracks the
/// logits' own (here, tens-of-units) dynamic range.
///
/// Measured (`ComputeUnits::CpuOnly`, this test's own run):
/// - Real audio (`ted_60.wav`, the full 60 s / 960,000-sample window —
/// already exactly the model's window, no padding needed): per-frame
/// `|logsumexp|` across all 2999 frames has max ≈ `5.2485e-3`, mean ≈
/// `1.0512e-3`.
/// - All-zeros input (second sample, corroborating on a degenerate input):
/// max ≈ `3.4290e-3`, mean ≈ `2.9445e-3`.
/// - The raw `emissions` values on the real-audio sample range up to
/// exactly `0.0` (`[-28.4375, 0.0]`) — the hard ceiling `log(p) <= 0`
/// admits for any probability `p <= 1`, which only a log-probability
/// tensor can hit exactly; raw logits have no such ceiling.
///
/// VERDICT: **log-probs.** Both signals agree with each other and with the
/// model card's own claim ("output | emissions float32 [1, 2999, 29] —
/// log-probs", `Models/alignkit/README.md`) — re-verified here rather than
/// trusted blind, per this module's opening paragraph.
///
/// Tolerance: `1e-2`, deliberately not the naively-hypothesized `1e-3` —
/// the measured max (`5.2485e-3`) already exceeds `1e-3`, and the model
/// card states `Precision: FLOAT16` (~3 decimal digits), which plausibly
/// explains `1e-3`-magnitude deviations accumulating over a 29-term
/// exp/sum/log per frame. `1e-2` keeps roughly 2x headroom above the
/// largest measured value while staying two-plus orders of magnitude below
/// the raw emission dynamic range (up to `28.4`) a genuinely-unnormalized
/// (raw-logit) tensor would be expected to produce — it cannot accidentally
/// mask a real logits-vs-log-probs mismatch.
///
/// DECISION CONSEQUENCE: because emissions are already log-probs, the shipping
/// encoder wrapper must NOT re-apply softmax/log-softmax over this output. It
/// does not treat the tensor as trusted, though: rather than wiring
/// `asry::LogProbsTV` straight from the raw `emissions`, it routes the raw tensor
/// through the value-domain guard (the staged contract's sentinel band plus the
/// logsumexp-normalization check, which mint a `ValueDomainChecked` capability)
/// and on to asry as an `EncoderOutput::LogProbs` — no softmax, but a checked
/// door, not a blind one. (Had the verdict instead been raw logits, the consequence would
/// have been the opposite: apply asry's `log_softmax_with_finite_guard` first.)
///
/// SUPERSEDED AS EVIDENCE, retained as a check: the model's `.mil` graph
/// settles the question directly — its final ops are `softmax` → `log` →
/// `cast(fp32)` (quoted in `coremlit::audio::align::encode`'s module doc). The verdict below
/// is inferred from measured values; the graph states it. The two agree.
/// Asserts every frame's `logsumexp` over the 29-entry vocab axis is within
/// `tolerance` of zero. See `emissions_are_log_probs_not_raw_logits`'s doc
/// comment for what this checks and the measured values that picked
/// `tolerance`.