Skip to content
Branch: master
Find file Copy path
Find file Copy path
4 contributors

Users who have contributed to this file

@anderspapitto @kostmo @pjh5 @bombs-kim
36 lines (25 sloc) 1.25 KB

libtorch (C++-only)

The core of pytorch does not depend on Python. A CMake-based build system compiles the C++ source code into a shared object,

Building libtorch

You can use a python script/module located in tools package to build libtorch

cd <pytorch_root>

# Make a new folder to build in to avoid polluting the source directories
mkdir build_libtorch && cd build_libtorch

# You might need to export some required environment variables here.
Normally sets good default env variables, but you'll have to do
that manually.
python ../tools/

Alternatively, you can call normally and then copy the built cpp libraries. This method may have side effects to your active Python installation.

cd <pytorch_root>
python build

ls torch/lib/tmp_install # output is produced here
ls torch/lib/tmp_install/lib/ # of particular interest

To produce libtorch.a rather than, set the environment variable BUILD_SHARED_LIBS=OFF.

To use ninja rather than make, set CMAKE_GENERATOR="-GNinja" CMAKE_INSTALL="ninja install".

Note that we are working on eliminating tools/ in favor of a unified cmake build.

You can’t perform that action at this time.