# Sparse Linear layer

**URL:** <https://discuss.pytorch.org/t/sparse-linear-layer/39150>\
**Category:** Uncategorized\
**Created:** [March 6, 2019, 8:49pm UTC](https://discuss.pytorch.org/t/sparse-linear-layer/39150 "2019-03-06T20:49:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Albert65](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/albert65/32/10175_2.png) [@Albert65](https://discuss.pytorch.org/u/Albert65)\
**Post date:** [March 6, 2019, 8:49pm UTC](https://discuss.pytorch.org/t/sparse-linear-layer/39150/1 "2019-03-06T20:49:37Z")

</div>

Hi All, I would appreciate an example how to create a sparse Linear layer, which is similar to fully connected one with some links absent. It turns out the “torch.sparse” should be used, but I do not quite understand how to achieve that. I start from the dense tensor (image in my case), the next (hidden) layer shoud be a dense image of smaller size, and so on following the autoencoder layout. The only difference with the conventional pattern is that not every pair of entries of successive layers is connected (for performance reason).

---

<div class="post-metadata">

**Author:** ![Kale-ab\_Tessera](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/kale-ab_tessera/32/11407_2.png) [@Kale-ab\_Tessera](https://discuss.pytorch.org/u/Kale-ab_Tessera)\
**Post date:** [October 7, 2019, 6:06pm UTC](https://discuss.pytorch.org/t/sparse-linear-layer/39150/2 "2019-10-07T18:06:41Z")

</div>

Any news on this? I am also looking for sparse linear layers.

---

<div class="post-metadata">

**Author:** ![Aamir\_Mirza](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/aamir_mirza/32/13336_2.png) [@Aamir\_Mirza](https://discuss.pytorch.org/u/Aamir_Mirza)\
**Post date:** [February 18, 2020, 11:53pm UTC](https://discuss.pytorch.org/t/sparse-linear-layer/39150/3 "2020-02-18T23:53:40Z")

</div>

here you go , full implementation on git hub for sparse layer [https://github.com/numenta/htmpapers/tree/master/arxiv/how\_can\_we\_be\_so\_dense](https://github.com/numenta/htmpapers/tree/master/arxiv/how_can_we_be_so_dense)

---

<div class="post-metadata">

**Author:** ![robloughnan](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/r/f9ae1b/32.png) [@robloughnan](https://discuss.pytorch.org/u/robloughnan)\
**Post date:** [May 13, 2020, 6:59pm UTC](https://discuss.pytorch.org/t/sparse-linear-layer/39150/4 "2020-05-13T18:59:39Z")

</div>

@Aamir_Mirza thanks for sharing. Does this implementation result in saving GPU memory instead of using dense layers? Or is it that it enforces sparsity of the weights for convergence reasons?

---

<div class="post-metadata">

**Author:** ![shreyansh26](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/shreyansh26/32/31436_2.png) [@shreyansh26](https://discuss.pytorch.org/u/shreyansh26)\
**Post date:** [November 24, 2020, 5:33am UTC](https://discuss.pytorch.org/t/sparse-linear-layer/39150/5 "2020-11-24T05:33:03Z")

</div>

Is there any update on this? Any new libraries that implement sparse layer?

---

<div class="post-metadata">

**Author:** ![Saurabh\_Kataria](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/saurabh_kataria/32/12442_2.png) [@Saurabh\_Kataria](https://discuss.pytorch.org/u/Saurabh_Kataria)\
**Post date:** [January 3, 2022, 9:46pm UTC](https://discuss.pytorch.org/t/sparse-linear-layer/39150/6 "2022-01-03T21:46:47Z")

</div>

[https://github.com/huggingface/pytorch\_block\_sparse](https://github.com/huggingface/pytorch_block_sparse) is the latest I am aware of but dont know about its performance.
