TrojanXu / onnxparser-trt-plugin-sample

A sample for onnxparser working with trt user defined plugins for TRT7.0
Apache License 2.0
166 stars 36 forks source link

The example cannot work when plugin to a large model #9

Closed hikaru-nara closed 3 years ago

hikaru-nara commented 3 years ago

When I use the method in this repo to export F.grid_sample in a large model, there is something wrong with the exported graph. The shapes of the inputs of GridSampler nodes are nonetype.

To reproduce

Change the model definition to (Note the +1 in the argument passed to F.grid_sample)

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

    def forward(self, input, grid):
        return F.grid_sample(input+1, grid, mode='bilinear', padding_mode='zeros', align_corners=True)

Then export the model, and print the nodeof op GridSampler with the following code.

def check_onnx(onnx_model_file):
    graph = gs.import_onnx(onnx.load(onnx_model_file))
    assert(graph is not None)
    for node in graph.nodes:
        if node.op == 'GridSampler':
            print(node)

And then the console prints

GridSampler_2 (GridSampler)
        Inputs: [Variable (3): (shape=None, dtype=None), Variable (grid): (shape=[1, 1, 128000, 2], dtype=float16)]
        Outputs: [Variable (4): (shape=[1, 17, 1, 128000], dtype=float16)]
Attributes: OrderedDict([('aligncorners', 1), ('interpolationmode', 0), ('paddingmode', 0)])

The desired behavior is that the shape and dtype of the input should not be None.

hikaru-nara commented 3 years ago

It is weird that adding that plus one cause the method to fail.... Am I doing anything wrong? Please, any hint will be appreciated.

hikaru-nara commented 3 years ago

It seems that it is ok even though the shapes are none. I've not tested but the engine has been built successfully. Close this one for the time being.

hikaru-nara commented 3 years ago

You just need to manually provide the shapes for modify_onnx().

jucic commented 3 years ago

You just need to manually provide the shapes for modify_onnx().

I encountered with the same problem, however, gridsampler is used many times with different input shape, so do you know any other solution for this issue, thanks ahead!