Tensor Allocation Order Bug in TensorRT Int8 #65019
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Category
Inference
PR Types
Bug fixes
Description
The provided C++ code snippet contains a bug related to tensor allocation:
temp_tensor
is pushed intodata_tensors_
usingdata_tensors_.push_back(temp_tensor);
, the tensor’s memory is not yet allocated. TheResize
function only changes the tensor's shape without allocating memory.mutable_data
is called (see PaddlePaddle's source code).data_buffers_
is set to point totemp_tensor.mutable_data<int16_t>(place)
, but since the tensor indata_tensors_
has no allocated memory, it leads to an invalid memory reference.temp_tensor
deallocates, leavingdata_tensors_
with an invalid pointer.With a stream-safe allocator, this bug is not immediately apparent because the allocator does not trigger
cudaFree
immediately. However, with an async allocator, the bug is detected due to stricter memory management.To fix this bug, reorder the operations to allocate memory before pushing the tensor into
data_tensors_