mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Summary: I am working on unifying the C++ extensions and C++ API, and one constraint for this is that we will want to be able to build the C++ API without cereal, since we won't want to ship it with the Python `torch` package. For this I introduce a `TORCH_WITH_CEREAL` option to CMake. If on, the C++ API will be built with cereal and thus serialization support. If off, serialization functions will throw exceptions, but the library will otherwise still compile the same. __This option is on by default, so for regular C++ API users nothing will change__. However, from C++ extensions, we'll be able to turn it off. This effectively means we won't be searching for any cereal headers from C++ API headers, which wouldn't be installed in the Python package. ebetica ezyang soumith Pull Request resolved: https://github.com/pytorch/pytorch/pull/11498 Differential Revision: D9784803 Pulled By: goldsborough fbshipit-source-id: 5d0a1f2501993012d28cf3d730f45932b483abc4
33 lines
985 B
Python
33 lines
985 B
Python
import argparse
|
|
import os
|
|
import shlex
|
|
import subprocess
|
|
import sys
|
|
|
|
from setup_helpers.cuda import USE_CUDA
|
|
|
|
if __name__ == '__main__':
|
|
# Placeholder for future interface. For now just gives a nice -h.
|
|
parser = argparse.ArgumentParser(description='Build libtorch')
|
|
parser.add_argument('--use-cereal', action='store_true')
|
|
options = parser.parse_args()
|
|
|
|
os.environ['BUILD_TORCH'] = 'ON'
|
|
os.environ['BUILD_TEST'] = 'ON'
|
|
os.environ['ONNX_NAMESPACE'] = 'onnx_torch'
|
|
os.environ['PYTORCH_PYTHON'] = sys.executable
|
|
|
|
tools_path = os.path.dirname(os.path.abspath(__file__))
|
|
build_pytorch_libs = os.path.join(tools_path, 'build_pytorch_libs.sh')
|
|
|
|
command = [build_pytorch_libs, '--use-nnpack']
|
|
if USE_CUDA:
|
|
command.append('--use-cuda')
|
|
if options.use_cereal:
|
|
command.append('--use-cereal')
|
|
command.append('caffe2')
|
|
|
|
sys.stdout.flush()
|
|
sys.stderr.flush()
|
|
subprocess.check_call(command, universal_newlines=True)
|