-
Notifications
You must be signed in to change notification settings - Fork 381
Empty tensor handling #3891
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
base: main
Are you sure you want to change the base?
Empty tensor handling #3891
Conversation
87ebaf5 to
547022d
Compare
547022d to
5d9d5fc
Compare
narendasan
left a comment
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.
@apbose this maybe be a case where we would want TRT to properly handle this rather than us doing something hacky. Lets raise it with Yuan Yuo. Dummy inputs do not feel like the right solution
core/runtime/execute_engine.cpp
Outdated
| auto shape = core::util::toVec(dims); | ||
| LOG_DEBUG("Input Name: " << name << " Shape: " << dims); | ||
|
|
||
| void* tensor_addr = nullptr; |
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 strongly want to avoid having nullptr basically anywhere, we should be looking for some sane default
47be81b to
f411fd1
Compare
narendasan
left a comment
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.
Its looking good, please add a testcase then should be good to merge
| # FX converters (legacy, stored as single function) | ||
| # Skip FX if dynamo converter exists but failed validation | ||
| # This ensures validator decisions are respected | ||
| if dynamo_converter_failed_validation: |
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.
Why is this needed for empty tensor handling? Also are we near the point we can just remove FX converters?
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.
This is particularly for the case where x is torch.Tensor([]), and y is torch.Tensor torch.randn(3,4) where the validator comes into play.
# makes use of validator
class ConcatEmptyModelEmptyConstantMisMatchDim(nn.Module):
def __init__(self, dim=0):
super().__init__()
self.dim = dim
def forward(self, x):
y = torch.tensor([], device="cuda")
return torch.cat([x, y], dim=self.dim)
This error comes -
"/code/torchTRT/TensorRT/py/torch_tensorrt/fx/converters/aten_ops_converters.py", line 465, in aten_ops_cat
return acc_ops_converters.acc_ops_cat(network, target, None, kwargs_new, name)
acc_ops converter is called since validator fails and it resorts to the fx converter implementation which is next in precedence. Yes we should remove the converters IMO, but till that is not done, this would be required I suppose?
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.
Also for the test case, class TestEmptyTensorMemoryLeak(TestCase): should cover the case of no memory leak or memory overload in case of repeated model calls. Let me know if you think any other test case is required
a61974f to
2090079
Compare
…or in add_constant TRT layer, not allowing obsolete FX converters to take over if converter validation fails
…m_numel from fx to dynamo converters
2090079 to
149514a
Compare
This PR addresses the case of empty tensor in torchTRT based on https://docs.nvidia.com/deeplearning/tensorrt/latest/inference-library/advanced.html#empty-tensors, and also focuses on concat operation edge case involving empty tensor
TODO: Might have to separate the case of concat from this PR, in the case when torch.Tensor([]) and a rank greater tensor are concatenated, which is a valid case in pytorch but not TRT.
This addressed #3865. Corresponding HF transformers issue raised - huggingface/transformers#42027 where empty tensor should not come in the first place