Thanks for participating in the TVM community! We use https://discuss.tvm.apache.org/ for any general usage questions and discussions. The issue tracker is used for actionable items such as feature proposals discussion, roadmaps, and bug tracking. You are always welcomed to post on the forum first 😸
Issues that are inactive for a period of time may get closed. We adopt this policy so that we won't lose track of actionable issues that may fall at the bottom of the pile. Feel free to reopen a new one if you feel there is an additional problem that needs attention when an old one gets closed.
Expected behavior
relax.op.nn.adaptive_avg_pool2d should return the average of each adaptive pooling window. For a (1, 1, 3, 4) NCHW input and output_size=(2, 2), the standard overlapping windows are:
height: [0:2], [1:3]
width : [0:2], [2:4]
For the input below, the expected output is:
input =
10 11 12 13
14 15 16 17
18 19 20 21
expected =
12.5 14.5
16.5 18.5
Actual behavior
The module builds and runs without an exception, but the LLVM CPU execution returns:
6.5 7.5
8.5 9.5
The maximum absolute difference is 9.0. The same incorrect result was observed with the project's default, zero, and none Relax pipelines.
This is a numerical correctness issue rather than a compilation crash. It can silently propagate incorrect values to later model computations.
The original fuzzing seed contained additional reshape, leakyrelu, pow, and strided_slice nodes. The first output, directly produced by adaptive_avg_pool2d, already mismatched in all 8 elements. The pow node was ruled out: it uses a positive integer exponent and its result is dead code, not part of the returned values.
Environment
- OS: Linux x86_64 under WSL2 (
6.6.114.1-microsoft-standard-WSL2)
- Python: 3.10.20
- NumPy: 1.26.4
- TVM: 0.25.dev0
- TVM source under test: local
tvm-relax-src fork, commit 4d9d129c9
- Target:
llvm, executed by relax.VirtualMachine on CPU
- Build used for the reproduction:
/home/cxk/tvm-relax-src/build-gcov
Steps to reproduce
Save the following as repro.py in a configured TVM environment:
import numpy as np
import tvm
from tvm import relax
from tvm.script import relax as R
data = np.arange(10, 22, dtype="float32").reshape(1, 1, 3, 4)
@tvm.script.ir_module
class Mod:
@R.function
def main(x: R.Tensor((1, 1, 3, 4), "float32")) -> R.Tensor((1, 1, 2, 2), "float32"):
return R.nn.adaptive_avg_pool2d(x, output_size=(2, 2), layout="NCHW")
ex = relax.build(Mod, target="llvm")
vm = relax.VirtualMachine(ex, tvm.cpu())
actual = vm["main"](tvm.runtime.tensor(data, tvm.cpu())).numpy()[0, 0]
expected = np.array([[12.5, 14.5], [16.5, 18.5]], dtype="float32")
print("actual:", actual)
print("expected:", expected)
print("max_abs_diff:", np.max(np.abs(actual - expected)))
np.testing.assert_allclose(actual, expected, rtol=1e-5, atol=1e-5)
Triage
Related issue: (#19520) reports a CUDA compilation crash for adaptive_avg_pool2d when the output size does not evenly divide the input. The present report is different in backend and symptom: LLVM/CPU execution succeeds but returns incorrect values. It should be treated as related, not as a duplicate.
Thanks for participating in the TVM community! We use https://discuss.tvm.apache.org/ for any general usage questions and discussions. The issue tracker is used for actionable items such as feature proposals discussion, roadmaps, and bug tracking. You are always welcomed to post on the forum first 😸
Issues that are inactive for a period of time may get closed. We adopt this policy so that we won't lose track of actionable issues that may fall at the bottom of the pile. Feel free to reopen a new one if you feel there is an additional problem that needs attention when an old one gets closed.
Expected behavior
relax.op.nn.adaptive_avg_pool2d should return the average of each adaptive pooling window. For a
(1, 1, 3, 4)NCHW input andoutput_size=(2, 2), the standard overlapping windows are:height: [0:2], [1:3]
width : [0:2], [2:4]
For the input below, the expected output is:
input =
10 11 12 13
14 15 16 17
18 19 20 21
expected =
12.5 14.5
16.5 18.5
Actual behavior
The module builds and runs without an exception, but the LLVM CPU execution returns:
6.5 7.5
8.5 9.5
The maximum absolute difference is
9.0. The same incorrect result was observed with the project'sdefault,zero, andnoneRelax pipelines.This is a numerical correctness issue rather than a compilation crash. It can silently propagate incorrect values to later model computations.
The original fuzzing seed contained additional
reshape,leakyrelu,pow, andstrided_slicenodes. The first output, directly produced byadaptive_avg_pool2d, already mismatched in all 8 elements. Thepownode was ruled out: it uses a positive integer exponent and its result is dead code, not part of the returned values.Environment
6.6.114.1-microsoft-standard-WSL2)tvm-relax-srcfork, commit4d9d129c9llvm, executed byrelax.VirtualMachineon CPU/home/cxk/tvm-relax-src/build-gcovSteps to reproduce
Save the following as
repro.pyin a configured TVM environment:import numpy as np
import tvm
from tvm import relax
from tvm.script import relax as R
data = np.arange(10, 22, dtype="float32").reshape(1, 1, 3, 4)
@tvm.script.ir_module
class Mod:
@R.function
def main(x: R.Tensor((1, 1, 3, 4), "float32")) -> R.Tensor((1, 1, 2, 2), "float32"):
return R.nn.adaptive_avg_pool2d(x, output_size=(2, 2), layout="NCHW")
ex = relax.build(Mod, target="llvm")
vm = relax.VirtualMachine(ex, tvm.cpu())
actual = vm["main"](tvm.runtime.tensor(data, tvm.cpu())).numpy()[0, 0]
expected = np.array([[12.5, 14.5], [16.5, 18.5]], dtype="float32")
print("actual:", actual)
print("expected:", expected)
print("max_abs_diff:", np.max(np.abs(actual - expected)))
np.testing.assert_allclose(actual, expected, rtol=1e-5, atol=1e-5)
Triage
Related issue: (#19520) reports a CUDA compilation crash for
adaptive_avg_pool2dwhen the output size does not evenly divide the input. The present report is different in backend and symptom: LLVM/CPU execution succeeds but returns incorrect values. It should be treated as related, not as a duplicate.