Skip to content

[CUDA] Wrong results for a 1×1 stride-2 conv when it lands in the reduction vector distribution pipeline #25303

Open

Description

@HarithF

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.

  1. Save this as repro.py and run it with python repro.py. It needs torch and iree-turbine, and writes pair_block.mlir, input.npy and PyTorch's output as expected.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()
  1. 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
  1. 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'
done

Output:

== 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

  1. added
    bug 🐞
    on Nov 18, 2026
  2. github-actions commented on Nov 18, 2026

    @github-actions

    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:

    • Issue reporters must fully understand the primary issue and the impact of the problem.
      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.
    • Contributors must write the summary of the issue themselves, so that the exact impact and scenario is clear to other participants.
    • Issue authors are expected to review and understand all LLM/AI-assisted segments of the report, if any. E.g.: CLI commands and IR reproducers, model/framework details, lowering pipeline details, assumptions about problematic behaviors of IREE components.
    • Substantial use of LLM/generative AI tools must be disclaimed in the header or footer of the issue description.

    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

  3. HarithF commented on Nov 18, 2026

    @HarithF
    Author

    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:

    * Issue reporters must fully understand the primary issue and the impact of the problem.
      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.
    
    * Contributors must write the summary of the issue themselves, so that the exact impact and scenario is clear to other participants.
    
    * Issue authors are expected to review and understand all LLM/AI-assisted segments of the report, if any. E.g.: CLI commands and IR reproducers, model/framework details, lowering pipeline details, assumptions about problematic behaviors of IREE components.
    
    * Substantial use of LLM/generative AI tools must be disclaimed in the header or footer of the issue description.
    

    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

    I understand the policy

  4. weimin023 commented on Dec 3, 2026

    @weimin023
    Contributor

    Hi @HarithF,

    I reproduced this on SM120 and can fix it. I’ll send a regression test and fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐞

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions