id stringlengths 9 29 | difficulty stringclasses 3
values | nl stringlengths 50 126 | mlir stringlengths 144 340 | notes stringlengths 3 23 | dialect stringclasses 1
value |
|---|---|---|---|---|---|
01_add-1d | easy | Write a function that adds two 1-D f32 tensors of 16 elements using stablehlo.add. | module {
func.func @a(%a: tensor<16xf32>, %b: tensor<16xf32>) -> tensor<16xf32> {
%0 = stablehlo.add %a, %b : tensor<16xf32>
return %0 : tensor<16xf32>
}
} | canonical stablehlo.add | stablehlo+func |
02_add-2d-dynamic | easy | Write a function that adds two 2-D f32 tensors with dynamic shapes and returns the result. | module {
func.func @add2d(%a: tensor<?x?xf32>, %b: tensor<?x?xf32>) -> tensor<?x?xf32> {
%0 = stablehlo.add %a, %b : tensor<?x?xf32>
return %0 : tensor<?x?xf32>
}
} | dynamic-shape addition | stablehlo+func |
03_subtract-1d-i32 | easy | Write a function that subtracts two 1-D i32 tensors elementwise. | module {
func.func @sub(%a: tensor<8xi32>, %b: tensor<8xi32>) -> tensor<8xi32> {
%0 = stablehlo.subtract %a, %b : tensor<8xi32>
return %0 : tensor<8xi32>
}
} | integer subtraction | stablehlo+func |
04_multiply-2d | easy | Write a function that multiplies two 4x4 f32 tensors elementwise using stablehlo.multiply. | module {
func.func @mul(%a: tensor<4x4xf32>, %b: tensor<4x4xf32>) -> tensor<4x4xf32> {
%0 = stablehlo.multiply %a, %b : tensor<4x4xf32>
return %0 : tensor<4x4xf32>
}
} | static 4x4 multiply | stablehlo+func |
05_divide-f64 | easy | Write a function that divides two 1-D f64 tensors of 32 elements using stablehlo.divide. | module {
func.func @div(%a: tensor<32xf64>, %b: tensor<32xf64>) -> tensor<32xf64> {
%0 = stablehlo.divide %a, %b : tensor<32xf64>
return %0 : tensor<32xf64>
}
} | f64 division | stablehlo+func |
06_abs-f32 | easy | Write a function that computes the elementwise absolute value of a 1-D f32 tensor. | module {
func.func @ab(%a: tensor<16xf32>) -> tensor<16xf32> {
%0 = stablehlo.abs %a : tensor<16xf32>
return %0 : tensor<16xf32>
}
} | abs | stablehlo+func |
07_exp-1d | easy | Write a function that computes the elementwise exponential of a 1-D f32 tensor of 10 elements. | module {
func.func @ex(%a: tensor<10xf32>) -> tensor<10xf32> {
%0 = stablehlo.exponential %a : tensor<10xf32>
return %0 : tensor<10xf32>
}
} | exp | stablehlo+func |
08_abs-dynamic | medium | Write a function that computes the elementwise absolute value of a dynamic-shape 2-D f32 tensor. | module {
func.func @abd(%a: tensor<?x?xf32>) -> tensor<?x?xf32> {
%0 = stablehlo.abs %a : tensor<?x?xf32>
return %0 : tensor<?x?xf32>
}
} | dynamic abs | stablehlo+func |
09_transpose-2d | medium | Write a function that transposes a 4x8 f32 tensor producing an 8x4 tensor. | module {
func.func @t(%a: tensor<4x8xf32>) -> tensor<8x4xf32> {
%0 = stablehlo.transpose %a, dims = [1, 0] : (tensor<4x8xf32>) -> tensor<8x4xf32>
return %0 : tensor<8x4xf32>
}
} | transpose 2D | stablehlo+func |
10_transpose-3d | medium | Write a function that transposes a 2x3x4 f32 tensor with permutation [2, 0, 1] producing a 4x2x3 tensor. | module {
func.func @t3(%a: tensor<2x3x4xf32>) -> tensor<4x2x3xf32> {
%0 = stablehlo.transpose %a, dims = [2, 0, 1] : (tensor<2x3x4xf32>) -> tensor<4x2x3xf32>
return %0 : tensor<4x2x3xf32>
}
} | 3D transpose | stablehlo+func |
11_transpose-square | easy | Write a function that transposes a 3x3 f32 tensor. | module {
func.func @t(%a: tensor<3x3xf32>) -> tensor<3x3xf32> {
%0 = stablehlo.transpose %a, dims = [1, 0] : (tensor<3x3xf32>) -> tensor<3x3xf32>
return %0 : tensor<3x3xf32>
}
} | square transpose | stablehlo+func |
12_broadcast-1d-to-2d | medium | Write a function that broadcasts a 1-D f32 tensor of 8 elements to a 4x8 2-D tensor along dimension 1. | module {
func.func @b(%a: tensor<8xf32>) -> tensor<4x8xf32> {
%0 = stablehlo.broadcast_in_dim %a, dims = [1] : (tensor<8xf32>) -> tensor<4x8xf32>
return %0 : tensor<4x8xf32>
}
} | broadcast 1D to 2D | stablehlo+func |
13_broadcast-scalar-to-vector | medium | Write a function that broadcasts a scalar f32 (shape [1]) to a 1-D f32 tensor of 16 elements. | module {
func.func @bs(%a: tensor<1xf32>) -> tensor<16xf32> {
%0 = stablehlo.broadcast_in_dim %a, dims = [0] : (tensor<1xf32>) -> tensor<16xf32>
return %0 : tensor<16xf32>
}
} | scalar broadcast | stablehlo+func |
14_reshape-flatten | medium | Write a function that flattens a 4x8 f32 tensor into a 1-D tensor of 32 elements. | module {
func.func @r(%a: tensor<4x8xf32>) -> tensor<32xf32> {
%0 = stablehlo.reshape %a : (tensor<4x8xf32>) -> tensor<32xf32>
return %0 : tensor<32xf32>
}
} | flatten | stablehlo+func |
15_reshape-2d-to-3d | medium | Write a function that reshapes a 12x8 f32 tensor into a 3x4x8 3-D tensor. | module {
func.func @r(%a: tensor<12x8xf32>) -> tensor<3x4x8xf32> {
%0 = stablehlo.reshape %a : (tensor<12x8xf32>) -> tensor<3x4x8xf32>
return %0 : tensor<3x4x8xf32>
}
} | 2D to 3D reshape | stablehlo+func |
16_reshape-transpose-chain | hard | Write a function that flattens a 4x8 f32 tensor, then transposes the result — no wait, simpler: reshape a 4x8 tensor into 8x4. | module {
func.func @r(%a: tensor<4x8xf32>) -> tensor<8x4xf32> {
%0 = stablehlo.reshape %a : (tensor<4x8xf32>) -> tensor<8x4xf32>
return %0 : tensor<8x4xf32>
}
} | reshape shape change | stablehlo+func |
17_dot_general-matmul | medium | Write a function that performs a matrix multiplication of a 4x8 f32 tensor and an 8x16 f32 tensor using stablehlo.dot_general. | module {
func.func @m(%a: tensor<4x8xf32>, %b: tensor<8x16xf32>) -> tensor<4x16xf32> {
%0 = stablehlo.dot_general %a, %b, contracting_dims = [1] x [0] : (tensor<4x8xf32>, tensor<8x16xf32>) -> tensor<4x16xf32>
return %0 : tensor<4x16xf32>
}
} | canonical matmul | stablehlo+func |
18_dot_general-square | medium | Write a function that multiplies two 8x8 f32 tensors using stablehlo.dot_general. | module {
func.func @m(%a: tensor<8x8xf32>, %b: tensor<8x8xf32>) -> tensor<8x8xf32> {
%0 = stablehlo.dot_general %a, %b, contracting_dims = [1] x [0] : (tensor<8x8xf32>, tensor<8x8xf32>) -> tensor<8x8xf32>
return %0 : tensor<8x8xf32>
}
} | square matmul | stablehlo+func |
19_dot_general-tall-thin | medium | Multiply a 128x16 f32 tensor by a 16x4 f32 tensor using stablehlo.dot_general. | module {
func.func @m(%a: tensor<128x16xf32>, %b: tensor<16x4xf32>) -> tensor<128x4xf32> {
%0 = stablehlo.dot_general %a, %b, contracting_dims = [1] x [0] : (tensor<128x16xf32>, tensor<16x4xf32>) -> tensor<128x4xf32>
return %0 : tensor<128x4xf32>
}
} | tall-thin matmul | stablehlo+func |
20_add-multiply-chain | medium | Write a function that adds two 1-D f32 tensors and then multiplies the sum by the first input. | module {
func.func @c(%a: tensor<16xf32>, %b: tensor<16xf32>) -> tensor<16xf32> {
%0 = stablehlo.add %a, %b : tensor<16xf32>
%1 = stablehlo.multiply %0, %a : tensor<16xf32>
return %1 : tensor<16xf32>
}
} | add-then-multiply | stablehlo+func |
21_abs-exp-chain | medium | Write a function that computes the exponential of the absolute value of a 1-D f32 tensor. | module {
func.func @c(%a: tensor<16xf32>) -> tensor<16xf32> {
%0 = stablehlo.abs %a : tensor<16xf32>
%1 = stablehlo.exponential %0 : tensor<16xf32>
return %1 : tensor<16xf32>
}
} | abs then exp | stablehlo+func |
22_matmul-add-bias | hard | Matrix-multiply a 4x8 f32 tensor by an 8x16 f32 tensor, then add a 4x16 bias tensor. | module {
func.func @lin(%a: tensor<4x8xf32>, %b: tensor<8x16xf32>, %bias: tensor<4x16xf32>) -> tensor<4x16xf32> {
%0 = stablehlo.dot_general %a, %b, contracting_dims = [1] x [0] : (tensor<4x8xf32>, tensor<8x16xf32>) -> tensor<4x16xf32>
%1 = stablehlo.add %0, %bias : tensor<4x16xf32>
return %1 : tensor<4x1... | linear layer | stablehlo+func |
23_transpose-matmul | hard | Transpose a 8x4 f32 tensor, then matrix-multiply the result with a 4x16 f32 tensor. | module {
func.func @tm(%a: tensor<8x4xf32>, %b: tensor<8x16xf32>) -> tensor<4x16xf32> {
%0 = stablehlo.transpose %a, dims = [1, 0] : (tensor<8x4xf32>) -> tensor<4x8xf32>
%1 = stablehlo.dot_general %0, %b, contracting_dims = [1] x [0] : (tensor<4x8xf32>, tensor<8x16xf32>) -> tensor<4x16xf32>
return %1 : te... | transpose+matmul | stablehlo+func |
24_reshape-add | medium | Reshape a 4x4 f32 tensor into a 16-element 1-D tensor, then add to an existing 16-element tensor. | module {
func.func @ra(%a: tensor<4x4xf32>, %b: tensor<16xf32>) -> tensor<16xf32> {
%0 = stablehlo.reshape %a : (tensor<4x4xf32>) -> tensor<16xf32>
%1 = stablehlo.add %0, %b : tensor<16xf32>
return %1 : tensor<16xf32>
}
} | reshape+add | stablehlo+func |
25_broadcast-multiply | hard | Broadcast a length-8 1-D f32 tensor to a 4x8 tensor, then multiply with an existing 4x8 tensor. | module {
func.func @bm(%a: tensor<8xf32>, %b: tensor<4x8xf32>) -> tensor<4x8xf32> {
%0 = stablehlo.broadcast_in_dim %a, dims = [1] : (tensor<8xf32>) -> tensor<4x8xf32>
%1 = stablehlo.multiply %0, %b : tensor<4x8xf32>
return %1 : tensor<4x8xf32>
}
} | broadcast+multiply | stablehlo+func |
26_add-3d | easy | Write a function that adds two 2x3x4 f32 tensors elementwise. | module {
func.func @a3(%a: tensor<2x3x4xf32>, %b: tensor<2x3x4xf32>) -> tensor<2x3x4xf32> {
%0 = stablehlo.add %a, %b : tensor<2x3x4xf32>
return %0 : tensor<2x3x4xf32>
}
} | 3D add | stablehlo+func |
27_subtract-bf16 | easy | Write a function that subtracts two 16-element bf16 tensors elementwise. | module {
func.func @s(%a: tensor<16xbf16>, %b: tensor<16xbf16>) -> tensor<16xbf16> {
%0 = stablehlo.subtract %a, %b : tensor<16xbf16>
return %0 : tensor<16xbf16>
}
} | bf16 arithmetic | stablehlo+func |
28_dot_general-f16 | medium | Multiply two 16x16 f16 tensors using stablehlo.dot_general. | module {
func.func @m(%a: tensor<16x16xf16>, %b: tensor<16x16xf16>) -> tensor<16x16xf16> {
%0 = stablehlo.dot_general %a, %b, contracting_dims = [1] x [0] : (tensor<16x16xf16>, tensor<16x16xf16>) -> tensor<16x16xf16>
return %0 : tensor<16x16xf16>
}
} | f16 matmul | stablehlo+func |
29_add-multiply-abs-chain | hard | Write a function that computes the absolute value of (a + b) * a for two 1-D f32 tensors. | module {
func.func @c(%a: tensor<16xf32>, %b: tensor<16xf32>) -> tensor<16xf32> {
%0 = stablehlo.add %a, %b : tensor<16xf32>
%1 = stablehlo.multiply %0, %a : tensor<16xf32>
%2 = stablehlo.abs %1 : tensor<16xf32>
return %2 : tensor<16xf32>
}
} | 3-op chain | stablehlo+func |
30_transpose-add | medium | Transpose a 4x4 f32 tensor then add it back to the original. | module {
func.func @ta(%a: tensor<4x4xf32>) -> tensor<4x4xf32> {
%0 = stablehlo.transpose %a, dims = [1, 0] : (tensor<4x4xf32>) -> tensor<4x4xf32>
%1 = stablehlo.add %0, %a : tensor<4x4xf32>
return %1 : tensor<4x4xf32>
}
} | symmetric sum | stablehlo+func |
StableHLO-Spec-30
Hand-authored NL→StableHLO pairs across 10 op families (n=30).
Composition
- Instances: 30
- Format: one JSON record per line in
data/test.jsonl - Schema: fields =
dialect,difficulty,id,mlir,nl,notes - Verifier:
stablehlo-opt v1.4.0(upstream truth) andiree-compile --compile-to=input(substitute, 50/50 concordant on a stratified n=50 sample) - License: Apache-2.0 (SPDX: Apache-2.0). No third-party IP restrictions.
Loading
from datasets import load_dataset
ds = load_dataset("plawanrath/StableHLO-Spec-30", split="test")
print(ds[0])
Each record is a self-contained natural-language→MLIR pair; verify-valid pass-rate under the dialect's verifier is the primary evaluation metric.
Source format
The JSONL file at data/test.jsonl is the canonical HuggingFace interface.
MLCommons Croissant 1.0 metadata (croissant.json) ships alongside the
release.
Datasheet
Key points (full Gebru-style datasheet ships with the dataset archive):
- All reference MLIR programs are verifier-clean at the time of release.
- Hand-authored (no crowdsourcing, no LLM-authored references).
- Test-only — fine-tuning on these benchmarks contaminates future evaluation and is explicitly out of scope.
License
Apache-2.0. See LICENSE.
- Downloads last month
- 29