# Sparse Tensors in PyTorch

**URL:** <https://discuss.pytorch.org/t/sparse-tensors-in-pytorch/859>\
**Category:** Uncategorized\
**Created:** [March 4, 2017, 3:39am UTC](https://discuss.pytorch.org/t/sparse-tensors-in-pytorch/859 "2017-03-04T03:39:04Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ilya\_Kostrikov](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ilya_kostrikov/32/93_2.png) [@Ilya\_Kostrikov](https://discuss.pytorch.org/u/Ilya_Kostrikov)\
**Post date:** [March 4, 2017, 3:39am UTC](https://discuss.pytorch.org/t/sparse-tensors-in-pytorch/859/1 "2017-03-04T03:39:04Z")

</div>

What is the current state of sparse tensors in PyTorch?

---

<div class="post-metadata">

**Author:** ![smth](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/smth/32/13_2.png) [@smth](https://discuss.pytorch.org/u/smth)\
**Post date:** [March 4, 2017, 4:19am UTC](https://discuss.pytorch.org/t/sparse-tensors-in-pytorch/859/2 "2017-03-04T04:19:47Z")

</div>

right now, the description / summary of this PR that was merged 11 hours ago gives a good idea of the current state of things:

> <https://github.com/pytorch/pytorch/pull/735#issue-207307698>

---

<div class="post-metadata">

**Author:** ![apaszke](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/apaszke/32/21_2.png) [@apaszke](https://discuss.pytorch.org/u/apaszke)\
**Post date:** [March 4, 2017, 11:07am UTC](https://discuss.pytorch.org/t/sparse-tensors-in-pytorch/859/3 "2017-03-04T11:07:29Z")

</div>

But we’re not documenting them on purpose, because they might undergo some more changes in the future. The first step was to implement sprase updates for Embedding. Can I ask what’s your use case?

---

<div class="post-metadata">

**Author:** ![Ilya\_Kostrikov](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ilya_kostrikov/32/93_2.png) [@Ilya\_Kostrikov](https://discuss.pytorch.org/u/Ilya_Kostrikov)\
**Post date:** [March 7, 2017, 11:45am UTC](https://discuss.pytorch.org/t/sparse-tensors-in-pytorch/859/4 "2017-03-07T11:45:46Z")

</div>

I need just basic sparse matrix multiplication in order to implement a Graph ConvNet model. For example:

> **[How powerful are Graph Convolutional Networks?](https://tkipf.github.io/graph-convolutional-networks/)**
>
> Many important real-world datasets come in the form of graphs or networks: social networks, knowledge graphs, protein-interaction networks, the World Wide Web, etc. (just to name a few). Yet, until recently, very little attention has been devoted to...

and

> <https://github.com/mdeff/cnn_graph/blob/master/lib/models.py#L898>

The Laplacian matrix is extremely sparse is this case.

---

<div class="post-metadata">

**Author:** ![apaszke](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/apaszke/32/21_2.png) [@apaszke](https://discuss.pytorch.org/u/apaszke)\
**Post date:** [March 7, 2017, 12:32pm UTC](https://discuss.pytorch.org/t/sparse-tensors-in-pytorch/859/5 "2017-03-07T12:32:08Z")

</div>

You need `sparse x sparse -> sparse` multiplication, right? Right now we only have `sparse x dense -> dense` and `sparse x dense -> sparse`, because that’s what we needed for sparse Embedding updates. You can open a feature request if you want.

---

<div class="post-metadata">

**Author:** ![Ilya\_Kostrikov](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ilya_kostrikov/32/93_2.png) [@Ilya\_Kostrikov](https://discuss.pytorch.org/u/Ilya_Kostrikov)\
**Post date:** [March 7, 2017, 12:53pm UTC](https://discuss.pytorch.org/t/sparse-tensors-in-pytorch/859/6 "2017-03-07T12:53:41Z")

</div>

I need sparse x dense -\> dense. So I can use PyTorch in this case. Thanks a lot!

---

<div class="post-metadata">

**Author:** ![apaszke](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/apaszke/32/21_2.png) [@apaszke](https://discuss.pytorch.org/u/apaszke)\
**Post date:** [March 7, 2017, 1:16pm UTC](https://discuss.pytorch.org/t/sparse-tensors-in-pytorch/859/7 "2017-03-07T13:16:08Z")

</div>

`torch.mm` and `torch.spmm` should work then

---

<div class="post-metadata">

**Author:** ![Ilya\_Kostrikov](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ilya_kostrikov/32/93_2.png) [@Ilya\_Kostrikov](https://discuss.pytorch.org/u/Ilya_Kostrikov)\
**Post date:** [March 7, 2017, 5:23pm UTC](https://discuss.pytorch.org/t/sparse-tensors-in-pytorch/859/8 "2017-03-07T17:23:21Z")

</div>

But it’s not in autograd yet?

Is there a fast way to add it?

---

<div class="post-metadata">

**Author:** ![smth](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/smth/32/13_2.png) [@smth](https://discuss.pytorch.org/u/smth)\
**Post date:** [March 7, 2017, 7:32pm UTC](https://discuss.pytorch.org/t/sparse-tensors-in-pytorch/859/9 "2017-03-07T19:32:18Z")

</div>

a fast and local way is for you to write an autograd function for yourself.

---

<div class="post-metadata">

**Author:** ![hconroy](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/h/87869e/32.png) [@hconroy](https://discuss.pytorch.org/u/hconroy)\
**Post date:** [September 21, 2017, 3:08pm UTC](https://discuss.pytorch.org/t/sparse-tensors-in-pytorch/859/10 "2017-09-21T15:08:11Z")

</div>

> [@Ilya\_Kostrikov](#):
>
> What is the current state of sparse tensors in PyTorch?

That’s my question too (now on 21st Sept). Can anyone comment on the current state of sparse tensors in PyTorch?

Thank you

---

<div class="post-metadata">

**Author:** ![11131](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/1/ecb155/32.png) [@11131](https://discuss.pytorch.org/u/11131)\
**Post date:** [October 24, 2017, 8:14am UTC](https://discuss.pytorch.org/t/sparse-tensors-in-pytorch/859/11 "2017-10-24T08:14:23Z")

</div>

I would like to update variable with sparse gradients. and it’s normal. I know that wasn’t support by tensorflow. so how about pytorch/. Thank you!

---

<div class="post-metadata">

**Author:** ![pradeepgopalakrishna](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/pradeepgopalakrishna/32/8233_2.png) [@pradeepgopalakrishna](https://discuss.pytorch.org/u/pradeepgopalakrishna)\
**Post date:** [December 4, 2018, 2:53pm UTC](https://discuss.pytorch.org/t/sparse-tensors-in-pytorch/859/12 "2018-12-04T14:53:48Z")

</div>

What is the status of Sparse Support in PyTorch? I’d like to contribute to the module. What are the current design strategies in place? There seems to be no detail or comprehensive discussion on this aspect.

---

<div class="post-metadata">

**Author:** ![rajeshpiryani](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/r/71e660/32.png) [@rajeshpiryani](https://discuss.pytorch.org/u/rajeshpiryani)\
**Post date:** [September 13, 2021, 6:01pm UTC](https://discuss.pytorch.org/t/sparse-tensors-in-pytorch/859/13 "2021-09-13T18:01:07Z")

</div>

[https://pytorch.org/docs/stable/sparse.html#sparse-coo-tensors](https://pytorch.org/docs/stable/sparse.html#sparse-coo-tensors)
