rust-bert icon indicating copy to clipboard operation
rust-bert copied to clipboard

Failed to run custom build command for torch-sys v0.7.2

Open Raduc4 opened this issue 1 year ago • 6 comments

Hi, unfortunately I got this error Rustc 1.61.0 nightly Libtorch instalation: manual Libtorch version: v1.11.0 cxx11 abi + cu113 -> Using v.1.12.0+cpu from docs link I'm getting error: failed to run custom build command for torch-sys v0.7.2 Rust-bers version: 0.18 OS: Arch Linux

These errors appeared about 3 or 4 days ago when I updated my system. Before that moment I didn't have any problems.

Full Error Log V1.12.0+cpu Error Log

Strange is that when I add rust-bert to Cargo.toml - rust-analyzer stops working rust-analyzer 1.64.0-nightly (5342f47 2022-07-09)

Error: Rust-analyzer failed to run build scripts.

[ERROR rust_analyzer::lsp_utils] rust-analyzer failed to run build scripts

The following warnings were emitted during compilation:


error: failed to run custom build command for `torch-sys v0.7.2`

Caused by:
  process didn't exit successfully: `/home/r/projects/rust/stock-perception-api/target/debug/build/torch-sys-792fbc61b068f06b/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=TORCH_CUDA_VERSION
  cargo:rerun-if-env-changed=LIBTORCH
error occurred: Command "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "/home/r/libtorch/include" "-I" "/home/r/libtorch/include/torch/csrc/api/include" "-Wl,-rpath=/home/r/libtorch/lib" "-std=c++14" "-D_GLIBCXX_USE_CXX11_ABI=0" "-o" "/home/r/projects/rust/stock-perception-api/target/debug/build/torch-sys-b8f6d3441bb83c77/out/libtch/torch_api.o" "-c" "libtch/torch_api.cpp" with args "c++" did not execute successfully (status code exit status: 1).

Error v1.11.0 cxx11 abi + cu113:

 Compiling cached-path v0.5.3
   Compiling tch v0.7.2
   Compiling rust-bert v0.18.0
   Compiling berd v0.1.0 (/home/r/projects/rust/berd)
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "/tmp/rustcLM2cDQ/symbols.o" "/home/r/projects/rust/berd/target/debug/deps/berd-6b6377244c895707.157iewas35ll61dk.rcgu.o" ... random error
  /usr/bin/ld: /home/r/libtorch/lib/libtorch_cuda_cu.so: undefined reference to `at::native::copy_ignoring_overlaps(at::Tensor const&, at::Tensor const&)'
          /usr/bin/ld: /home/r/libtorch/lib/libtorch_cuda_cu.so: undefined reference to `at::native::clamp_max_out(at::Tensor const&, c10::Scalar const&, at::Tensor&)'
          collect2: error: ld returned 1 exit status
          
  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `berd` due to previous error

Raduc4 avatar Jul 19 '22 17:07 Raduc4

Hello @Raduc4 ,

The current released version (1.18) requires libtorch v1.11. If pulling the code directly from this repository libtorch 1.12 is required (this is because of the different dependencies for tch).

Can you please ensure you download the cxx11 ABI for linux with either CPU or CUDA and point to that local installation when building the library: CPU version / CUDA version?

I would recommend deleting your target repository (or run cargo clean) to force a clean installation.

guillaume-be avatar Jul 24 '22 08:07 guillaume-be

Hi, @guillaume-be Thank you for the reply. Unfortunately I'm still getting the error

env | grep -e LIBTORCH -e LD_LIBRARY_PATH
                                                                                   
LD_LIBRARY_PATH=/home/r/libtorch/lib
LIBTORCH=/home/r/libtorch

I've tried with CPU version, the same happens also with CUDA version rust-bert v 0.18.0

