Need help on building torch_xla 2.3 from source
❓ Questions and Help
we were able to build torch_xla 2.1 from source (along with pytorch), but since 2.3 release, the setup doesn't work anymore. I wonder if someone has seen this issue before.
ERROR: /home/thonle/tmp/tmp.W8H3G8ZvuS.pytorch/xla/BUILD:6:10: Linking _XLAC.so failed: (Exit 1): crosstool_wrapper_driver_is_not_gcc failed: error executing command (from target //:_XLAC.so) external/local_config_cuda/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc @bazel-out/k8-opt/bin/_XLAC.so-2.params
lto1: fatal error: bytecode stream in file ‘/apcv/shared/conda-envs/ai-2799/lib/python3.11/config-3.11-x86_64-linux-gnu/libpython3.11.a’ generated with LTO version 12.0 instead of the expected 11.3
compilation terminated.
lto-wrapper: fatal error: /usr/bin/gcc returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
Target //:_XLAC.so failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 907.035s, Critical Path: 273.22s
INFO: 24303 processes: 15420 internal, 8883 local.
FAILED: Build did NOT complete successfully
error: command '/home/thonle/bin/bazel' failed with exit code 1
Our setup of building torch_xla:
- build pytorch 2.3 from source
git clone --recursive https://github.com/pytorch/pytorch.git -b v2.3.0 --depth=1 --single-branch <dir>
CMAKE_PREFIX_PATH=${CONDA_PREFIX} \
CMAKE_C_FLAGS="-ffile-prefix-map=${DIR}=." \
CMAKE_CXX_FLAGS="-ffile-prefix-map=${DIR}=." \
CUDA_ROOT=/cm/shared/apps/cuda12.2/toolkit/current \
CUDA_HOME=/cm/shared/apps/cuda12.2/toolkit/current \
CUDNN_LIB_DIR=/cm/shared/apps/cudnn8.9-cuda12.2/8.9.4.25/lib \
CUDNN_INCLUDE_DIR=/cm/shared/apps/cudnn8.9-cuda12.2/8.9.4.25/include \
MAX_JOBS=36 \
USE_MKLDNN=0 \
USE_BREAKPAD=0 \
BUILD_TEST=0 \
USE_FBGEMM=0 \
BUILD_CAFFE2=0 \
BUILD_CAFFE2_OPS=0 \
USE_SYSTEM_NCCL=0 \
USE_XNNPACK=0 \
python setup.py build
- build torch_xla 2.3 from source,
git clone --recursive https://github.com/pytorch/xla.git
git checkout v2.3.0
CMAKE_PREFIX_PATH=${CONDA_PREFIX} \
CMAKE_C_FLAGS="-ffile-prefix-map=${DIR}/xla=." \
CMAKE_CXX_FLAGS="-ffile-prefix-map=${DIR}/xla=." \
CUDNN_INSTALL_PATH=/cm/shared/apps/cudnn8.9-cuda12.2/8.9.4.25 \
TF_CUDA_PATHS=/cm/shared/apps/cuda12.2/toolkit/12.2.2 \
TF_CUDNN_VERSION=8.9 \
TF_CUDA_VERSION=12.2 \
TF_CUDA_COMPUTE_CAPABILITIES="6.1,7.0,8.0,8.6,9.0" \
XLA_CUDA=1 \
TORCH_XLA_VERSION=${WHL_NAME} \
VERSIONED_XLA_BUILD=0 \
python setup.py bdist_wheel
@JackCaoG really appreciate if someone could help us on this, thanks
Hi @thong3le, thanks for trying out building PyTorch/XLA from source!
Here is a guide on how to build PyTorch/XLA from source, in which you will build in a docker container. As is mentioned in the guide, alternatively, you can also start a dev container in VS code, IMO that brings a better dev experience than using bare docker container (IMO).
Back to the original building failure in the post, I haven't seen such error before, it seems like an error on the lto1 version in the env. I found a possible related issue here.
If you installed all dependencies that are required for building PyTorch, there shouldn't be additional dependencies to build PyTorch/XLA. And CMAKE_PREFIX_PATH is not needed to build locally now. After building PyTorch from source, PyTorch/XLA can be built just with python setup.py develop.
Hope this help!
thanks for helping @lsy323, testing on docker container works, however, we don't support docker in production. We need to find a way to build from source without docker.
Still not able to build it with your suggestions, let me know if you have any other ideas. Thanks.
after simplify our env, we ran into
[2/33351]
run_gen_lazy_tensor(
File "/home/rol/.local/lib/python3.11/site-packages/torchgen/gen_lazy_tensor.py", line 358, in run_gen_lazy_tensor parsed_yaml = parse_native_yaml(native_yaml_path, tags_yaml_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rol/.local/lib/python3.11/site-packages/torchgen/gen.py", line 241, in parse_native_yaml
_GLOBAL_PARSE_NATIVE_YAML_CACHE[path] = parse_native_yaml_struct(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rol/.local/lib/python3.11/site-packages/torchgen/gen.py", line 163, in parse_native_yaml_struct
func, m = NativeFunction.from_yaml(e, loc, valid_tags, ignore_keys)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rol/.local/lib/python3.11/site-packages/torchgen/model.py", line 667, in from_yaml
dispatch_key = DispatchKey.parse(k.strip())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rol/.local/lib/python3.11/site-packages/torchgen/model.py", line 205, in parse
raise AssertionError(f"unknown dispatch key {value}")
AssertionError: unknown dispatch key SparseCsrMeta
in bazel-out/k8-opt-exec-50AE0418/bin/codegen/lazy_tensor_generator.runfiles/torch/aten/src/ATen/native/native_functions.yaml:2365:
empty.memory_format(SymInt[] size, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None, MemoryFormat? memory_format=None) -> Tensor
Target //:_XLAC.so failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: /home/rol/tmp/tmp.mqwA3dmjy8.torch_xla/xla/torch_xla/csrc/BUILD:31:17 Middleman _middlemen/_S_Storch_Uxla_Scsrc_Ctensor-cc_library-compile failed: (Exit 1): bash failed: error executing command (from targe
Have you seen this before?
AssertionError: unknown dispatch key SparseCsrMeta
what;s your pytorch version? it should match the pytorch/xla one.
@JackCaoG it is 2.3, we use this commit (with some internal patches on top) https://github.com/pytorch/pytorch/commit/97ff6cfd9c86c5c09d7ce775ab64ec5c99230f5d
Hmm I spot something weird
File "/home/rol/.local/lib/python3.11/site-packages/torchgen/gen_lazy_tensor.py", line 358, in run_gen_lazy_tensor del.py", line 205, in parse
your torch gen is under the system dir instead of the local dir, for example, if I do
Python 3.10.14 (main, Mar 25 2024, 21:57:21) [GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torchgen
>>> torchgen.__file__
'/workspaces/dk3/pytorch/torchgen/__init__.py'
Did you try to build both pytorch and pytorch/xla? or you pip install the torch and then try to build pytorch/xla? We usually build them sequentially and put torch_xla in the torch dir like this /workspaces/dk3/pytorch/xla.
thanks @JackCaoG, you're right, I have some local torch version installed during the build. After fixing that, it works now!