Cross-Dialect Generalization Without Retraining: Benchmarks and Evaluation of Schema-Derived Constrained Decoding for MLIR
Organizations: Meta
Abstract
Multi-Level Intermediate Representation (MLIR) underlies modern ML compiler infrastructure (TensorFlow, JAX/StableHLO, PyTorch Inductor, IREE), yet appears only in trace amounts in code-LM pretraining corpora. MLIR is also extensible by design: new dialects ship per application domain, so a fine-tuned model per dialect does not scale. We ask whether inference-time priors derived mechanically from each dialect's Operation Definition Specification (ODS) can substitute for gradient-based adaptation. First, we release four natural-language-to-MLIR benchmarks across three dialects (MLIR-Spec-150, Linalg-Spec-30, StableHLO-Spec-30, StableHLO-Held-Out-200), totaling 410 in-scope NL-to-MLIR pairs, plus a 25-program out-of-grammar stress set, with functional references on 30 Spec prompts, under Apache-2.0 with Gebru datasheets and Croissant 1.1 metadata. Second, we build a three-layer schema-derived constraint stack: a CFG over op signatures (C1), type-domain splits from an ODS-extracted type lattice (C2), and an SSA-scope validator driving five-retry rejection sampling (C3). Porting it to StableHLO required no new constraint-layer code. On structurally dominated dialects, SmolLM2-1.7B with token-level constraints matches or exceeds 15B-34B code LMs running post-hoc rejection at a matched retry budget and 8-25x the per-generation speed: on linalg it reaches 80.0% verify-valid (three runs, n=125), 21 to 44 pp above CodeLlama-34B, Granite-Code-34B, and StarCoder2-15B with non-overlapping CIs. The comparison is between systems, not models: under the baselines' post-hoc protocol, SmolLM2 falls from 52.0% to 24.5% on arith+func. On arith+func and the templated StableHLO-Held-Out-200 the baselines match or beat the SLM; we scope these as non-win cells. We release benchmarks, decoder, every per-prompt generation, and a pinned reproducibility Dockerfile.
Figures & tables
| Benchmark | Dialect | Ops covered | E/M/H | Source | Verifier | |
|---|---|---|---|---|---|---|
| MLIR-Spec-150 | 150 | arith+func+memref | distinct | 38/44/18% | hand | mlir-opt |
| Linalg-Spec-30 | 30 | linalg (memref) | 12 named | - | hand | mlir-opt |
| StableHLO-Spec-30 | 30 | stablehlo | 10 op families | 40/40/20% | hand | iree-compile |
| StableHLO-Held-Out-200 | 200 | stablehlo | 7 fam 6 dtypes ranks | sweep | sweep | iree-compile |
| StableHLO-OutOfGrammar-25 | 25 | stablehlo | 23 fam, out of grammar | - | hand | iree-compile |
| System | arith+func | linalg |
|---|---|---|
| SmolLM2-1.7B + + + | 53.2% ( 1.8pp) | 80.0% ( 0.0pp) |
| CodeLlama-34B + + | 59.8% ( 0.8pp) | 58.7% ( 2.4pp) |
| Granite-Code-34B + + | 51.5% ( 2.5pp) | 35.7% ( 4.4pp) |
| StarCoder2-15B + + | 66.8% ( 1.5pp) | 54.9% ( 1.2pp) |
| Granite-Code-8B-fp16 + + (fp16 control) | 68.2% ( 3.0pp) | 50.1% ( 1.6pp) |
| Benchmark | SmolLM2 1.7B | CodeLlama 34B | Granite-Code 34B | StarCoder2 15B |
|---|---|---|---|---|
| Spec-30 ( , hand-curated) | 63.3% | 36.7% | 33.3% | 60.0% |
| Held-Out-200 ( , parametric) | 61.5% | 100.0% | 98.0% | 100.0% |
| OutOfGrammar-25 ( , stress) | 0% (intended) | — | — | — |
| Dialect | Verify-valid (three runs) | Fixed-input output-match (10 references) | Gold-differential (spec prompts) |
|---|---|---|---|
| arith+func | 53.2% ( ) | 80.0% (8/10) | 63.2% (43/68) |
| linalg | 80.0% ( ) | 20.0% (2/10) | 36.4% (8/22) |
| StableHLO (Spec-30) | 63.3% ( ) | 50.0% (5/10) | n/a |
Appendix figures & tables16 assets
Supplementary material from the paper’s appendix.
Appendix
| Generations | arith+func | linalg |
|---|---|---|
| SmolLM2-1.7B ( rung) | 3 / 89 | 1 / 80 |
| SmolLM2-1.7B ( rung) | 5 / 91 | 1 / 92 |
| CodeLlama-34B | 0 / 121 | 0 / 71 |
| StarCoder2-15B | 0 / 134 | 0 / 59 |
| Granite-Code-34B | 0 / 94 | 0 / 42 |
| System | arith+func (n=200) | linalg (n=125) |
|---|---|---|
| SmolLM2-1.7B, free | 20.0 [14.5, 25.5] | 52.0 [43.2, 60.8] |
| SmolLM2-1.7B + C1 | 44.5 [37.5, 51.5] | 64.0 [55.2, 72.0] |
| SmolLM2-1.7B + C1+C2 | 45.5 [38.5, 52.5] | 73.6 [65.6, 80.8] |
| SmolLM2-1.7B + C1+C2+C3 (ours) | 52.0 [45.0, 59.0] | 77.6 [70.4, 84.8] |
| Granite-Code-34B, free | 39.0 [32.5, 46.0] | 27.2 [20.0, 35.2] |
| Granite-Code-34B + C1 | 47.0 [40.5, 54.0] | 33.6 [25.6, 41.6] |
| System | arith C1-only | arith C1+C3 | linalg C1-only | linalg C1+C3 |
|---|---|---|---|---|
| CodeLlama-34B | 60.5 | 59.8 | 56.8 | 58.7 |
| StarCoder2-15B | 67.0 | 66.8 | 47.2 | 54.9 |
| Granite-Code-34B | 47.0 | 51.5 | 33.6 | 35.7 |
| Cell | arith+func all | arith+func unique | linalg all | linalg unique |
| SmolLM2 free | 20.0 | 18.7 | 52.0 | 38.7 |
| SmolLM2 + C1 | 44.5 | 43.5 | 64.0 | 56.0 |
| SmolLM2 + C1+C2 | 45.5 | 44.6 | 73.6 | 69.3 |
| SmolLM2 + C1+C2+C3 (seed-0 ladder) | 52.0 | 50.8 | 77.6 | 75.0 |
| SmolLM2 + C1+C2+C3 (3 runs) | 53.2 | 52.2 | 80.0 | 75.7 |
| CodeLlama-34B + C1+C3 | 59.8 | 59.4 | 58.7 | 63.6 |
| Dialect | Constraint | passed | type | type_ssa | syntax | other |
|---|---|---|---|---|---|---|
| arith+func | none | 40 | 1 | 3 | 0 | 156 |
| arith+func | c1 | 89 | 13 | 51 | 0 | 47 |
| arith+func | c1_c2 | 91 | 1 | 61 | 0 | 47 |
| arith+func | c1_c2_c3 | 104 | 9 | 37 | 0 | 50 |
| linalg | none | 65 | 0 | 1 | 4 | 55 |
| linalg | c1 | 80 | 0 | 5 | 19 | 21 |
| Cell | s0 | s1 | s2 | mean | hr |
| SmolLM2 + + + , arith+func | 52.0% | 52.0% | 55.5% | 53.2% | pp |
| SmolLM2 + + + , linalg | 80.0% | 80.0% | 80.0% | 80.0% | pp |
| Granite-Code-34B-Q4 + + , arith+func | 49.5% | 54.5% | 50.5% | 51.5% | pp |
| Granite-Code-34B-Q4 + + , linalg | 34.4% | 40.8% | 32.0% | 35.7% | pp |
| CodeLlama-34B-Q4 + + , arith+func | 60.5% | 59.0% | 60.0% | 59.8% | pp |
| CodeLlama-34B-Q4 + + , linalg | 59.2% | 60.8% | 56.0% | 58.7% | pp |
| Claim | Status | Supporting evidence |
|---|---|---|
| linalg win (system-level) | Robust | Mean of three runs 80.0% (each run 80.0%); to pp over the baselines with non-overlapping CIs; at least pp over each baseline’s best configuration; the fp16 control trails by 29.9pp |
| Enforcement asymmetry | Measured | SmolLM2 under the baselines’ post-hoc protocol: 24.5% vs 52.0% with masking on arith+func ( pp, CI ) |
| 8–25 per-generation speedup | Robust | Wall-clock on a single Apple M4 Max (Fig. 4 ); 1.65–1.86 s vs 16–40 s |
| Mechanical schema port across dialects | Robust | Zero new constraint-layer code from arith+func+memref+linalg StableHLO |
| StableHLO win on hand-curated Spec-30 | Corpus-conditional | to pp over the 34B baselines on Spec-30 only; baselines saturate at 98–100% on Held-Out-200 |
| arith+func win | Not supported | 53.2% vs CodeLlama-34B 59.8% (within CI), StarCoder2-15B 66.8% (non-overlapping), Granite-Code-8B-fp16 68.2% (paired pp) |
| Benchmark | Dialect | Source | Type | |
|---|---|---|---|---|
| MLIR-Spec-150 | 150 | arith+func+memref | author-curated | in-grammar |
| Linalg-Spec-30 | 30 | linalg (12 ops) | author-curated | in-grammar |
| StableHLO-Spec-30 | 30 | stablehlo (10 fam.) | author-curated | in-grammar |
| StableHLO-Held-Out-200 | 200 | stablehlo | parametric sweep | in-grammar (held-out) |
| StableHLO-OutOfGrammar-25 | 25 | stablehlo | author-curated | out-of-grammar (stress) |
| MLIR-Functional-Reference-30 | 30 | arith+func+memref / linalg+memref / stablehlo (10 ea.) | author-curated | evaluation artifact (NL+MLIR+inputs+expected output) |
Constrained Decoding
Constrained decoding steers language model outputs to satisfy formal or task-specific rules while balancing validity, quality, and faithful probabilities.
See all 67 papers