Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Convolution outputs gibberish values when filter size > 32, with naive mapping options #179

Open
@jeanfeydy

Description

@jeanfeydy

Hi all,
When playing around with large convolution filters, I discovered an unexpected behavior: with a large filter, if the input image size exceeds 32, a standard convolution outputs gibberish results.

import tensor_comprehensions as tc
import torch
from torch.autograd import Variable
from matplotlib import pyplot as plt

def two_char(s) :
    if   s    == "0.0" : return ". " 
    elif s[0] == "0"   : return s[1:]
    else :               return s[:2]

def pretty_print(t) :
    l = [two_char("{:.1f}".format(i)) for i in t.data.cpu().numpy()]
    return " ".join(l)

convolution_lang = """
def convolution(float(X) A, float(Xp) K) -> (B) {
    B(x)   +=! A(xp) * K(X-1+x-xp) where xp in 0:X
}
"""

convolution = tc.define(convolution_lang, name="convolution")

for X in [30,31,32,33,34] :
    A = torch.zeros(X).cuda()
    A[10] = 1
    A = Variable(A)

    # len(C) = 2*X-1
    C = Variable( torch.arange(-X+1,X).cuda()**2 )
    K = (-C/9).exp()

    B = convolution( A, K )

    print("X =", X, "==============================")
    print("A :\n",         pretty_print(A) )
    print("K :\n",         pretty_print(K))
    print("B = A ★ K :\n", pretty_print(B))
[WARNING]: No mapping options passed, 'naive' type mapping options will be used and will likely have bad performance. See help(your_layer.__call__) for setting mapping options.
X = 30 ==============================
A :
 .  .  .  .  .  .  .  .  .  .  1. .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
K :
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .1 .2 .4 .6 .9 1. .9 .6 .4 .2 .1 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
B = A ★ K :
 .  .  .  .  .  .1 .2 .4 .6 .9 1. .9 .6 .4 .2 .1 .  .  .  .  .  .  .  .  .  .  .  .  .  . 
[WARNING]: No mapping options passed, 'naive' type mapping options will be used and will likely have bad performance. See help(your_layer.__call__) for setting mapping options.
X = 31 ==============================
A :
 .  .  .  .  .  .  .  .  .  .  1. .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
K :
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .1 .2 .4 .6 .9 1. .9 .6 .4 .2 .1 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
B = A ★ K :
 .  .  .  .  .  .1 .2 .4 .6 .9 1. .9 .6 .4 .2 .1 .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
[WARNING]: No mapping options passed, 'naive' type mapping options will be used and will likely have bad performance. See help(your_layer.__call__) for setting mapping options.
X = 32 ==============================
A :
 .  .  .  .  .  .  .  .  .  .  1. .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
K :
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .1 .2 .4 .6 .9 1. .9 .6 .4 .2 .1 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
B = A ★ K :
 .  .  .  .  .  .1 .2 .4 .6 .9 1. .9 .6 .4 .2 .1 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
[WARNING]: No mapping options passed, 'naive' type mapping options will be used and will likely have bad performance. See help(your_layer.__call__) for setting mapping options.
X = 33 ==============================
A :
 .  .  .  .  .  .  .  .  .  .  1. .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
K :
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .1 .2 .4 .6 .9 1. .9 .6 .4 .2 .1 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
B = A ★ K :
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
[WARNING]: No mapping options passed, 'naive' type mapping options will be used and will likely have bad performance. See help(your_layer.__call__) for setting mapping options.
X = 34 ==============================
A :
 .  .  .  .  .  .  .  .  .  .  1. .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
K :
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .1 .2 .4 .6 .9 1. .9 .6 .4 .2 .1 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
B = A ★ K :
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 

The output "B" should have stayed equal to a translated copy of the convolution filter, but for one reason or another, this stops being true when the length of A exceeds 32.

Note that using

B = convolution( A, K, options=tc.Options("conv") )

solves the issue... But this weird behavior may be related to #174
I'm running on Ubuntu 16.04, with a standard PyTorch+TC install from conda.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions