Sparse convolution library for modern PyTorch and CUDA.
Project description
Torch Lattice
torch-lattice is the Torch/CUDA training-side companion to
mlx-lattice. It keeps the sparse
model authoring and CUDA provenance workflow on the Torch side, then exports
portable lattice MLIR artifacts for MLX/Metal deployment.
torch-lattice is a project-owned fork of MIT HAN Lab's TorchSparse. The public
semantics are aligned to mlx-lattice and the lattice MLIR contract rather than
to historical TorchSparse API quirks.
MLX Lattice | Acknowledgements
Install
torch-lattice currently targets Python 3.14, PyTorch CUDA 12.8 wheels, and a
CUDA 12.8 runtime/build environment. After the package is published, install the
CUDA wheel with:
uv pip install --torch-backend cu128 torch-lattice
For development from a checkout:
uv sync --all-packages --extra test
The repository also provides a CUDA Linux GitHub workflow that builds and smoke checks the native CUDA wheel on an Ubuntu runner.
Relationship to MLX Lattice
The two packages are intentionally split by runtime role:
torch-latticeis the CUDA training and artifact-production side.mlx-latticeis the Apple Silicon inference and deployment side.lattice-contractdefines the shared artifact constants and MLIR contract metadata used by both sides.
Portable artifacts use graph.mlir plus weights.safetensors. Torch-side
exporters write those files; MLX-side artifact loading compiles them into an
executable MLX program.
Convolution semantics
Convolution classes are explicit:
torch_lattice.nn.Conv3dis forward support-generating sparse convolution and exports tolattice.conv3d, includingstride=1.torch_lattice.nn.SubmConv3dis support-preserving submanifold convolution and exports tolattice.subm_conv3d.torch_lattice.nn.ConvTranspose3dexports tolattice.conv_transpose3d.torch_lattice.nn.GenerativeConvTranspose3dexports tolattice.generative_conv_transpose3d.
Artifact builders lower module identity directly. They do not infer submanifold semantics from stride, padding, or legacy indice-key conventions.
Tooling
After uv sync --all-packages, use the workspace scripts from the repository
root:
uv run bench --preset smoke
uv run fuzz --cases 32 --device cuda --archive /tmp/torch_lattice_fuzz.tar.gz
uv run conformance fuzz --cases 32 --device cuda
uv run migration all --device cuda
The corresponding MLX-side replay command is:
uv run conformance replay /tmp/torch_lattice_fuzz.tar.gz \
--report /tmp/torch_lattice_fuzz_report.json
Migration compatibility checks
Original TorchSparse and torch-lattice are not assumed to have identical class
semantics. The supported migration rule is explicit:
- original
torchsparse.nn.Conv3d(kernel_size > 1, stride = 1)maps totorch_lattice.nn.SubmConv3d; - original pointwise
Conv3d(kernel_size = 1)maps totorch_lattice.nn.Conv3d; - original strided forward convolutions map to
torch_lattice.nn.Conv3dwith the same stride.
The migration CLI verifies the covered subset against a kept original
TorchSparse package/worktree in separate subprocesses.
Documentation
The full documentation site lives in docs/. Build it locally with:
uv sync --all-packages --extra test --group docs
uv run --group docs sphinx-build -W -b html docs docs/_build/html
Development
Common local checks:
uv run --all-packages --extra test pytest tests -q
uv run bench --list
Build CUDA Linux distributions locally with:
export CUDA_PATH=/usr/local/cuda-12.8
uv build \
--sdist \
--wheel \
--config-setting=cmake.define.CMAKE_CUDA_COMPILER="$CUDA_PATH/bin/nvcc" \
--config-setting=cmake.define.CUDAToolkit_ROOT="$CUDA_PATH"
Acknowledgements
torch-lattice is based on MIT HAN Lab's original
TorchSparse project.
It is developed together with
mlx-lattice, which provides the
MLX/Metal deployment runtime for the same artifact contract.
License
Open sourced under the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torch_lattice-0.1.2.tar.gz.
File metadata
- Download URL: torch_lattice-0.1.2.tar.gz
- Upload date:
- Size: 9.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da70643925a33915ea78caf3e05654d6a85e0c5882f1b33730fe257101010e1a
|
|
| MD5 |
47492eda06c4e262b800197760d30e9a
|
|
| BLAKE2b-256 |
a6e0ac10f3920bd597cb235e18a37bba93352104d02e4205ffcdf10f75814ead
|
File details
Details for the file torch_lattice-0.1.2-cp314-cp314-manylinux_2_38_x86_64.whl.
File metadata
- Download URL: torch_lattice-0.1.2-cp314-cp314-manylinux_2_38_x86_64.whl
- Upload date:
- Size: 3.6 MB
- Tags: CPython 3.14, manylinux: glibc 2.38+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96527a272c13214da4cd022ab4742106001548b01be7d0a2cb9a5562f8e93d93
|
|
| MD5 |
b890de97c6a9c9d320a043c19cacc02d
|
|
| BLAKE2b-256 |
23c7dc147724bebf47377927bd7487bcd8544e455f57f8ef653738e477cc2a3f
|