mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 00:21:07 +01:00
This sparsifier creates a nearly diagonal mask to be applied to the weight matrix.
Nearly Diagonal Matrix is a matrix that contains non-zero elements near the diagonal and the rest are zero.
An example of a nearly diagonal matrix with degree (or nearliness) 3 and 5 are follows respectively.
1 1 0 0 1 1 1 0
1 1 1 0 1 1 1 1
0 1 1 1 1 1 1 1
0 0 1 1 0 1 1 1
Note that a nearly diagonal matrix with degree 1 is just a matrix with main diagonal populated
This sparsifier is controlled by one variable:
1. `nearliness` defines the number of non-zero diagonal lines that are closest to the main diagonal.
Currently - supports only odd number
Note:
This can be accelerated (vectorized) once the Spdiagonal feature (PR: #78439) is landed or the banded matrix
feature is landed: https://stackoverflow.com/questions/52463972/generating-banded-matrices-using-numpy
Test Plan:
```
python test/test_ao_sparsity.py TestNearlyDiagonalSparsifier
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/78448
Approved by: https://github.com/z-a-f, https://github.com/HDCharles
29 lines
918 B
Python
29 lines
918 B
Python
# -*- coding: utf-8 -*-
|
|
# Owner(s): ["module: unknown"]
|
|
|
|
from torch.testing._internal.common_utils import run_tests
|
|
|
|
# Kernels
|
|
from ao.sparsity.test_kernels import TestQuantizedSparseKernels # noqa: F401
|
|
from ao.sparsity.test_kernels import TestQuantizedSparseLayers # noqa: F401
|
|
|
|
# Parametrizations
|
|
from ao.sparsity.test_parametrization import TestFakeSparsity # noqa: F401
|
|
|
|
# Sparsifier
|
|
from ao.sparsity.test_sparsifier import TestBaseSparsifier # noqa: F401
|
|
from ao.sparsity.test_sparsifier import TestWeightNormSparsifier # noqa: F401
|
|
from ao.sparsity.test_sparsifier import TestNearlyDiagonalSparsifier # noqa: F401
|
|
|
|
# Pruner
|
|
from ao.sparsity.test_pruner import TestBasePruner # noqa: F401
|
|
|
|
# Scheduler
|
|
from ao.sparsity.test_scheduler import TestScheduler # noqa: F401
|
|
|
|
# Composability
|
|
from ao.sparsity.test_composability import TestComposability # noqa: F401
|
|
|
|
if __name__ == '__main__':
|
|
run_tests()
|