README.md 4.91 KB
Newer Older
yan.yan's avatar
yan.yan committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!--
 Copyright 2021 Yan Yan
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 
     http://www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

traveller59's avatar
traveller59 committed
17
18
# SpConv: PyTorch Spatially Sparse Convolution Library

tusimple's avatar
tusimple committed
19
20
[![Build Status](https://github.com/traveller59/spconv/workflows/build/badge.svg)](https://github.com/traveller59/spconv/actions?query=workflow%3Abuild)

21
22
23
# !!!!!!!!!!
If you are using spconv < 2.0.2, update after spconv 2.0.2 build success or check [this issue](https://github.com/traveller59/spconv/issues/340#issuecomment-951493008) to fix a serious bug, I'm so sorry for this stupid bug.

yan.yan's avatar
yan.yan committed
24
## Breaking changes in Spconv 2.x
traveller59's avatar
traveller59 committed
25

yan.yan's avatar
yan.yan committed
26
27
* ```spconv.xxx``` move to ```spconv.pytorch.xxx```, change all ```import spconv``` to ```import spconv.pytorch as spconv``` and ```from spconv.xxx import``` to ```from spconv.pytorch.xxx import```.
* ```use_hash``` in Sparse Convolution is removed, we only use hash table in 2.x.
yan.yan's avatar
yan.yan committed
28
* ```x.features = F.relu(x)``` now raise error. use ```x = x.replace_feature(F.relu(x.features))``` instead.
yan.yan's avatar
yan.yan committed
29
30
31
32
* weight layout has been changed to RSKC (native algorithm) or KRSC (implicit gemm), no longer RSCK (spconv 1.x). RS is kernel size, C is input channel, K is output channel.
* all util ops are removed (pillar scatter/nms/...)
* VoxelGenerator has been replaced by Point2VoxelGPU[1-4]d/Point2VoxelCPU[1-4]d.
* spconv 2.x don't support CPU for now
traveller59's avatar
traveller59 committed
33

yan.yan's avatar
yan.yan committed
34
* test spconv 1.x model in spconv 2.x: set environment variable before run program. Linux: ```export SPCONV_FILTER_HWIO="1"```, Windows powershell: ```$Env:SPCONV_FILTER_HWIO = "1"```
35

FindDefinition's avatar
FindDefinition committed
36
37
38
39
40
## Upcoming release Spconv 2.1.0 (10.31.2021): 
* implicit gemm algorithm, greatly faster than native algorithm when using float16 (tested in RTX 3080 Laptop).
* simple CPU support and CPU-only build
* bug fix

yan.yan's avatar
yan.yan committed
41
## News in Spconv 2.0.0
traveller59's avatar
traveller59 committed
42

yan.yan's avatar
yan.yan committed
43
* training/inference speed is increased (+50~80% for float32)
yan.yan's avatar
yan.yan committed
44
45
46
* support int8/tensor core
* doesn't depend on pytorch binary. 
* since spconv 2.x doesn't depend on pytorch binary (never in future), it's impossible to support torch.jit/libtorch inference.
traveller59's avatar
traveller59 committed
47

48
49
50
51
52
53
54
Spconv 2.1.0 vs 1.x speed:

|                | 1080Ti Spconv 1.x F32 | 1080Ti Spconv 2.0 F32 | 3080M* Spconv 2.1 F16  |
| -------------- |:---------------------:| ---------------------:| ----------:|
| 27x128x128 Fwd | 11ms                  | 5.4ms                 | 1.4ms      |

\* 3080M (Laptop) ~= 3070 Desktop
yan.yan's avatar
yan.yan committed
55
56
57
58
59
60
61

## Usage

Firstly you need to use ```import spconv.pytorch as spconv``` in spconv 2.x.

Then see docs/USAGE.md.

traveller59's avatar
traveller59 committed
62

yan.yan's avatar
yan.yan committed
63
## Install
traveller59's avatar
traveller59 committed
64

yan.yan's avatar
yan.yan committed
65
You need to install python >= 3.7 first to use spconv 2.x.
traveller59's avatar
traveller59 committed
66

yan.yan's avatar
yan.yan committed
67
You need to install CUDA toolkit first before using prebuilt binaries or build from source.
traveller59's avatar
traveller59 committed
68

yan.yan's avatar
yan.yan committed
69
You need at least CUDA 10.2 to build and run spconv 2.x. We won't offer any support for CUDA < 10.2.
traveller59's avatar
traveller59 committed
70

yan.yan's avatar
yan.yan committed
71
### Prebuilt
traveller59's avatar
traveller59 committed
72

73
74
We offer python 3.7-3.10 and 11.1/11.4 prebuilt binaries for linux (manylinux) and windows 10/11.

yan.yan's avatar
yan.yan committed
75
CUDA 10.2 support will be added in version 2.0.2.
traveller59's avatar
traveller59 committed
76

yan.yan's avatar
yan.yan committed
77
We will offer prebuilts for CUDA versions supported by latest pytorch release. For example, pytorch 1.9 support cuda 10.2 and 11.1, so we support them too.
traveller59's avatar
traveller59 committed
78

yan.yan's avatar
yan.yan committed
79
For Linux users, you need to install pip >= 20.3 first to install prebuilt.
traveller59's avatar
traveller59 committed
80

yan.yan's avatar
yan.yan committed
81
```pip install spconv-cu111``` for CUDA 11.1
traveller59's avatar
traveller59 committed
82

yan.yan's avatar
yan.yan committed
83
```pip install spconv-cu114``` for CUDA 11.4
traveller59's avatar
traveller59 committed
84

yan.yan's avatar
yan.yan committed
85
86
**NOTE** It's safe to have different minor cuda version between system and conda (pytorch). for example, you can use spconv-cu114 with anaconda version of pytorch cuda 11.1 in a OS with CUDA 11.2 installed.

yan.yan's avatar
yan.yan committed
87
### Build from source
traveller59's avatar
traveller59 committed
88

yan.yan's avatar
yan.yan committed
89
You need to rebuild ```cumm``` first if you are build along a CUDA version that not provided in prebuilts.
traveller59's avatar
traveller59 committed
90

yan.yan's avatar
yan.yan committed
91
#### Linux
traveller59's avatar
traveller59 committed
92

yan.yan's avatar
yan.yan committed
93
94
1. install build-essential, install CUDA
2. run ```export SPCONV_DISABLE_JIT="1"```
yan.yan's avatar
yan.yan committed
95
3. run ```python setup.py bdist_wheel```+```pip install dists/xxx.whl```
traveller59's avatar
traveller59 committed
96

yan.yan's avatar
yan.yan committed
97
#### Windows 10/11
traveller59's avatar
traveller59 committed
98

yan.yan's avatar
yan.yan committed
99
100
101
102
1. install visual studio 2019 or newer. make sure C++ development package is installed. install CUDA
2. set [powershell script execution policy](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.1)
3. start a new powershell, run ```tools/msvc_setup.ps1```
4. run ```$Env:SPCONV_DISABLE_JIT = "1"```
yan.yan's avatar
yan.yan committed
103
5. run ```python setup.py bdist_wheel```+```pip install dists/xxx.whl```
traveller59's avatar
traveller59 committed
104

yan.yan's avatar
yan.yan committed
105
106
107
108
109
110
111
112
## TODO in Spconv 2.x
- [ ] Ampere (A100 / RTX 3000 series) feature support (work in progress)
- [ ] torch QAT support (work in progress)
- [ ] TensorRT (torch.fx based)
- [ ] Build C++ only package
- [ ] JIT compilation for CUDA kernels
- [ ] Document (low priority)
- [ ] CPU support (low priority)
yan.yan's avatar
yan.yan committed
113

yan.yan's avatar
yan.yan committed
114
## Note
traveller59's avatar
traveller59 committed
115

yan.yan's avatar
yan.yan committed
116
The work is done when the author is an employee at Tusimple.
traveller59's avatar
traveller59 committed
117

yan.yan's avatar
yan.yan committed
118
## LICENSE
traveller59's avatar
traveller59 committed
119

FindDefinition's avatar
FindDefinition committed
120
Apache 2.0