Also got the error Full log here

 Compiling berd v0.1.0 (/home/r/projects/rust/berd)
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "/tmp/rustceJiECu/symbols.o" "/home/r/projects/rust/berd/target/debug/deps/berd-... 

-------------------------------------------------------big error

          /usr/bin/ld: /home/r/libtorch/lib/libtorch_cuda_cu.so: undefined reference to `c10::MessageLogger::MessageLogger(char const*, int, int)'
          /usr/bin/ld: /home/r/libtorch/lib/libtorch_cuda_cu.so: undefined reference to `at::native::DispatchStubImpl::get_call_ptr(c10::DeviceType, void*, void*)'
          collect2: error: ld returned 1 exit status
          
  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `berd` due to previous error

Running cargo run --verbose Full error log

   Compiling berd v0.1.0 (/home/r/projects/rust/berd)
     Running `rustc --crate-name berd --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=26a83bcf0ed1dc23 -C extra-filename=-26a83bcf0ed1dc23 --out-dir /home/r/projects/rust/berd/target/debug/deps -C incremental=/home/r/projects/rust/berd/target/debug/incremental -L dependency=/home/r/projects/rust/berd/target/debug/deps --extern rust_bert=/home/r/projects/rust/berd/target/debug/deps/librust_bert-cffdf2fd615aa953.rlib -L native=/usr/lib -L native=/home/r/libtorch/lib -L native=/home/r/projects/rust/berd/target/debug/build/torch-sys-da5158f2c0f027d9/out`
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" 
-----------------------long error

          collect2: error: ld returned 1 exit status
          
  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `berd` due to previous error

Caused by:
  process didn't exit successfully: `rustc --crate-name berd --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=26a83bcf0ed1dc23 -C extra-filename=-26a83bcf0ed1dc23 --out-dir /home/r/projects/rust/berd/target/debug/deps -C incremental=/home/r/projects/rust/berd/target/debug/incremental -L dependency=/home/r/projects/rust/berd/target/debug/deps --extern rust_bert=/home/r/projects/rust/berd/target/debug/deps/librust_bert-cffdf2fd615aa953.rlib -L native=/usr/lib -L native=/home/r/libtorch/lib -L native=/home/r/projects/rust/berd/target/debug/build/torch-sys-da5158f2c0f027d9/out` (exit status: 1)

Raduc4 avatar Jul 24 '22 09:07 Raduc4

Hi @Raduc4 working perfectly if i dont set the env for libtorch. Seems it is downloading in the background and configured as per the requirement.

vimal-quilt avatar Jul 25 '22 10:07 vimal-quilt

It compiles well if I don't import anything from the library.

Compiling torch-sys v0.7.2
 Compiling tch v0.7.2
 Compiling rust-bert v0.18.0
   Compiling ai2 v0.1.0 (/home/r/projects/rust/ai2)
    Finished dev [unoptimized + debuginfo] target(s) in 1m 18s
     Running `target/debug/ai2`
Hello, world!

If I import something from the library It doesn't compile at all, Here is the error from the example below

use rust_bert::pipelines::question_answering::{QaInput, QuestionAnsweringModel};    
fn main() {    
    println!("Hello, world!");    
}    

Raduc4 avatar Jul 31 '22 03:07 Raduc4

Hello @Raduc4 ,

These errors are caused because the tch dependency fails to link the libtorch installation. I am not able to reproduce the error, maybe you will be able to find more help directly at https://github.com/LaurentMazare/tch-rs?

guillaume-be avatar Jul 31 '22 15:07 guillaume-be

It seems that there are some incompatibilities with cpp on arch linux, I changed on fedora. It worked well without downloading lib-torch and ENV vars

Raduc4 avatar Aug 13 '22 11:08 Raduc4

@Raduc4 glad you found a workaround, it would still be great to have the library working on all linux platforms. I am closing this issue as it is more related to tch-rs and an issue was created on the project page.

guillaume-be avatar Nov 26 '22 08:11 guillaume-be