Skip to content

[Bug] Meta schedule produce inconsistant inference results #17947

@Cookiee235

Description

@Cookiee235

When I optimized the model using MetaSchedule, the modified model produced inconsistent inference results compared to the original model for the same inputs. This suggests a potential bug in MetaSchedule's implementation. In my view, MetaSchedule should always ensure semantically equivalent transformations of the model.

Actual behavior

Traceback (most recent call last):
  File "/data/qshenaf/remote_pc/TirFuzz/bugs/05-11_03-53/topi.expand_like_1.py", line 31, in <module>
    np.testing.assert_allclose(
  File "/data/qshenaf/miniconda3/envs/tvm/lib/python3.12/site-packages/numpy/testing/_private/utils.py", line 1715, in assert_allclose
    assert_array_compare(compare, actual, desired, err_msg=str(err_msg),
  File "/data/qshenaf/miniconda3/envs/tvm/lib/python3.12/site-packages/numpy/testing/_private/utils.py", line 921, in assert_array_compare
    raise AssertionError(msg)
AssertionError:
Not equal to tolerance rtol=1e-05, atol=1e-05
An Inconsistent ouputs
Mismatched elements: 9 / 60 (15%)
Max absolute difference among violations: 502
Max relative difference among violations: inf
 ACTUAL: array([[[  0,   0,   0],
        [  0,   0,   0],
        [  0,   0,   0],...
 DESIRED: array([[[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],...

Environment

tvm-0.21-dev0

Steps to reproduce

import tvm
from tvm import te, topi, tir
from tvm import meta_schedule as ms
import numpy as np


def compile_mod(mod, np_input_list, output_shape, output_type, opt_level=3):
    with tvm.transform.PassContext(opt_level):
        ref_mod = tvm.build(mod, target='llvm')
    mod_output = tvm.nd.empty(output_shape, dtype=output_type, device=tvm.cpu(0))

    tvm_inputs = [tvm.nd.array(x) for x in np_input_list]
    ref_mod(*tvm_inputs, mod_output)
    return mod_output


a = te.placeholder((5, 1), dtype='int16', name='a')
shape_like = te.placeholder((5, 4, 3), dtype='float64', name='shape_like')
op_output = topi.expand_like(a, shape_like=shape_like, axis=[2])
np_inputs = [np.random.uniform(-1, 1, size=(5, 1)).astype('int16'),np.random.uniform(-1, 1, size=(5, 4, 3)).astype('float64')]
sch = tir.Schedule(te.create_prim_func([a, shape_like, op_output]).with_attr('target', tvm.target.Target('llvm')))
ref_output = compile_mod(sch.mod, np_inputs, op_output.shape, op_output.dtype, opt_level=0)

database = ms.tir_integration.tune_tir(mod=sch.mod, target='llvm --num-cores=16', work_dir='./tune_tmp', max_trials_global=1, num_trials_per_iter=1)
sch = ms.tir_integration.compile_tir(database, sch.mod, 'llvm --num-cores=16')
opt_mod_output = compile_mod(sch.mod, np_inputs, op_output.shape, op_output.dtype, opt_level=0)

np.testing.assert_allclose(
    ref_output.numpy(), opt_mod_output.numpy(), rtol=1e-5, atol=1e-5, err_msg=f"An Inconsistent ouputs"

Triage

  • needs-triage
  • tune:metaschedule

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