How to perform efficient sparse matrix multiplication by using tf.matmul?

后端 未结 1 1601
时光说笑
时光说笑 2020-12-19 19:21

I\'m trying to perform a sparse matrix multiplication by using tf.matmul().

However, the inference speed is much more slower than dense matrix multiplication.

<
相关标签:
1条回答
  • 2020-12-19 20:13

    The relative performance depends on many factor. Sparse multiplication can be faster than dense multiplication with dense matrix (hopefully), but you are right that it can also be slower.

    For one thing, it depends on the size of your matrix.

    Here is the result of the multiplication of two square matrices, one random and one filled with zeros, and recorded the computation time for dense and spare multiplication.

    As you can see, even with a completely zero matrix, sparse multiplication can be slower than dense multiplication for smaller matrix size -- in fact almost three times slower for matrices about 120x120. In this experiment on my computer, sparse matrix multiplication starts taking over for sizes of about 700x700 and ends up being about 2 times faster. Of course YMMV depending on your configuration.

    0 讨论(0)
提交回复
热议问题