Skip to content

[Bug][Relax] Arithmetic on an unbatched AdaptiveAvgPool2d output fails in from_exported_program: "Please convert 2.0 with const first" #20943

Open

Description

@raindrops-0199

Expected behavior

AdaptiveAvgPool2d accepts an unbatched (C, H, W) input, and pool(x) * 2.0 works in eager and torch.export, so from_exported_program should convert it.

Actual behavior

The conversion fails. torch.maximum or torch.minimum of two such outputs fails with maximum(): argument 'input' (position 1) must be Tensor, not Call. AdaptiveAvgPool3d with an unbatched (C, D, H, W) input fails the same way. A batched input, or an output size of (1, 1), works.

TypeError: Please convert 2.0 with `const` first

Possibly _adaptive_avg_pool2d and _adaptive_avg_pool3d return the squeeze for an unbatched input without emitting it, so _binary_op gets a Call instead of a Var.

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 __init__(self):
        super().__init__()
        self.pool = torch.nn.AdaptiveAvgPool2d((2, 2))

    def forward(self, x):
        return self.pool(x) * 2.0


x = torch.rand(2, 4, 4)  # no batch dimension
args = (x,)
print("eager:", M()(*args).flatten().tolist())

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().flatten().tolist())

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
  2. GoyalIshaan commented on Nov 9, 2026

    @GoyalIshaan

    Is this available for me to work on? I’d investigate the unbatched pooling output handling and add CPU tests for 2D/3D pooling followed by scalar arithmetic and maximum/minimum, keeping the batched cases as controls.

    AI disclosure: this request was drafted and posted with AI assistance. I would implement the fix and submit the PR myself.

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