keras-team / keras

Deep Learning for humans
http://keras.io/
Apache License 2.0
61.29k stars 19.38k forks source link

Sparse Tensors #18420

Open adi-kmt opened 11 months ago

adi-kmt commented 11 months ago

Hey @fchollet,

do you have any roadmap to implement sparse tensors for the different backends?

fchollet commented 11 months ago

The general plan is to let backend ops receive and return backend-native sparse tensor types. E.g. backend.tensorflow.numpy.matmul should be able to receive sparse inputs, in which case it would return sparse outputs.

Then, when passed sparse data inputs (e.g. via tf.data or via scipy sparse arrays) we would not densify them and just pass them to the backend ops.

Lastly, we would avoid densify gradients in the optimizer (which we currently do).

The most work will be enabling all backend ops with sparse tensors support.

We should do this for the TensorFlow backend first, as it has the most mature support for sparse tensors so far.

jackd commented 10 months ago

I'd be willing to do a lot of the dogs-work to make this happen (e.g. write backend wrappers, keras Operations) if some framework for composite tensors (or even just a SparseTensor class) could be established.

fchollet commented 10 months ago

@hertschuh is currently working on this -- but there may be items you guys can take on!