torchrec icon indicating copy to clipboard operation
torchrec copied to clipboard

Fix dynamic embedding bugs that may lead to segmentation faults

Open sherlockkenan opened this issue 9 months ago • 3 comments

Hi TorchRec Team,

We've recently been trying to use the dynamic embedding feature in torchrec contrib, but we have encountered a few challenges. The process may result in a segmentation fault. After debugging, we've identified two potential problems.

1) fetch_notifications_ is not thread-safe. 2)Tensor data might be recycled during pushing operations.

For the first issue, the fetch_notifications_ variable is accessed in both the pull and sync fetch functions. As these functions are called in different threads, there might be a thread safety issue.

For the second issue, the tensor generated by concat in the push function is a temporary variable. The subsequent call to io.push is asynchronous and does not copy the data. Therefore, the data might have been recycled by the time it is executed asynchronously, leading to access to invalid data.

In light of these findings, we have undertaken some corrective measures to address these issues. We appreciate your attention to this Pull Request and eagerly await your valuable feedback.

Thank you for your time and consideration.

sherlockkenan avatar May 03 '24 12:05 sherlockkenan

Hi @sherlockkenan!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

facebook-github-bot avatar May 03 '24 12:05 facebook-github-bot

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

facebook-github-bot avatar May 03 '24 13:05 facebook-github-bot

Hi, I don't have expertise on dynamic embeddings, so probably will just cc @colin2328

also probably make an issue as well, since it is easier to track there

henrylhtsang avatar May 06 '24 17:05 henrylhtsang

sorry for the late response. I have created an issue here: https://github.com/pytorch/torchrec/issues/2006. I would appreciate any further suggestions regarding the pull request.

sherlockkenan avatar May 15 '24 04:05 sherlockkenan

@PaulZhang12 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar May 17 '24 20:05 facebook-github-bot

Please address CI failures and then you are good

PaulZhang12 avatar May 17 '24 20:05 PaulZhang12

Please address CI failures and then you are good

thanks! sorry for the failures and I've fixed them and pushed the changes to the merge request. However, it seems that the workflow requires approval again.

sherlockkenan avatar May 19 '24 15:05 sherlockkenan

CI looks good, previously flaky test. Feel free to merge!

PaulZhang12 avatar May 20 '24 16:05 PaulZhang12