README.md 2.5 KB
Newer Older
aiss's avatar
aiss committed
1
# <div align="center"><strong>torch-sparse-0.6.18</strong></div>
quyuanhao123's avatar
quyuanhao123 committed
2
3
4
5
## 简介
torch-sparse是PyTorch的一个扩展库,用于处理稀疏数据。它提供了一些功能强大的稀疏矩阵操作,以及能够高效执行稀疏计算的函数和工具。

## 依赖安装
aiss's avatar
aiss committed
6
7
+ 建议pytorch1.13以及对应的torchvision(建议dtk-23.10)
+ python 3.8及以上
quyuanhao123's avatar
quyuanhao123 committed
8
9
10
11
12
13
14
15

### 1、使用源码编译方式安装

#### 编译环境准备
提供2种环境准备方式:

1. 基于光源pytorch基础镜像环境:镜像下载地址:[https://sourcefind.cn/#/image/dcu/pytorch](https://sourcefind.cn/#/image/dcu/pytorch),根据pytorch、python、dtk及系统下载对应的镜像版本。

quyuanhao123's avatar
quyuanhao123 committed
16
2. 基于现有python环境:安装pytorch和torchvision,whl包下载目录:[https://cancon.hpccube.com:65024/4/main/pytorch](https://cancon.hpccube.com:65024/4/main/pytorch)[https://cancon.hpccube.com:65024/4/main/vision](https://cancon.hpccube.com:65024/4/main/vision),根据python、dtk版本,下载对应pytorch和torchvision的whl包。安装命令如下:
quyuanhao123's avatar
quyuanhao123 committed
17
18
```shell
pip install torch* (下载的torch的whl包)
quyuanhao123's avatar
quyuanhao123 committed
19
pip install torchvision* (下载的torchvision的whl包)
quyuanhao123's avatar
quyuanhao123 committed
20
21
22
23
24
25
26
27
28
29
pip install setuptools==59.5.0 wheel
```

#### 源码编译安装
- 代码下载
```shell
git clone http://developer.hpccube.com/codes/aicomponent/torch-sparce # 根据编译需要切换分支
```
- 源码编译(进入torch-sparse目录):
```
aiss's avatar
aiss committed
30
31
source /opt/dtk/env.sh
export FORCE_CUDA=1
quyuanhao123's avatar
quyuanhao123 committed
32
33
34
export CC=hipcc
export CXX=hipcc

aiss's avatar
aiss committed
35
python setup.py install bdist_wheel
quyuanhao123's avatar
quyuanhao123 committed
36
37
```
#### 注意事项
aiss's avatar
aiss committed
38
+ 编译后生成的安装包whl在dist文件夹下,pip直接安装即可
quyuanhao123's avatar
quyuanhao123 committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
+ 若使用pip install下载安装过慢,可添加pypi清华源:-i https://pypi.tuna.tsinghua.edu.cn/simple/
+ ROCM_PATH为dtk的路径,默认为/opt/dtk

## 验证

```python
import torch
from torch_sparse import coalesce

index = torch.tensor([[1, 0, 1, 0, 2, 1],
                      [0, 1, 1, 1, 0, 0]])
value = torch.Tensor([[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]])

index, value = coalesce(index, value, m=3, n=2)
```

```
print(index)
tensor([[0, 1, 1, 2],
        [1, 0, 1, 0]])
print(value)
tensor([[6.0, 8.0],
        [7.0, 9.0],
        [3.0, 4.0],
        [5.0, 6.0]])
```

## Known Issue
- 该库没有基于cpu环境修改,仅支持dcu,请在有dcu卡的环境运行。
- 如需完整使用所有pyg功能,请pip install torch-geometric

## 参考资料
- [README_ORIGIN](README_ORIGIN.md)
aiss's avatar
aiss committed
72
- [https://github.com/rusty1s/pytorch_sparse/tree/0.6.18](https://github.com/rusty1s/pytorch_sparse/tree/0.6.18)