Repository navigation
Description
What happened?
I've been compiling the KernelBench Level 3 models with IREE (exported through iree-turbine). ResNet101 matched PyTorch on llvm-cpu but failed the correctness check on CUDA. I narrowed it down to the stage transitions, where the first bottleneck block has a 1×1 stride-2 downsample conv on its shortcut.
In the full program, that conv ends up as a reduction dispatch, with the stride folded into the input's indexing map:
// @main$async_dispatch_5_reduction_10x512x28x28x256_f32
%7 = linalg.generic {indexing_maps = [
affine_map<(d0, d1, d2, d3, d4) -> (d0, d4, d2 * 2, d3 * 2)>,
affine_map<(d0, d1, d2, d3, d4) -> (d1, d4)>,
affine_map<(d0, d1, d2, d3, d4) -> (d0, d1, d2, d3)>],
iterator_types = ["parallel", "parallel", "parallel", "parallel", "reduction"]}
ins(%3, %4 : tensor<10x256x56x56xf32>, tensor<512x256xf32>)
outs(%6 : tensor<10x512x28x28xf32>)However, the other convs in the program become matmul_like or conv dispatches. Compiling the downsample conv on its own, the stride goes into the load instead (strides = [1, 1, 2, 2]), the dispatch is matmul_like instead, producing correct results. So the bug only shows up when the conv is part of a larger program, which is why the reproducer below has two full bottleneck blocks.
With --iree-codegen-llvmgpu-use-reduction-vector-distribution=false the CUDA output is correct again (see the steps below).
So my guess is that the reduction pipeline doesn't handle the strided input map, but I haven't dug into the pipeline itself.
Steps to reproduce your issue
The weights are random, so nothing needs to be downloaded. It needs the real ResNet101 sizes; with smaller channels the conv doesn't become a reduction dispatch and the bug goes away.
- Save this as
repro.pyand run it withpython repro.py. It needstorchandiree-turbine, and writespair_block.mlir,input.npyand PyTorch's output asexpected.npy.
import numpy as np, torch
from iree.turbine import aot
class BN(torch.nn.Module):
def __init__(self, ch): super().__init__(); self.bn = torch.nn.BatchNorm2d(ch)
def forward(self, x): return self.bn(x)
class Bottleneck(torch.nn.Module):
expansion = 4
def __init__(self, in_ch, out_ch, stride=1, downsample=None):
super().__init__()
self.conv1 = torch.nn.Conv2d(in_ch, out_ch, 1, bias=False)
self.bn1 = BN(out_ch)
self.conv2 = torch.nn.Conv2d(out_ch, out_ch, 3, stride=stride, padding=1, bias=False)
self.bn2 = BN(out_ch)
self.conv3 = torch.nn.Conv2d(out_ch, out_ch*4, 1, bias=False)
self.bn3 = BN(out_ch*4)
self.relu = torch.nn.ReLU(inplace=True)
self.downsample = downsample
def forward(self, x):
idt = x
o = self.relu(self.bn1(self.conv1(x)))
o = self.relu(self.bn2(self.conv2(o)))
o = self.bn3(self.conv3(o))
if self.downsample is not None: idt = self.downsample(x)
return self.relu(o + idt)
class PairBlock(torch.nn.Module):
def __init__(self, a, b): super().__init__(); self.a = a; self.b = b
def forward(self, x): return self.b(self.a(x))
def main():
# Full ResNet101 sizes for the layer1.2 -> layer2.0 transition
CH_IN, BLOCK_A, BLOCK_B, BS, S = 256, 64, 128, 10, 56
torch.manual_seed(0)
ds = torch.nn.Sequential(torch.nn.Conv2d(CH_IN, BLOCK_B*4, 1, stride=2, bias=False), BN(BLOCK_B*4))
blk_a = Bottleneck(CH_IN, BLOCK_A)
blk_b = Bottleneck(CH_IN, BLOCK_B, stride=2, downsample=ds)
m = PairBlock(blk_a, blk_b).eval()
with torch.no_grad():
for p in m.parameters(): p.normal_(0, 0.1)
x = torch.randn(BS, CH_IN, S, S)
np.save("input.npy", x.numpy())
np.save("expected.npy", m(x).numpy()) # PyTorch reference output
aot.export(m, x).save_mlir("pair_block.mlir")
if __name__ == "__main__":
main()- Compile it for CPU, for CUDA, and for CUDA with reduction vector distribution turned off:
iree-compile pair_block.mlir -o cpu.vmfb --iree-hal-target-backends=llvm-cpu --iree-llvmcpu-target-cpu=host
iree-compile pair_block.mlir -o cuda.vmfb --iree-hal-target-backends=cuda
iree-compile pair_block.mlir -o cuda_fix.vmfb --iree-hal-target-backends=cuda \
--iree-codegen-llvmgpu-use-reduction-vector-distribution=false- Run each build and compare it with the PyTorch output:
for b in cpu:local-task cuda:cuda cuda_fix:cuda; do
echo "== ${b%%:*}"
iree-run-module --module=${b%%:*}.vmfb --device=${b##*:} --function=main \
[email protected] [email protected] \
--expected_rtol=1e-3 --expected_f32_threshold=1e-2 2>&1 | grep -E 'SUCCESS|FAILED'
doneOutput:
== cpu
[SUCCESS] all function outputs matched their expected values.
== cuda
[FAILED] result[0]: element at index 5 (0) does not match the expected (0.0176343); expected that the view is equal to contents of a view of 10x512x28x28xf32
== cuda_fix
[SUCCESS] all function outputs matched their expected values.
The grep is only there to keep the output short: without it, the failing cuda run also prints the expected and actual 10x512x28x28 tensors, about 1.4 MB of text on two very long lines.
What component(s) does this issue relate to?
No response
Version information
Environment: iree-base-compiler 3.13.0 (89ece87b), also 3.14.0; RTX PRO 500 Blackwell (sm_120) and A100 (sm_80); iree-turbine 3.9.
Additional context
Workaround: --iree-codegen-llvmgpu-use-reduction-vector-distribution=false. With it, ResNet101 passes and is about 2× faster.
Disclosure: the draft and minimal reproducer were created with help from Claude; I have reviewed them and verified the results myself.
Activity
github-actions commentedon Nov 18, 2026
Hello @HarithF 👋
Thank you for submitting an issue to IREE! It looks like it's your first one.
The volume of issues is huge, and triage times may vary. If you need quicker assistance on the issue, consider posting it on IREE Discord and providing short context there.
Feel free to identify the most frequent contributors to the corresponding part of the codebase via Git history/CODEOWNERS and (gently!) tag them below.
Action required: acknowledge IREE project policies
IREE is a Linux Foundation project. All participants are expected to follow the LF Projects Code of Conduct.
Please note that all contributions to IREE, including GitHub issues, must follow our IREE AI Tool Use Policy. This means:
For bug reports, specifics of the use-case, workflow and/or crash scenario usually suffice.
For improvement suggestions, this usually implies deeper understanding of suboptimal code, IR design choices, assumed performance tradeoffs, etc.
Before the issue can be triaged, we kindly ask you to reply to this message and confirm that you understand and accept the proposed policy. As required, please adjust your initial issue description.
If you have any questions, feel free to leave a comment here, or ask away on IREE Discord.
Thank you,
The IREE Community
HarithF commentedon Nov 18, 2026
I understand the policy
weimin023 commentedon Dec 3, 2026
Hi @HarithF,
I reproduced this on SM120 and can fix it. I’ll send a regression test and fix.