swift-apis icon indicating copy to clipboard operation
swift-apis copied to clipboard

Add linear algebra operations and their derivatives

Open dan-zheng opened this issue 6 years ago • 10 comments

Swift for TensorFlow should provide standard linear algebra operations from tf.linalg/np.linalg:

Some of these operations are already accessible via TensorFlow bindings, e.g. _Raw.cholesky, _Raw.choleskyGrad.

Reference TensorFlow derivative implementations: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/linalg_grad.py


Mirror of TF-980.

If anyone requests support for specific operations, please comment and we add to the checklist!

dan-zheng avatar Nov 20 '19 20:11 dan-zheng

Hello @dan-zheng, this is not a full list of operations, but it would be good to start with this (all of them implicitly should work as batched versions as well):

  • [ ] Norm
  • [ ] Trace
  • [ ] Cholesky
  • [ ] Triangular Solve
  • [ ] Cholesky Solve
  • [ ] Diag (make a [batch] tensor from [batch] diagonal)
  • [ ] Diag Part (extract [batch] diagonal)
  • [ ] Einsum
  • [ ] Eye
  • [ ] Logdet
  • [ ] Eigh

awav avatar Nov 20 '19 23:11 awav

@dan-zheng , how can I add a new binding here? It is an auto-generated file and I don't see how it was generated.

awav avatar Nov 22 '19 16:11 awav

@awav you can't add new bindings in that file, You can check where how its generated here.

Shashi456 avatar Nov 22 '19 16:11 Shashi456

[EDITED] that's my bad, "TriangularSolve" is in the RawOpsGenerated.swift file, as well as many other linalg ops.

@Shashi456 , yeah, I've checked it. But, it is not clear why for e.g. "TriangularSolve" is not reflected in the RawOpsGenerated.swift file, but "TriangularSolve" is in the ops.pbtxt. Does S4TF uses different protobuf file?

awav avatar Nov 22 '19 16:11 awav

@Shashi456 , yeah, I've checked it. But, it is not clear why for e.g. "TriangularSolve" is not reflected in the RawOpsGenerated.swift file, but "TriangularSolve" is in the ops.pbtxt. Does S4TF uses different protobuf file?

Swift for TensorFlow uses the same ops.pbtxt - here's the script that generates op bindings.

TensorFlow.Raw and ops.pbtxt are consistent, both define matrixTriangularSolve and batchMatrixTriangularSolve:

image

dan-zheng avatar Nov 24 '19 07:11 dan-zheng

@awav are you working on supporting these ops? could i ask what ops you are working on currently?

Shashi456 avatar Dec 06 '19 20:12 Shashi456

@Shashi456, solvers and trace for now

@dan-zheng, you can mark diag and diag_part as finished. They were implemented in https://github.com/tensorflow/swift-apis/pull/571

awav avatar Dec 06 '19 21:12 awav

@Shashi456, @dan-zheng hello guys, sorry for the delay with PRs for solvers and other promised ops. I'm at NeurIPS and don't have much time to finish the work. Thanks!

awav avatar Dec 13 '19 08:12 awav

@dan-zheng, trace can be marked as done now.

awav avatar Dec 20 '19 10:12 awav

Hi, If I can add to the wishlist, the following matrix operations could be useful:

  • QR eigen decomposition with explicit shift (Wilkinson shif)
  • the Schur decomposition

pedronahum avatar Mar 27 '20 12:03 pedronahum