Repository: pytorch
Issue: Building PyTorch from Source with BUILD_LAZY_TS_BACKEND_ON
Labels: module: build,triaged

### 🐛 Describe the bug

BUILD_LAZY_TS_BACKEND ON
```
FAILED: bin/test_lazy 
: && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -Xpreprocessor -fopenmp -I/usr/local/include -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOCUPTI -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-range-loop-analysis -Wno-pass-failed -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -Wno-invalid-partial-specialization -Wno-typedef-redefinition -Wno-unknown-warning-option -Wno-unused-private-field -Wno-inconsistent-missing-override -Wno-aligned-allocation-unavailable -Wno-c++14-extensions -Wno-constexpr-not-const -Wno-missing-braces -Qunused-arguments -fcolor-diagnostics -fno-math-errno -fno-trapping-math -Werror=format -Werror=cast-function-type -DUSE_MPS -fno-objc-arc -Wno-unused-private-field -Wno-missing-braces -Wno-c++14-extensions -Wno-constexpr-not-const -DHAVE_AVX512_CPU_DEFINITION -DHAVE_AVX2_CPU_DEFINITION -O3 -DNDEBUG -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -mmacosx-version-min=10.9 -Wl,-search_paths_first -Wl,-headerpad_max_install_names -rdynamic test_lazy/CMakeFiles/test_lazy.dir/__/common/main.cpp.o test_lazy/CMakeFiles/test_lazy.dir/test_backend_device.cpp.o test_lazy/CMakeFiles/test_lazy.dir/test_cache.cpp.o test_lazy/CMakeFiles/test_lazy.dir/test_ir.cpp.o test_lazy/CMakeFiles/test_lazy.dir/test_ir_util.cpp.o test_lazy/CMakeFiles/test_lazy.dir/test_misc.cpp.o test_lazy/CMakeFiles/test_lazy.dir/test_permutation_util.cpp.o test_lazy/CMakeFiles/test_lazy.dir/test_shape.cpp.o test_lazy/CMakeFiles/test_lazy.dir/test_symbolic_shape.cpp.o test_lazy/CMakeFiles/test_lazy.dir/test_trie_cache.cpp.o test_lazy/CMakeFiles/test_lazy.dir/test_util.cpp.o -o bin/test_lazy  -Wl,-rpath,/Users/davidlaxer/pytorch/build/lib -Wl,-rpath,/Users/davidlaxer/anaconda3/envs/AI-feynman/lib  lib/libtorch.dylib  lib/libgtest.a  lib/libtorch_cpu.dylib  /Users/davidlaxer/protobuf/src/.libs/libprotobuf.dylib  lib/libc10.dylib  /Users/davidlaxer/anaconda3/envs/AI-feynman/lib/libmkl_intel_lp64.dylib  /Users/davidlaxer/anaconda3/envs/AI-feynman/lib/libmkl_intel_thread.dylib  /Users/davidlaxer/anaconda3/envs/AI-feynman/lib/libmkl_core.dylib  /Users/davidlaxer/anaconda3/envs/AI-feynman/lib/libiomp5.dylib  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/lib/libpthread.tbd  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/lib/libm.tbd && :
ld: warning: dylib (/Users/davidlaxer/protobuf/src/.libs/libprotobuf.dylib) was built for newer macOS version (12.0) than being linked (10.9)
ld: warning: dylib (/Users/davidlaxer/anaconda3/envs/AI-feynman/lib/libmkl_intel_lp64.dylib) was built for newer macOS version (10.14) than being linked (10.9)
ld: warning: dylib (/Users/davidlaxer/anaconda3/envs/AI-feynman/lib/libmkl_intel_thread.dylib) was built for newer macOS version (10.14) than being linked (10.9)
ld: warning: dylib (/Users/davidlaxer/anaconda3/envs/AI-feynman/lib/libmkl_core.dylib) was built for newer macOS version (10.14) than being linked (10.9)
ld: warning: dylib (/Users/davidlaxer/anaconda3/envs/AI-feynman/lib/libiomp5.dylib) was built for newer macOS version (10.11) than being linked (10.9)
Undefined symbols for architecture x86_64:
  "torch::lazy::GetTSBackendImpl()", referenced from:
      __GLOBAL__sub_I_test_symbolic_shape.cpp in test_symbolic_shape.cpp.o
  "torch::lazy::TsNode::TsNode(torch::lazy::OpKind, torch::lazy::Shape, unsigned long, torch::lazy::hash_t)", referenced from:
      std::__1::shared_ptr<torch::lazy::Node> torch::lazy::MakeNode<torch::lazy::TsNode, torch::lazy::OpKind, torch::lazy::Shape, int, torch::lazy::hash_t const&>(torch::lazy::OpKind&&, torch::lazy::Shape&&, int&&, torch::lazy::hash_t const&) in test_ir.cpp.o
  "torch::lazy::TsNode::TsNode(torch::lazy::OpKind, torch::lazy::Shape, unsigned long, torch::lazy::hash_t)", referenced from:
      torch::lazy::CacheNodeWithShape::CacheNodeWithShape(torch::lazy::Shape const&) in test_cache.cpp.o
  "torch::lazy::SizeAdd::SizeAdd(torch::lazy::Value, torch::lazy::Value)", referenced from:
      std::__1::shared_ptr<torch::lazy::Node> torch::lazy::MakeNode<torch::lazy::SizeAdd, torch::lazy::Value, torch::lazy::Value>(torch::lazy::Value&&, torch::lazy::Value&&) in test_ir.cpp.o
  "torch::lazy::SizeMul::SizeMul(torch::lazy::Value, torch::lazy::Value)", referenced from:
      std::__1::shared_ptr<torch::lazy::Node> torch::lazy::MakeNode<torch::lazy::SizeMul, torch::lazy::Value, torch::lazy::Value>(torch::lazy::Value&&, torch::lazy::Value&&) in test_ir.cpp.o
  "torch::lazy::SizeNode::SizeNode(torch::lazy::Value, unsigned long)", referenced from:
      std::__1::shared_ptr<torch::lazy::Node> torch::lazy::MakeNode<torch::lazy::SizeNode, torch::lazy::Value, int>(torch::lazy::Value&&, int&&) in test_ir.cpp.o
  "torch::lazy::TsNode::hash() const", referenced from:
      vtable for torch::lazy::CacheNodeWithShape in test_cache.cpp.o
  "torch::lazy::TsNode::Lower(std::__1::shared_ptr<torch::jit::GraphFunction>, torch::lazy::TSLoweringContext*) const", referenced from:
      vtable for torch::lazy::CacheNodeWithShape in test_cache.cpp.o
  "torch::lazy::TsNode::shapeHash() const", referenced from:
      vtable for torch::lazy::CacheNodeWithShape in test_cache.cpp.o
  "typeinfo for torch::lazy::TsNode", referenced from:
      typeinfo for torch::lazy::CacheNodeWithShape in test_cache.cpp.o
      torch::lazy::IrTest_TsNodeTest_Test::TestBody() in test_ir.cpp.o
  "typeinfo for torch::lazy::SizeAdd", referenced from:
      torch::lazy::IrTest_DimensionNodeTest_Test::TestBody() in test_ir.cpp.o
  "typeinfo for torch::lazy::SizeMul", referenced from:
      torch::lazy::IrTest_DimensionNodeTest_Test::TestBody() in test_ir.cpp.o
  "typeinfo for torch::lazy::SizeNode", referenced from:
      torch::lazy::IrTest_DimensionNodeTest_Test::TestBody() in test_ir.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

```

