Open mhsmith opened 1 year ago
You don't need to build, torch, chaquopy-openblas or chaquopy-libgfortran yourself, because they're already available in the public repository. I haven't looked at the torchaudio build, but it might not even need any of those packages at build time, in which case you don't need to to list them as requirements in the torchaudio meta.yaml file.
If you do need any of them at build time, it'll probably only be torch, in which case you can download its wheels from the repository into your server/pypi/dist
directory before trying to build torchaudio.
A couple more notes:
So I downloaded the wheel files for torch and tried to compile torchaudio. It fails with the following log: torchaudio output.txt
I changed the version I'm trying to compile from torchaudio 0.13.1
to torchaudio 0.4.0
as that is the version that aligns with the older version of torch 1.4
It looks like the issue occurs at line 8 in the setup.py
from torch.utils.cpp_extension import BuildExtension, CppExtension
The error it creates:
Running command python setup.py egg_info
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/flame/chaquopy/server/pypi/packages/torchaudio/build/0.4.0/cp38-cp38-android_21_x86_64/src/setup.py", line 8, in <module>
from torch.utils.cpp_extension import BuildExtension, CppExtension
File "/home/flame/chaquopy/server/pypi/packages/torchaudio/build/0.4.0/cp38-cp38-android_21_x86_64/requirements/torch/__init__.py", line 81, in <module>
from torch._C import *
ImportError: /lib/x86_64-linux-gnu/libm.so: invalid ELF header
The error also seems to change if I try targeting arm64-v8a
instead of x86_64
I changed the version I'm trying to compile from
torchaudio 0.13.1
totorchaudio 0.4.0
as that is the version that aligns with the older version oftorch 1.4
If you look at the repository again, you'll see it also contains a newer version of torch: 1.8.1. So I suggest you build whatever version of torchaudio corresponds to that instead.
For this particular error, it looks like the existing patch for torchvision will be a useful guide.
So I've updated to torch 1.8.1
and torchaudio 0.8.1
, and I attempted to patch the problem area with the following:
diff --git a/build_tools/setup_helpers/extension.py b/build_tools/setup_helpers/extension.py
index 3d3cb6d0..1a180633 100644
--- a/build_tools/setup_helpers/extension.py
+++ b/build_tools/setup_helpers/extension.py
@@ -6,7 +6,9 @@ import distutils.sysconfig
from setuptools import Extension
from setuptools.command.build_ext import build_ext
-import torch
+#import torch
+# Chaquopy: disabling torch import
+import os.path as _osp
__all__ = [
'get_ext_modules',
@@ -63,7 +65,7 @@ class CMakeBuild(build_ext):
cmake_args = [
f"-DCMAKE_BUILD_TYPE={cfg}",
- f"-DCMAKE_PREFIX_PATH={torch.utils.cmake_prefix_path}",
+ f"-DCMAKE_PREFIX_PATH={_osp.join(_osp.dirname(_osp.dirname(_osp.dirname(_osp.dirname(__file__)))), 'requirements', 'torch', 'share', 'cmake')}",
f"-DCMAKE_INSTALL_PREFIX={extdir}",
'-DCMAKE_VERBOSE_MAKEFILE=ON',
f"-DPython_INCLUDE_DIR={distutils.sysconfig.get_python_inc()}",
I looked at what the actual call to torch.utils.cmake_prefix_path
was doing and just inlined it. Once I did that I no longer had errors around the python script, but now get errors around CMake.
I tried this myself this morning and got as far as you did @flamewave000
I get a different error though, something that seems related to torch
:
@flamewave000: Your error is:
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
You should be able to fix that by installing the ninja
tool, e.g. its Debian package name is ninja-build
.
@BeMain: Your error is:
CMake Error at /home/agardh/Development/chaquopy/server/pypi/packages/torchaudio/build/0.8.1/cp38-cp38-android_21_armeabi_v7a/requirements/torch/share/cmake/Caffe2/Caffe2Targets.cmake:115 (message):
The imported target "c10" references the file
"/home/agardh/Development/chaquopy/server/pypi/packages/torchaudio/build/0.8.1/cp38-cp38-android_21_armeabi_v7a/requirements/torch/lib/libc10.so"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/home/agardh/Development/chaquopy/server/pypi/packages/torchaudio/build/0.8.1/cp38-cp38-android_21_armeabi_v7a/requirements/torch/share/cmake/Caffe2/Caffe2Targets.cmake"
but not all the files it references.
Call Stack (most recent call first):
/home/agardh/Development/chaquopy/server/pypi/packages/torchaudio/build/0.8.1/cp38-cp38-android_21_armeabi_v7a/requirements/torch/share/cmake/Caffe2/Caffe2Config.cmake:116 (include)
/home/agardh/Development/chaquopy/server/pypi/packages/torchaudio/build/0.8.1/cp38-cp38-android_21_armeabi_v7a/requirements/torch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
CMakeLists.txt:55 (find_package)
I can reproduce this myself as well. The actual location of libc10.so is requirements/chaquopy/lib/libc10.so
. It was moved there by the package_data
patch in torch/patches/chaquopy.patch
, but the CMake file wasn't updated to match. I guess this didn't affect torchvision because it used CMake in a different way.
It may be possible to work around this by patching Caffe2Targets.cmake to give the correct location, but it's been a long time since I looked at this area, so I can't give any more detailed advice.
I'm guessing I will have to build torch
myself then, to apply the patch?
When trying to build torch
I get the following error:
ninja: error: '/bin/mkrename', needed by 'include/sleef.h', missing and no known rule to make it
Note: I downloaded the required wheels for chaquopy-openblas
and numpy
from https://chaquo.com/pypi-7.0/
Making this change while building torch itself will lead to many more complications, so I suggest you first try this:
--no-build
, to extract the requirements.torchaudio/build/.../requirements
directory as necessary.--no-reqs
to prevent your edits from being overwritten.
The discussion below is about building torchaudio using the Chaquopy package build tool. Since we currently only have torch available for Python 3.8, torchaudio will have to be built for the same version.
If you'd like to try building this package yourself, please read the existing discussion and then follow the instructions here. And if you're successful, please make a pull request so we can add the package to the public repository.
If anyone else wants this package too, let us know by clicking the thumbs-up button below.
Originally posted by @flamewave000 in https://github.com/chaquo/chaquopy/issues/773#issuecomment-1432689612
So I've gone through and tried to further but it seems that the
chaquopy-libgfortran
package is failing. The current dependency tree is as follows:demucs > torchaudio > torch > chaquopy-openblas > chaquopy-libgfortran
.The packages did not contain a version for
torchaudio
so I added it in the same way aslameenc
. I installedgfortran
but I've run into a couple of issues. Below are the steps I've taken so far.export FC="/usr/bin/gfortran" && export CC="/usr/bin/gcc"
sed -E 's/^GNU Fortran \(.*\) ([0-9]+(\.[0-9])+).*/\1/')
libgfortran.so.3
but that file and path do not exist. I changed the line tocp /usr/lib*/*/libgfortran.so.5 $PREFIX/lib
chaquopy_libgfortran-12.2.0-0-py3-none-android_21_x86.whl
todist/chaquopy-libgfortran
.chaquopy-openblas
requirement tochaquopy-libgfortran 12.2.0
chaquopy-openblas
At that point all hell breaks loose in the terminal. It seems like it gets into an infinite loop and then ending with the following error:
@BeMain were you able to get further than I did tonight?