Installation#

TorchSparse is available for Python 3.7 to Python 3.10. Before installing torchsparse, make sure that PyTorch has been successfully installed following the official guide.

Installation via Pip Wheels#

We provide pre-built torchsparse v2.1.0 packages (recommended) with different PyTorch and CUDA versions to simplify the building for the Linux system.

  1. Ensure at least PyTorch 1.9.0 is installed:

    python -c "import torch; print(torch.__version__)"
    >>> 1.10.0
    
  2. If you want to use TorchSparse with gpus, please ensure PyTorch was installed with CUDA:

    python -c "import torch; print(torch.version.cuda)"
    >>> 11.3
    
  3. Then the right TorchSparse wheel can be found and installed by running the installation script:

    python -c "$(curl -fsSL https://raw.githubusercontent.com/mit-han-lab/torchsparse/master/install.py)"
    

If Pypi server does not work as expected, no worries, you can still manually download the wheels. The wheels are listed in this website. One can utilize our installation script to automatically determine the version number used to index the wheels. For example, if you use PyTorch 1.11.0, CUDA 11.5, the version number will end up to be 2.1.0+torch111cu115. You can then select the proper wheel according to your Python version.

Installation from Source#

You can alternatively choose to install TorchSparse from source. Currently, we only support installing from source for torchsparse <= 2.0.0.

  1. TorchSparse depends on the Google Sparse Hash library.

    • On Ubuntu, it can be installed by:

    sudo apt-get install libsparsehash-dev
    
    • On Mac OS, it can be installed by:

    brew install google-sparsehash
    
    • You can also compile the library locally (if you do not have the sudo permission) and add the library path to the environment variable CPLUS_INCLUDE_PATH.

  2. Install Python dependencies by:

    pip install -r requirements.txt
    
  3. Then TorchSparse can be built from source and installed by:

    pip install -e .