Skip to content

[Bug][Relax] interpolate(mode="bilinear", align_corners=True) to an output size of 1 fails in tvm.compile: "Divide by zero" #20941

Open

Description

@raindrops-0199

Expected behavior

With align_corners=True and an output size of 1 along an axis, PyTorch samples the first input element along that axis. It works in eager and torch.export, so tvm.compile should build it.

Actual behavior

tvm.compile fails. The same happens for an output size of (6, 1) or (1, 1), and for a scale_factor that gives an output size of 1 (e.g. an input height of 1 with scale_factor=1.5). align_corners=False, or output sizes larger than 1, work.

eager: torch.Size([1, 1, 1, 6])
RuntimeError: Check failed: fb->value != 0 (0 vs. 0) : Divide by zero

Possibly get_inx in topi/image/resize.py divides by target_width - 1 in the align_corners mode, without the size-one guard that the pytorch_half_pixel mode has.

Environment

  • TVM: main @ 2bf0532 (0.28.dev0), built from source, target llvm
  • PyTorch: 2.12.0+cu130
  • Python: 3.12, Ubuntu x86_64

Steps to reproduce

import torch
import tvm
import tvm_tirx
from tvm import relax
from tvm.relax.frontend.torch import from_exported_program


class M(torch.nn.Module):
    def forward(self, x):
        return torch.nn.functional.interpolate(x, size=(1, 6), mode="bilinear", align_corners=True)


x = torch.rand(1, 1, 4, 4)
args = (x,)
print("eager:", M()(x).shape)

ep = torch.export.export(M(), args)
mod = from_exported_program(ep)
ex = tvm.compile(mod, target="llvm")
vm = relax.VirtualMachine(ex, tvm_tirx.cpu())
out = vm["main"](*[tvm_tirx.runtime.tensor(a.numpy()) for a in args])
print("tvm:  ", out[0].numpy().shape)

Activity

  1. added
    needs-triagePRs or issues that need to be investigated by maintainers to find the right assignees to address it
    on Nov 9, 2026
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

    needs-triagePRs or issues that need to be investigated by maintainers to find the right assignees to address ittype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions