Problems with LAPACK on iOS

I’m trying to run my model on iOS and encounter a problem with LibTorch. The problem is in the call of SVD function.

The following code:

#import <torch/script.h>
#import <ATen/Functions.h>
at::Tensor tensor = torch::ones({3,3});
auto result = at::svd(tensor);

crushes with error as execution time:

svd: LAPACK library not found in compilation (apply_svd at /Users/distiller/project/aten/src/ATen/native/BatchLinearAlgebra.cpp:935)
(no backtrace available)

Any thoughts would be appreciated!


I am not very familiar with the iOS build system. Did you built libtorch from source yourself?

The error comes from the fact that there were no linear algebra library found at compile time and so linear algebra functions (svd, eig, etc) are not available.

Thanks for your reply! No, I’ve followed the tutorial

Interesting. I don’t see any good reason why the official binary was not compiled with Lapack…
Let’s wait for some mobile people to shed some light.

In the meantime. If you want, you can try to compile from source using the instructions from that link. And double check that during the compilation, your lapack library (the native apple one should be good) is properly detected and used.

Hi @kulikovv,

We didn’t compile LAPACK into our binary. However, since LAPCK is supported by the Accelerate.framework on iOS. You can manually enable it by following the steps below

  1. Add a compiler flag - CMAKE_ARGS+=("-DUSE_LAPACK=ON") in to tell cmake to compile LAPACK.
  2. Follow the tutorial to run the build script and setup your project
  3. Link Accelerate.framework to your project

Let me know if it works for you. Thanks.


Thanks! It solved my problem!

1 Like

Hi, I got the same problem in android platfrom, do you have any suggestions? really thanks!

, add the flag
CMAKE_ARGS+=("-DUSE_LAPACK=ON") , but I get the error like in the picture , it.s likes lack of LAPACK lib’s error. How I fix this error ? thanks ! :nauseated_face: I want to build IOS Pytorch lib , use the command : BUILD_PYTORCH_MOBILE=1 IOS_ARCH=arm64 ./scripts/

I got the similar error when I built for the android with LAPACK, PyTorch version 1.9.

@IvanKobzarev do you know the solution in Android?