fix: prevent dangling pointer in merged embedding buffer(#18410)#18987
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18987
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New Failures, 2 Unrelated FailuresAs of commit 158115b with merge base 490ec5c ( NEW FAILURES - The following jobs have failed:
BROKEN TRUNK - The following jobs failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Hi @fgsiveone! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
This PR needs a
|
| template <typename T> | ||
| struct TensorStruct { | ||
| std::unique_ptr<executorch::aten::TensorImpl> tensor; | ||
| std::shared_ptr<std::vector<T>> buffer; |
There was a problem hiding this comment.
Look great, thanks for the fix.
Nit: Do you think we can use unique_ptr to match the semantics of the tensor above?
Summary
Fix dangling pointer in TensorStruct merged embedding buffer.
The merged embedding data was stored in a local std::vector variable inside the function. When the function returned, the local vector was destroyed, leaving merged_embeddings.data as a dangling pointer to freed memory, causing invalid data when accessed in downstream inference stages.
Added a shared_ptr<vector> buffer field to TensorStruct to take ownership of the underlying data, extending the buffer lifetime to match the struct lifetime.
Test plan
Manually validated by running multimodal inference with the patched TensorStruct:
Confirmed merged_embeddings.data points to valid memory after function return
Verified inference output is correct and consistent across multiple runs
Previously observed invalid/garbage output in embedding data no longer reproduces
cc @cccclai @cbilgin @abhinaykukkadapu