Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

torch.aten.conv_tbc conv1d and conv3d #345

Closed
Tracked by #347 ...
renxida opened this issue Jan 11, 2024 · 4 comments
Closed
Tracked by #347 ...

torch.aten.conv_tbc conv1d and conv3d #345

renxida opened this issue Jan 11, 2024 · 4 comments
Assignees

Comments

@renxida
Copy link
Contributor

renxida commented Jan 11, 2024

No description provided.

@renxida
Copy link
Contributor Author

renxida commented Jan 11, 2024

Seems pretty straightforward. Just need to transpose the inputs.

According to this issue,

The input shape for nn.Conv1d is batch x channels x time (BCT), which would require a transpose since the rest of the network operates with time x batch x channel (TBC) tensors. conv_tbc takes time x batch x channel (TBC) input directly.

So this would be as simple as
TBC
(transpose 0 1)
BTC
(transpose 1 2)
BCT

@renxida
Copy link
Contributor Author

renxida commented Jan 12, 2024

From https://github.com/pytorch/pytorch/blob/5bc896e5dc856ca831a7f78fdda3b95b1cb8c631/torch/onnx/symbolic_opset9.py#L3605

@_onnx_symbolic("aten::conv_tbc")
@symbolic_helper.parse_args("v", "v", "v", "i")
@_beartype.beartype
def conv_tbc(g: jit_utils.GraphContext, input, weight, bias, pad):
    if symbolic_helper.is_caffe2_aten_fallback():
        return g.at("conv_tbc", input, weight, bias, pad_i=pad)
    else:
        # input must have 3 dimensions, see:
        # https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/ConvolutionTBC.cpp#L8-L10
        # input = (time, batch, in_channels)
        # weight = (kernel_width, in_channels, out_channels)
        # bias = (out_channels,)
        input = g.op("Transpose", input, perm_i=[1, 2, 0])
        weight = g.op("Transpose", weight, perm_i=[2, 1, 0])
        conv = conv1d(g, input, weight, bias, [1], [pad], [1], 1)
        return g.op("Transpose", conv, perm_i=[2, 0, 1])     

@renxida renxida self-assigned this Jan 12, 2024
@renxida renxida changed the title torch.aten.conv_tbc torch.aten.conv_tbc conv1d and conv3d Jan 19, 2024
@renxida
Copy link
Contributor Author

renxida commented Jan 19, 2024

It looks like to implement convtbc i need to implement conv1d, and conv3d seems pretty trivial to tack on.

@vivekkhandelwal1
Copy link
Contributor

Support added for these ops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants