Hey again,
I realize that the method is not functioning if there is a difference > 1 between all the kernels. Is there something equivalent to SAME on tensorflow?
import torch
import torch.nn as nn
import torch.nn.functional as F

def create_kernal(kernel_size, largest_kernel):
    #return torch.cat([torch.ones(kernel_size), torch.zeros(kernel_size - 1 + max(largest_kernel + (largest_kernel - 1) - (kernel_size + (kernel_size - 1)), 0))])
    pad = kernel_size - 1 + max(largest_kernel + (largest_kernel - 1) - (kernel_size + (kernel_size - 1)), 0)
    offset = int(pad % 2 == 1)
    pad = pad // 2
    return F.pad(torch.ones(kernel_size), (pad + offset, pad), mode='constant', value=0)

inputs1 = [0 for _ in range(20)]
inputs1[8] = 1
inputs2 = [0 for _ in range(20)]
inputs2[13] = 1
inputs3 = [0 for _ in range(20)]
inputs3[1] = 1
inputs4 = [0 for _ in range(20)]
inputs4[0] = 1
inputs5 = [0 for _ in range(20)]
inputs5[18] = 1
inputs = torch.FloatTensor([inputs1, inputs2, inputs3, inputs4, inputs5])

kernel_size1 = 5
kernel_size2 = 4
kernel_size3 = 4 # Change it to 6 to see the problem.
kernel_size4 = 5
kernel_size5 = 4
all_kernels = [kernel_size1, kernel_size2, kernel_size3, kernel_size4, kernel_size5]
largest_kernel = max(all_kernels)
min_kernel = min(all_kernels)

ks = kernel_size1 - 1 + max(largest_kernel + (largest_kernel - 1) - (kernel_size1 + (kernel_size1 - 1)), 0)
kernels = torch.cat([create_kernal(kernel_size, largest_kernel).unsqueeze(0) for kernel_size in (kernel_size1, kernel_size2, kernel_size3, kernel_size4, kernel_size5)], axis=0)

inputs = inputs.unsqueeze(0) # Inverse channel and batch
kernels = kernels.unsqueeze(1)
print('Predicted')
conv_res = F.conv1d(inputs, kernels, padding=largest_kernel + 1, groups=inputs.size(1)).long()[:, :, :inputs.size(-1)]
for (true, ks), pred in zip(zip(inputs.squeeze().long().tolist(), (kernel_size1, kernel_size2, kernel_size3, kernel_size4, kernel_size5)), conv_res.squeeze().tolist()):
    pred_str = ''.join([str(x) for x in pred])
    print('P ({})'.format(len(pred)), pred_str, '({})'.format(pred_str.count('1')))

    one_idx = None
    if 1 in true:
        one_idx = true.index(1)
        for i in range(one_idx, min(one_idx + ks, len(true))):
            true[i] = 1
    true_str = ''.join([str(x) for x in true])
    print('E ({})'.format(len(true)), true_str, '({})'.format(true_str.count('1')))

    assert true_str == pred_str
    print()