Commit 56b3adce authored by limm's avatar limm
Browse files

fix README.md

parent d3ff4f16
Pipeline #2798 failed with stages
in 0 seconds
[pypi-image]: https://badge.fury.io/py/torch-bincount.svg
[pypi-url]: https://pypi.python.org/pypi/torch-bincount
[build-image]: https://travis-ci.org/rusty1s/pytorch_bincount.svg?branch=master
[build-url]: https://travis-ci.org/rusty1s/pytorch_bincount
[coverage-image]: https://codecov.io/gh/rusty1s/pytorch_bincount/branch/master/graph/badge.svg
[coverage-url]: https://codecov.io/github/rusty1s/pytorch_bincount?branch=master
# <div align="center"><strong>PyTorch Bincount</strong></div>
## 简介
PyTorch Bincount是一个小型扩展库,该扩展库具有高度优化的 bincount作,用于 PyTorch,而主包中缺少该作。该作适用于不同的数据类型,并且同时针对 CPU 和 GPU 实现。DAS软件栈中的PyTorch Bincount版本,不仅保证了该组件 核心功能在DCU加速卡的可用性,还针对DCU特有的硬件架构进行了深度定制优化,这使得开发者能够以极低的成本,轻松实现应用程序在DCU加速卡上的快速迁移和性能提升。目前已适配支持Pytorch1.13,Pyotrch2.1,Pytorch2.4.1
# PyTorch BinCount
## 安装
组件支持组合
[![PyPI Version][pypi-image]][pypi-url]
[![Build Status][build-image]][build-url]
[![Code Coverage][coverage-image]][coverage-url]
| PyTorch版本 | fastpt版本 |pytorch_Bincount版本 | DTK版本 | Python版本 | 推荐编译方式 |
| ----------- | ----------- | -------------------- | ------------ | ---------------- | ------------ |
| 2.5.1 | 2.1.0 |0.1.1 | >= 25.04 | 3.8、3.10、3.11 | fastpt不转码 |
| 2.4.1 | 2.0.1 |0.1.1 | >= 25.04 | 3.8、3.10、3.11 | fastpt不转码 |
| 其他 | 其他 | 其他 | 其他 | 3.8、3.10、3.11 | hip转码 |
This package consists of a small extension library of a highly optimized `bincount` operation for the use in [PyTorch](http://pytorch.org/), which is missing in the main package.
The operation works on varying data types and is implemented both for CPU and GPU.
## Installation
Ensure that at least PyTorch 0.4.1 is installed and verify that `cuda/bin` and `cuda/install` are in your `$PATH` and `$CPATH` respectively, *e.g.*:
+ pytorch版本大于2.4.1 && dtk版本大于25.04 推荐使用fastpt不转码编译。
- 安装相关依赖
```shell
pip install pytest
pip install wheel
```
$ python -c "import torch; print(torch.__version__)"
>>> 0.4.1
$ echo $PATH
>>> /usr/local/cuda/bin:...
$ echo $CPATH
>>> /usr/local/cuda/install:...
### 使用pip方式安装
pytorch-bincount whl包下载目录:[光合开发者社区](https://download.sourcefind.cn:65024/4/main/torch_bincount),选择对应的pytorch版本和python版本下载对应torch_bincount的whl包
```shell
pip install torch* (下载torch的whl包)
pip install fastpt* --no-deps (下载fastpt的whl包)
source /usr/local/bin/fastpt -E
pip install torch_bincount* (下载的torch_bincount的whl包)
```
Then run:
### 使用源码编译方式安装
```
pip install torch-scatter torch-bincount
```
#### 编译环境准备
提供基于fastpt不转码编译:
If you are running into any installation problems, please create an [issue](https://github.com/rusty1s/pytorch_bincount/issues).
## Usage
1. 基于光源pytorch基础镜像环境:镜像下载地址:[光合开发者社区](https://sourcefind.cn/#/image/dcu/pytorch),根据pytorch、python、dtk及系统下载对应的镜像版本。
2. 基于现有python环境:安装pytorch,fastpt whl包下载目录:[光合开发者社区](https://sourcefind.cn/#/image/dcu/pytorch),根据python、dtk版本,下载对应pytorch的whl包。安装命令如下:
```shell
pip install torch* (下载torch的whl包)
pip install fastpt* --no-deps (下载fastpt的whl包, 安装顺序,先安装torch,后安装fastpt)
```
torch_bincount.bincount(src, size=None) -> LongTensor
#### 源码编译安装
```shell
git clone http://developer.sourcefind.cn/codes/OpenDAS/torch-bincount.git
```
Counts the number of occurrences of each value in a non-negative tensor.
### Parameters
* **src** *(Tensor)* - The input tensor.
* **size** *(int, optional)* - The maximum number of bins for the output array. (default: `None`)
### Returns
* **out** *(LongTensor)* - The result of binning the input tensor.
### Example
```py
import torch
from torch_bincount import bincount
src = torch.tensor([2, 1, 1, 2, 4, 4, 2])
out = bincount(src)
- 提供2种源码编译方式(进入torch-bincount目录):
1. 设置不转码编译环境变量
```shell
export FORCE_CUDA=1
source /usr/local/bin/fastpt -C
```
2. 编译whl包并安装
```shell
cd torch-bincount
python setup.py bdist_wheel
pip install dist/*.whl
```
print(out)
tensor([ 0, 2, 3, 0, 2])
3. 源码编译安装
```shell
python3 setup.py install
```
#### 注意事项
+ 若使用pip install下载安装过慢,可添加pypi清华源:-i https://pypi.tuna.tsinghua.edu.cn/simple/
+ ROCM_PATH为dtk的路径,默认为/opt/dtk
## Running tests
## 验证
python -c "import torch_bincount; torch_bincount.\_\_version__",版本号与官方版本同步,查询该软件的版本号,例如0.1.1
## 单测
```shell
cd torch-bincount
pytest
```
python setup.py test
```
## Known Issue
## 参考资料
[README_ORIGIN.md](README_ORIGIN.md)
[https://github.com/rusty1s/pytorch_bincount.git](https://github.com/rusty1s/pytorch_bincount.git)
[pypi-image]: https://badge.fury.io/py/torch-bincount.svg
[pypi-url]: https://pypi.python.org/pypi/torch-bincount
[build-image]: https://travis-ci.org/rusty1s/pytorch_bincount.svg?branch=master
[build-url]: https://travis-ci.org/rusty1s/pytorch_bincount
[coverage-image]: https://codecov.io/gh/rusty1s/pytorch_bincount/branch/master/graph/badge.svg
[coverage-url]: https://codecov.io/github/rusty1s/pytorch_bincount?branch=master
# PyTorch BinCount
[![PyPI Version][pypi-image]][pypi-url]
[![Build Status][build-image]][build-url]
[![Code Coverage][coverage-image]][coverage-url]
This package consists of a small extension library of a highly optimized `bincount` operation for the use in [PyTorch](http://pytorch.org/), which is missing in the main package.
The operation works on varying data types and is implemented both for CPU and GPU.
## Installation
Ensure that at least PyTorch 0.4.1 is installed and verify that `cuda/bin` and `cuda/install` are in your `$PATH` and `$CPATH` respectively, *e.g.*:
```
$ python -c "import torch; print(torch.__version__)"
>>> 0.4.1
$ echo $PATH
>>> /usr/local/cuda/bin:...
$ echo $CPATH
>>> /usr/local/cuda/install:...
```
Then run:
```
pip install torch-scatter torch-bincount
```
If you are running into any installation problems, please create an [issue](https://github.com/rusty1s/pytorch_bincount/issues).
## Usage
```
torch_bincount.bincount(src, size=None) -> LongTensor
```
Counts the number of occurrences of each value in a non-negative tensor.
### Parameters
* **src** *(Tensor)* - The input tensor.
* **size** *(int, optional)* - The maximum number of bins for the output array. (default: `None`)
### Returns
* **out** *(LongTensor)* - The result of binning the input tensor.
### Example
```py
import torch
from torch_bincount import bincount
src = torch.tensor([2, 1, 1, 2, 4, 4, 2])
out = bincount(src)
```
```
print(out)
tensor([ 0, 2, 3, 0, 2])
```
## Running tests
```
python setup.py test
```
import torch
from torch.testing import get_all_dtypes
def get_all_dtypes():
return [torch.uint8, torch.int8, torch.int16, torch.int32, torch.int64,
torch.float16, torch.float32, torch.float64]
dtypes = get_all_dtypes()
dtypes.remove(torch.half)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment