-
Notifications
You must be signed in to change notification settings - Fork 360
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
fix/feat: Move convolution core to impl
+ add feature (FX converter refactor)
#1972
Conversation
5348ac2
to
075a028
Compare
impl
+ add feature (FX converter refactor)
# Process bias terms | ||
if isinstance(bias, torch.Tensor): | ||
# Transform the bias constant into a Numpy array | ||
bias = to_numpy(bias) | ||
|
||
elif isinstance(bias, TRTTensor): | ||
bias = get_trt_tensor(network, bias, f"{name}_bias") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did not add an unsqueeze operation to bias term since the requirement in TRT for the bias term is that it must have number of elements equal to the number of output features of the convolution, so the same bias as is used for Conv1D would work for Conv2D, with the number of output features being fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to clarify, you mean 1D or 2D conv? For 1D, we need bias to be unsqueezed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially meant for all conv layers since this documentation seems to indicate we just need the number of elements in the bias Tensor to the be correct, and not necessarily the dimensions, but if bias needs to be unsqueezed for 1D, I can add that functionality back. I am wondering if the intended unsqueeze should be in the first dimension (torch.unsqueeze(bias, 0)
) or the last dimension (torch.unsqueeze(bias, -1)
)?
Note: I think initially, it was torch.unsqueeze(bias, 0)
, while the weights and inputs were unsqueezed in the last dimension
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if TRT has done the broadcast internally since the unit test for 1D works good even though you did not unsqueeze it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I verified on a small sample that Conv1D with bias compiles + runs inference successfully without unsqueezing the bias term
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have a unit test for this just to catch if TRT behavior changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could add one, but it would likely be very similar to this case, which interprets, builds, and runs inference on a Conv1D model with TRT both with and without bias:
class TestConvolutionConverter(AccTestCase): | |
@parameterized.expand( | |
[ | |
("default", 1), | |
param("no_bias", 1, bias=False), | |
("tuple_parameters", 1, (1), (1)), | |
param("non_zero_padding", 1, padding=1), | |
param("dilation", 1, dilation=2), | |
param("groups", 1, groups=3), | |
] | |
) | |
def test_conv1d( | |
self, | |
_, | |
kernel_size, | |
stride=1, | |
padding=0, | |
dilation=1, | |
groups=1, | |
bias=True, | |
): | |
class TestModule(torch.nn.Module): | |
def __init__(self): | |
super().__init__() | |
self.conv = torch.nn.Conv1d( | |
3, 6, kernel_size, stride, padding, dilation, groups, bias | |
) | |
def forward(self, x): | |
return self.conv(x) | |
inputs = [torch.randn(1, 3, 32)] | |
self.run_test( | |
TestModule(), | |
inputs, | |
expected_ops={acc_ops.conv1d}, | |
test_explicit_precision=True, | |
) |
A breaking TRT change to that specific case should cause the accuracy check in the above test to fail.
e92034d
to
08d6c41
Compare
a6b5e6c
to
a21d778
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly organization stuff
# Process bias terms | ||
if isinstance(bias, torch.Tensor): | ||
# Transform the bias constant into a Numpy array | ||
bias = to_numpy(bias) | ||
|
||
elif isinstance(bias, TRTTensor): | ||
bias = get_trt_tensor(network, bias, f"{name}_bias") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have a unit test for this just to catch if TRT behavior changes?
a21d778
to
69e8d33
Compare
69e8d33
to
de9938e
Compare
de9938e
to
b7eea6f
Compare
b7eea6f
to
0f5be88
Compare
- Centralize convolution implementation in FX, similar across all source IRs, including aten, acc, nn - Enable pass-through of build errors in e2e tests to ensure errors are not being hidden - Allow conv layers to take bias inputs in FX, per new functionality from TRT - Remove separate `convolution.py` file and centralize `nn` converters to a single file
0f5be88
to
834064e
Compare
HI @wushirong - thank you for the review. I was wondering if you could have another look at the changes, as I've moved |
Description
convolution
implementation in FX across all source IR variants, including support forconv1d
, quantized, and other configurationsFixes #1954
Addresses first bug in #1565
Type of change
Checklist: