SparseToDense Torch Extension Test
Test description
This directory verifies aten::_to_dense registered by SparseToDense through the unified torch_extension
(CSR/CSC/COO → Tensor.to_dense()). For the operator interface and specifications, see
SparseToDense operator description and
Torch Extension interface description.
Prerequisites
Before running on an Ascend device with CANN and matching PyTorch / torch_npu installed, configure the environment first:
source /usr/local/Ascend/cann/set_env.sh
# Or: source /usr/local/Ascend/ascend-toolkit/latest/set_env.sh
Optional environment variables:
| Variable | Meaning | Default |
|---|---|---|
SOC |
build.sh --soc |
ascend950 |
OPS_SPARSE_LIB_DIR |
Directory containing libops_sparse.so |
The script automatically detects build_out/lib64 |
TORCH_EXTENSIONS_DIR |
JIT extension cache directory | $PWD/.torch_extensions |
Run
Run the following build and test steps in the repository root directory:
CMAKE_BUILD_TYPE=Release bash build.sh --ops=sparse2dense --soc="${SOC:-ascend950}"
python3 -m pip install -r torch_extension/requirements.txt
bash build.sh --torch_extension --ops=sparse2dense
python3 -m pip install --force-reinstall --no-deps build_out/cann_ops_sparse-*.whl
export OPS_SPARSE_LIB_DIR=$PWD/build_out/lib64
export TORCH_EXTENSIONS_DIR=$PWD/.torch_extensions
python3 -m pytest -q test/sparse2dense/python/test_sparse2dense_torch_extension.py -v