### Versions

```
% python collect_env.py
Collecting environment information...
PyTorch version: N/A
Is debug build: N/A
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: N/A

OS: macOS 12.4 (x86_64)
GCC version: Could not collect
Clang version: 13.1.6 (clang-1316.0.21.2.5)
CMake version: version 3.22.4
Libc version: N/A

Python version: 3.8.13 (default, Mar 28 2022, 06:16:26)  [Clang 12.0.0 ] (64-bit runtime)
Python platform: macOS-10.16-x86_64-i386-64bit
Is CUDA available: N/A
CUDA runtime version: Could not collect
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: N/A

Versions of relevant libraries:
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.22.3
[pip3] numpydoc==1.2
[pip3] pytorch-lightning==1.6.3
[pip3] pytorch-transformers==1.1.0
[pip3] torch==1.13.0a0+gitcbdb694
[pip3] torchmetrics==0.8.2
[pip3] torchtext==0.12.0
[pip3] torchvision==0.13.0.dev20220517
[conda] blas                      1.0                         mkl    anaconda
[conda] libblas                   3.9.0              12_osx64_mkl    conda-forge
[conda] libcblas                  3.9.0              12_osx64_mkl    conda-forge
[conda] liblapack                 3.9.0              12_osx64_mkl    conda-forge
[conda] liblapacke                3.9.0              12_osx64_mkl    conda-forge
[conda] mkl                       2021.4.0           hecd8cb5_637    anaconda
[conda] mkl-include               2022.0.0           hecd8cb5_105    anaconda
[conda] mkl-service               2.4.0            py38h9ed2024_0    anaconda
[conda] mkl_fft                   1.3.1            py38h4ab4a9b_0    anaconda
[conda] mkl_random                1.2.2            py38hb2f4e1b_0    anaconda
[conda] numpy                     1.22.3                   pypi_0    pypi
[conda] numpy-base                1.21.5           py38h3b1a694_2    anaconda
[conda] numpydoc                  1.2                pyhd3eb1b0_0    anaconda
[conda] pytorch                   1.11.0                  py3.8_0    pytorch
[conda] pytorch-lightning         1.6.3                    pypi_0    pypi
[conda] pytorch-transformers      1.1.0                    pypi_0    pypi
[conda] torch                     1.12.0.dev20220517          pypi_0    pypi
[conda] torchmetrics              0.8.2                    pypi_0    pypi
[conda] torchtext                 0.12.0                     py38    pytorch
[conda] torchvision               0.13.0.dev20220517          pypi_0    pypi
```

cc @malfet @seemethere