Commit e6935c3
Make Whisper encoder compile end-to-end via SKaiNET → StableHLO → IREE
Prior state: `iree-compile` rejected the Whisper-encoder MLIR emitted by
`StableHloConverterFactory.createExtended()` — 141 `// Unsupported` comments
over 296 graph nodes and 12 `stablehlo.custom_call @reduce_*` ops. Cascade
analysis in `docs/whisper-iree-issues/` identified a mix of missing converters
and invalid-MLIR emissions; a single upstream miss fanned out via
`StableHloConverter.processNode`'s `mapNotNull` operand lookup and appeared
downstream as bogus "wrong arity" failures.
Result: 0 Unsupported, 0 custom_call reductions, 35 real `stablehlo.reduce`,
32 `stablehlo.dot_general` (including the 8 rank-4 attention matmuls), and a
40 MB `.vmfb` compiled with `iree-compile --iree-hal-target-backends=llvm-cpu`.
Individual fixes, each guarded by an end-to-end assertion in the new
`Conv1dTapeToHloTest`:
* `TraceToGraphBuilder.buildOutputSpecs`: fall back to
`trace.outputs[i].shape.dimensions` when the KSP-generated tracer omits
`outputShapes` from attributes. Fixes `tensor<?xf32>` on every conv/gelu/etc.
whose wrapper didn't go through `OpAttributeFactory.shapesAndDTypes`.
* `NeuralNetOperationsConverter.buildConv1d/ConvolutionOperation`: emit
`stablehlo.broadcast_in_dim %bias, dims = [1]` before the bias add so the
add's operands share a type; previously produced
`stablehlo.add %conv, %bias : tensor<N,C,L>` with a rank-mismatched bias.
* `BasicMathConverter`: rewrite `add`/`subtract`/`multiply`/`divide` lowering.
Old code short-circuited broadcasting whenever dtypes matched, and the
broadcast path itself emitted split-line syntax MLIR rejects. New path
takes `node.outputs[0]` as the target spec, adapts each operand via
`stablehlo.convert` then `stablehlo.broadcast_in_dim` with NumPy-style
right-aligned dim mapping.
* New `UnaryMathConverter`: `sqrt`, `rsqrt`, `exp`, `expm1`, `log`, `log1p`,
`abs`, `sign`, `negate`, `ceil`, `floor`, `round`, `cos`, `sin` → 1:1
StableHLO primitives.
* New `ScalarOperationsConverter`: `addScalar`/`subScalar`/`mulScalar`/
`divScalar`/`rsubScalar`/`rdivScalar` materialize the scalar as a splat
`stablehlo.constant` then apply the matching binary op (reversed for
`r*Scalar`). Reads the scalar from `operation.parameters["b"]` (the KSP
tracer stores it there via `OpAttributeFactory.scalarOp`).
* `ReductionOperationsConverter`: emit real `stablehlo.reduce` instead of
`stablehlo.custom_call @reduce_*` (the previous form was both non-standard
and syntactically malformed). `mean` = reduce-sum + divide-by-count;
`variance` decomposes to `E[X²] − E[X]²` via two reduces.
* `ActivationOperationsConverter.convertSoftmax`: softmax's two reductions
now use `stablehlo.reduce` applying `stablehlo.maximum` and `stablehlo.add`.
Same motivation as the reductions above.
* `LinalgOperationsConverter`: route every matmul variant
(`matmul`/`dot`/`mm`/`bmm`/`batch_matmul`) through the rank-generic batched
lowering. Prior `matmul` path hardcoded `contracting_dims = [1] x [0]` and
produced invalid MLIR for Whisper attention's rank-4 matmul
`[1,6,1500,64] × [1,6,64,1500]`; now emits
`batching_dims = [0, 1] x [0, 1], contracting_dims = [3] x [2]`. Rank-2
continues to emit the compact form (empty batching clause).
* `StableHloConverter.processNodes`: enrich the fallback "Unsupported op"
comment with the quoted name and the registry's full key list. Makes the
MLIR self-diagnostic so a future missing-converter case surfaces without
needing a local reproducer.
Registry entries added for the two new converters in all three factory
entry points (`createBasic`, `createExtended`, `createFast`).
`docs/whisper-iree-issues/` is included for context — it captured the
failure surface that these changes close.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent c04257c commit e6935c3
16 files changed
Lines changed: 1076 additions & 292 deletions
File tree
- docs/whisper-iree-issues
- skainet-compile
- skainet-compile-dag/src/commonMain/kotlin/sk/ainet/lang/trace
- skainet-compile-hlo/src
- commonMain/kotlin/sk/ainet/compile/hlo
- converters
- commonTest/kotlin/sk/ainet/compile/hlo
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
Lines changed: 73 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
350 | 350 | | |
351 | 351 | | |
352 | 352 | | |
353 | | - | |
354 | | - | |
| 353 | + | |
| 354 | + | |
355 | 355 | | |
356 | 356 | | |
357 | 357 | | |
| |||
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
182 | 189 | | |
183 | 190 | | |
184 | 191 | | |
| |||
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
56 | 67 | | |
57 | 68 | | |
58 | 69 | | |
| |||
98 | 109 | | |
99 | 110 | | |
100 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
101 | 121 | | |
102 | 122 | | |
103 | 123 | | |
| |||
128 | 148 | | |
129 | 149 | | |
130 | 150 | | |
| 151 | + | |
| 152 | + | |
131 | 153 | | |
132 | 154 | | |
133 | 155 | | |
| |||
Lines changed: 14 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| 149 | + | |
149 | 150 | | |
150 | 151 | | |
151 | 152 | | |
152 | 153 | | |
| 154 | + | |
153 | 155 | | |
154 | 156 | | |
155 | 157 | | |
156 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
157 | 163 | | |
158 | 164 | | |
159 | | - | |
160 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
161 | 169 | | |
162 | 170 | | |
163 | 171 | | |
| |||
170 | 178 | | |
171 | 179 | | |
172 | 180 | | |
173 | | - | |
174 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
175 | 185 | | |
176 | 186 | | |
177 | 187 | | |
| |||
0 commit comments