The result of "contrib conv2d winograd without weight transform" op is different in each run

The following is an example:

dtype = "float32"
x_shape = (1, 32, 16, 16)
w_shape = (6, 6, 64, 32)
x_data = np.random.random_sample(x_shape).astype(dtype)
w_data = np.random.random_sample(w_shape).astype(dtype)
np.savetxt("x_np.npy", x_data.flatten())
np.savetxt("w_np.npy", w_data.flatten())
x_np = np.loadtxt("x_np.npy").reshape(x_shape).astype(dtype)
w_np = np.loadtxt("w_np.npy").reshape(w_shape).astype(dtype)
x = relay.var("x", shape=x_shape, dtype=dtype)
w = relay.var("w", shape=w_shape, dtype=dtype)
y = relay.nn.contrib_conv2d_winograd_without_weight_transform(
    x,
    w,
    kernel_size=(3, 3),
    padding=(1, 1),
    groups=1,
    dilation=(1, 1),
    channels=64,
    tile_size=8,
    data_layout="NHWC",
    kernel_layout="HWIO",
)
func = relay.Function([x, w], y)
mod = tvm.IRModule().from_expr(func)
params = {}
inputs = {"x":tvm.nd.array(x_np), "w":tvm.nd.array(w_np)}
with tvm.transform.PassContext(opt_level=2):
   exe = relay.backend.vm.compile(mod=mod, params=params, target="llvm")
vm = tvm.runtime.vm.VirtualMachine(exe, device=tvm.device("llvm"))
out = vm.run(**{**params, **inputs})

The result of each run with the same input is different.

When I run this I get NaNs so there is probably some overflow/underflow/other funkiness. Are you sure you are using the func correctly?

You are passing empty params:

params = {}
with tvm.transform.PassContext(opt_level=2):
   exe = relay.backend.vm.compile(mod=mod, params=params, target="llvm")

Also w_shape = (6, 6, 64, 32) is probably not correct for contrib_conv2d_winograd_without_weight_transform.

I’m sorry. I revised the code:

def make_arr(shape, dtype):
    """ Make random numpy array by the shape and the dtype """
    arr = np.array([0])
    epsilon = 1e-10
    if "float" in dtype:
        dtype = "float32" if dtype=="float" else dtype
        while abs(arr).any() < epsilon: arr = (10*np.random.random_sample(shape)-5).astype(dtype)
    elif "uint" in dtype:
        range = 2**(int(re.search(r'\d+$',dtype).group()))
        low, high = 1, range
        arr = np.random.randint(low, high, shape, dtype)
    elif "int" in dtype:
        half = 2**(int(re.search(r'\d+$',dtype).group())-1)
        arr = np.random.randint(1, half-1, shape, dtype)*np.random.choice([-1,1],shape).astype(dtype)
    elif "bool" in dtype:
        arr = np.random.choice([True, False], shape)
    else:
        raise TypeError(f"{dtype} is not kind of data type.")
    return arr

dtype = "float32"
x_shape = (1, 32, 16, 16)
w_shape = (6, 6, 64, 32)
x_data = make_arr(x_shape, dtype)
w_data = make_arr(w_shape, dtype)
np.savetxt("x_np.npy", x_data.flatten())
np.savetxt("w_np.npy", w_data.flatten())
x_np = np.loadtxt("x_np.npy").reshape(x_shape).astype(dtype)
w_np = np.loadtxt("w_np.npy").reshape(w_shape).astype(dtype)
x = relay.var("x", shape=x_shape, dtype=dtype)
w = relay.var("w", shape=w_shape, dtype=dtype)
y = relay.nn.contrib_conv2d_winograd_without_weight_transform(
    x,
    w,
    kernel_size=(3, 3),
    padding=(1, 1),
    groups=1,
    dilation=(1, 1),
    channels=64,
    tile_size=8,
    data_layout="NHWC",
    kernel_layout="HWIO",
)
func = relay.Function([x, w], y)
mod = tvm.IRModule().from_expr(func)
params = {}
inputs = {"x":tvm.nd.array(x_np), "w":tvm.nd.array(w_np)}
with tvm.transform.PassContext(opt_level=2):
   exe = relay.backend.vm.compile(mod=mod, params=params, target="llvm")
vm = tvm.runtime.vm.VirtualMachine(exe, device=tvm.device("llvm"))
out = vm.run(**{**params, **inputs})