-
Notifications
You must be signed in to change notification settings - Fork 633
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
Package libomp.so with torchaudio wheel for ROCm #3575
base: main
Are you sure you want to change the base?
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/audio/3575
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 11 PendingAs of commit e9f5c88 with merge base 6fb6854 (): This comment was automatically generated by Dr. CI and updates every 15 minutes. |
cc @atalman The above is an attempt to fix the binary import test failure for torchaudio |
@atalman This is part 1 of my proposed solution for fixing the torchaudio wheel issue with libomp.so. However, it will also need a part 2 fix in the yml file for building the wheel. Can you please take a look at the proposed solution in the PR description and let us know if it sounds okay? |
setup.py
Outdated
@@ -115,6 +115,12 @@ def _main(): | |||
with open("README.md") as f: | |||
long_description = f.read() | |||
|
|||
# ROCm build of torchaudio needs libomp.so to be packaged with the wheel | |||
# to avoid import-time error due to missing dependency | |||
if torch.hip is not None: |
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 will affect all builds not only rocm. Since this issue happens only on rocm can we implement this only for rocm builds ?
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.
Actually this should be torch.version.hip is not None
. That should ensure that this change is applied only to ROCm builds. Doest that sound good?
@pruthvistony, can you please make the changes as appropriate?
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.
Changes pushed. It should affect only ROCm builds now.
Is there a way to handle this in PyTorch core in abstracted manner, like how CUDA is handled? |
Since libomp.so is not a dependency for Pytorch, I didn't consider adding it to Pytorch wheels. I'll need @atalman to weigh in here if that's the route we should go. It'll probably remove any need for changes to torchaudio wheel recipe, since the torchaudio so should be able to pick up libomp.so from torch wheel install path in that case. |
if torch.version.hip is not None: | ||
import shutil | ||
|
||
shutil.copy("/opt/rocm/llvm/lib/libomp.so", "./torchaudio/lib/") |
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.
What is the test plan for this ?
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 a fix for the import of torchaudio using wheel, so in a way, we already have a test case for this, right?
@pruthvistony @jithunnair-amd for second part of the fix we should do it in torchaudio as well, via post script. Since this is audio only change we should not put it in test-infra : https://github.com/pytorch/test-infra/blob/65abc6ecc3afe43012e74bc45b824f6cd36c1eff/.github/workflows/build_wheels_linux.yml#L187 |
OpenMP is used by many different projects, so I'd be careful with shipping |
Problem:
#2485 introduced a build-time dependency on libomp.so for torchaudio, but when a torchaudio wheel built with that PR is imported in an environment where ROCm is NOT installed, it errors out e.g.:
https://github.com/pytorch/builder/actions/runs/5954772894/job/16152043224
Proposed solution:
PART 1:
We need to package the libomp.so library (that comes as part of ROCm installation) with the torchaudio wheel (similar to how we package ROCm libraries with torch wheel). This PR adds the libomp.so to the wheel packaging.
PART 2:
The above solution will be needed in conjunction with another fix in the wheel building yml file (this or this?) to set the RUNPATH for
libtorchaudio.so
so that it looks in its current directory ($ORIGIN
) for any dependencies. This is a technique already used in the PyTorch wheels here.However, I propose just adding
$ORIGIN
to the RUNPATH instead of replacing it, like we do in the PyTorch wheels (for minimal behavior change):This brings the following change in RUNPATH for libtorchaudio.so:
ldd shows the expected output: