tensil-ai / tensil

Open source machine learning accelerators
https://www.tensil.ai
Other
348 stars 28 forks source link

Fix ONNX frontend Reshape behavior #45

Closed trulyspinach closed 2 years ago

trulyspinach commented 2 years ago

When performing a 1D to 4D reshape, the current implementation directly perform an in order remap which leads to an unexpected transpose from NCHW(1D) to NHWC thus make the accelerator outputs different result from other ONNX inference engine.

This can be easily reproduced with the following ONNX model: reshaper.onnx.zip

Screen Shot 2022-04-23 at 9 48 29 PM

Generated with the following PyTorch code:

class Reshaper(nn.Module):
    def __init__(self):
        super(Reshaper, self).__init__()

        self.conv1 = nn.Conv2d(2, 2, 3, stride=1, padding=0)
        self.up = nn.Upsample(scale_factor=2, mode='bilinear', align_corners=False)

    def forward(self, z):
        out = z
        out = z.reshape(z.shape[0], 2,2,2)
        # out = self.up(out)
        return out
CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.

petrohi commented 2 years ago

Also I did fix our CI to include forks. I took the liberty of merging main into your branch to force the CI. It's green now!

trulyspinach commented 2 years ago

@petrohi Thanks! I've updated the format and added a test case that checks for the output. Could you push the model file here into tensil-models so the CI can pass? reshape_1d_4d.onnx.zip

petrohi commented 2 years ago

I added test model to tensil-models.

tdb-alcorn commented 2 years ago

Thanks for the contribution @trulyspinach! :fire: