Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: differentiable matrix solve #1724

Closed
dbbert opened this issue Jun 5, 2017 · 13 comments · Fixed by #1733
Closed

feature request: differentiable matrix solve #1724

dbbert opened this issue Jun 5, 2017 · 13 comments · Fixed by #1733

Comments

@dbbert
Copy link

dbbert commented Jun 5, 2017

Are there any plans to implement something like tensorflow's tf.matrix_solve() and tf.matrix_solve_ls()?

torch.gels() exists but it doesn't have the backward step implemented.

@fmassa
Copy link
Member

fmassa commented Jun 5, 2017

One workaround for the moment would be to write matrix_solve as x = A.inverse() * b, which should support backprop since #1670 .
Adding support for matrix_solve should be trivial, the gradient for it can be found in https://github.com/tensorflow/tensorflow/blob/359d6f9716c0bb9bd8201ce600da98b0481a8049/tensorflow/python/ops/linalg_grad.py#L81-L91

@fmassa
Copy link
Member

fmassa commented Jun 5, 2017

I'll add backward support for gesv, which should be equivalent to tf.matrix_solve. I'll try to do it later today.

@MarcoForte
Copy link

How difficult would it be to add in batched versions (where only the final two dimensions are square) of GESV and inverse? Are there any plans for this?

@fmassa
Copy link
Member

fmassa commented Apr 25, 2018

If we have batched version of gesv, then adapting the autograd part is very simple.
There is an open issue already that discuss implementing batched gesv #3164

@fmassa
Copy link
Member

fmassa commented Apr 25, 2018

Actually, there is an open PR for that, so it might be coming soon #6100

@zou3519
Copy link
Contributor

zou3519 commented Apr 27, 2018

I'll rebase the batched version of gesv. It'll come in soon

@D-X-Y
Copy link

D-X-Y commented Aug 10, 2018

@fmassa May I ask why gesv only support A is a square matrix. As I saw from https://www.tensorflow.org/api_docs/python/tf/matrix_solve_ls, it support that A is a MxN matrix, and B is a NxK matrix, then solve a matrix X (NxK). If I want to use a non-square matrix A in gesv, would you mind to let me know how to implement in PyTorch?

@zou3519
Copy link
Contributor

zou3519 commented Aug 10, 2018

@D-X-Y this doesn't exactly answer your question but you can add zero-rows to the A matrix until it becomes square.

@D-X-Y
Copy link

D-X-Y commented Aug 11, 2018

@zou3519 thanks a lot, I find the solution, torch.gels can solve the problem.

@bobchennan
Copy link

Any plan to add gradient calculation for gels?

houseroad added a commit to houseroad/pytorch that referenced this issue Jan 10, 2019
…b9fdd5

Summary:
Previous import was 8384c788939bc65463f9754b6a7a00b212b18ba1

Included changes:
- **[7abd834](onnx/onnx@7abd834)**: Clarify some aspects of the Loop spec. (pytorch#1587) <Scott McKay>
- **[5a5b15f](onnx/onnx@5a5b15f)**: Support rtol and atol at the model granularity (pytorch#1723) <Lu Fang>
- **[ba76e45](onnx/onnx@ba76e45)**: print some information (pytorch#1724) <Lu Fang>
- **[797390d](onnx/onnx@797390d)**: Update README.md (pytorch#1722) <Prasanth Pulavarthi>
- **[40cdb5f](onnx/onnx@40cdb5f)**: repaire convtranspose shape inference (pytorch#1660) <peter yang>
- **[68fdb3f](onnx/onnx@68fdb3f)**: [Minor] Fix Windows line ending in test coverage generating script (pytorch#1717) <Raymond Yang>
- **[00101bf](onnx/onnx@00101bf)**: Remove ConstantLike op. Updates to ConstantOfShape op. (pytorch#1716) <Spandan Tiwari>
- **[c59e90a](onnx/onnx@c59e90a)**: add a shape inference test for group conv (pytorch#1719) <Lu Fang>

Reviewed By: zrphercule

Differential Revision: D13629499

fbshipit-source-id: 61d4b30be2018f6b1e39a6acf9d80f8a5f26d7fc
facebook-github-bot pushed a commit that referenced this issue Jan 11, 2019
…b9fdd5 (#15942)

Summary:
Pull Request resolved: #15942

Previous import was 8384c788939bc65463f9754b6a7a00b212b18ba1

Included changes:
- **[7abd834](onnx/onnx@7abd834)**: Clarify some aspects of the Loop spec. (#1587) <Scott McKay>
- **[5a5b15f](onnx/onnx@5a5b15f)**: Support rtol and atol at the model granularity (#1723) <Lu Fang>
- **[ba76e45](onnx/onnx@ba76e45)**: print some information (#1724) <Lu Fang>
- **[797390d](onnx/onnx@797390d)**: Update README.md (#1722) <Prasanth Pulavarthi>
- **[40cdb5f](onnx/onnx@40cdb5f)**: repaire convtranspose shape inference (#1660) <peter yang>
- **[68fdb3f](onnx/onnx@68fdb3f)**: [Minor] Fix Windows line ending in test coverage generating script (#1717) <Raymond Yang>
- **[00101bf](onnx/onnx@00101bf)**: Remove ConstantLike op. Updates to ConstantOfShape op. (#1716) <Spandan Tiwari>
- **[c59e90a](onnx/onnx@c59e90a)**: add a shape inference test for group conv (#1719) <Lu Fang>

Reviewed By: zrphercule

Differential Revision: D13629499

fbshipit-source-id: 4b3e4cb29bdb84c3777a8fb26263548efb20f317
@LemonPi
Copy link

LemonPi commented Mar 18, 2019

I am also wondering if torch.gels will have differentiation support.
My current workaround is to use torch.mm(X.pinverse(), Y) instead

@bobchennan
Copy link

bobchennan commented Mar 18, 2019 via email

@LemonPi
Copy link

LemonPi commented Mar 18, 2019

https://gist.github.com/bobchennan/a865b153c6835a3a6a5c628213766150 I actually implemented overdetermined case following tensorflow implementation. For backward pass I only did basic grad test.

On Monday, March 18, 2019, Johnson Zhong @.***> wrote: I am also wondering if torch.gels will have differentiation support. My current workaround is to use torch.mm(X.pinverse(), Y) instead — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#1724 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AA5UUNUEgeqv37Zxc01iV6hW17gScRQfks5vYADxgaJpZM4NwDQO .

Thanks, seems to work fine!

jjsjann123 pushed a commit to jjsjann123/pytorch that referenced this issue May 24, 2022
malfet pushed a commit that referenced this issue Jun 8, 2022
Syncing nvfuser devel branch to upstream master. https://github.com/csarofeen/pytorch/

A few bigger updates:
1. Initial support of cp.async and cp.async.wait: csarofeen#1619
2. Emulate ampere's mma 16816 with Turing's mma 1688, for a unified interface: csarofeen#1643
3. Extending the infrastructure to support mma operators on turing and ampere arch: csarofeen#1440

Commits that's actually in this PR from the csarofeen branch
```
* dd23252 (csarofeen/devel) Fusion Segmenter: Unify single kernel and multi-kernel runtime path (#1710)
* b3d1c3f Fix missing cooperative launch (#1726)
* dc670a2 Async gmem copy support on sm80+ (#1619)
* 5e6a8da Add turing mma support and test (#1643)
* d6d6b7d Fix rFactor when there are indirect root domain(s), and refactor (#1723)
* 7093e39 Mma op integration on ampere (#1440)
* fade8da patch python test for bfloat16 (#1724)
* 8fbd0b1 Fine-grained kernel profiling (#1720)
* 77c1b4f Adding dry run mode to skip arch dependent checks (#1702)
* 151d95b More precise concretization analysis (#1719)
* f4d3630 Enable complex python tests (#1667)
* 4ceeee5 Minor bugfix in transform_rfactor.cpp (#1715)
* 3675c70 Separate root domain and rfactor domain in TransformPrinter (#1716)
* f68b830 Fix scheduling with polymorphic broadcast (#1714)
* 4ab5ef7 updating_ci_machine (#1718)
* 56585c5 Merge pull request #1711 from csarofeen/upstream_master_bump_0517
* 174d453 Allow using nvFuser on CUDA extension (#1701)
* 18bee67 Validate LOOP concrete IDs have complete IterDomains (#1676)
```
Pull Request resolved: #78244
Approved by: https://github.com/csarofeen, https://github.com/malfet
facebook-github-bot pushed a commit that referenced this issue Jun 8, 2022
Summary:
Syncing nvfuser devel branch to upstream master. https://github.com/csarofeen/pytorch/

A few bigger updates:
1. Initial support of cp.async and cp.async.wait: csarofeen#1619
2. Emulate ampere's mma 16816 with Turing's mma 1688, for a unified interface: csarofeen#1643
3. Extending the infrastructure to support mma operators on turing and ampere arch: csarofeen#1440

Commits that's actually in this PR from the csarofeen branch
```
* dd23252 (csarofeen/devel) Fusion Segmenter: Unify single kernel and multi-kernel runtime path (#1710)
* b3d1c3f Fix missing cooperative launch (#1726)
* dc670a2 Async gmem copy support on sm80+ (#1619)
* 5e6a8da Add turing mma support and test (#1643)
* d6d6b7d Fix rFactor when there are indirect root domain(s), and refactor (#1723)
* 7093e39 Mma op integration on ampere (#1440)
* fade8da patch python test for bfloat16 (#1724)
* 8fbd0b1 Fine-grained kernel profiling (#1720)
* 77c1b4f Adding dry run mode to skip arch dependent checks (#1702)
* 151d95b More precise concretization analysis (#1719)
* f4d3630 Enable complex python tests (#1667)
* 4ceeee5 Minor bugfix in transform_rfactor.cpp (#1715)
* 3675c70 Separate root domain and rfactor domain in TransformPrinter (#1716)
* f68b830 Fix scheduling with polymorphic broadcast (#1714)
* 4ab5ef7 updating_ci_machine (#1718)
* 56585c5 Merge pull request #1711 from csarofeen/upstream_master_bump_0517
* 174d453 Allow using nvFuser on CUDA extension (#1701)
* 18bee67 Validate LOOP concrete IDs have complete IterDomains (#1676)
```

Pull Request resolved: #78244

Reviewed By: ejguan

Differential Revision: D36678948

Pulled By: davidberard98

fbshipit-source-id: 0ccde965acbd31da67d99c6adb2eaaa888948105
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants