-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add Cholesky Decompostion #8202
Conversation
Why don't you use |
How is
|
SciPy-compatible GPU implementation is available in
Inputs to
|
Sorry for the late response! Edit: I also found that the results of |
chainer/functions/math/cholesky.py
Outdated
|
||
def backward(self, indexes, gy): | ||
a, = self.get_retained_inputs().array | ||
return cuda.cupy.dot(a, a.T) * gy[0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable
-level equivalent code would be
a, = self.get_retrained_inputs()
return chainer.functions.matmul(a, a, transb=True),
Sorry for the late response! I have added changes and also added test patterns How do I solve this? |
When I run tests, in some cases the gradients computed backwards is absurdly more than the numeric gradients. For example -
|
The |
Yes I have made the necessary changes, but the mismatch still exists (its of a lower magnitude now, but more than tolerance value) |
chainer/functions/math/cholesky.py
Outdated
|
||
def backward(self, indexes, gy): | ||
a, = self.get_retained_inputs() | ||
return functions.matmul(a, a, transb=True) * gy[0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My fix is available at UmashankarTriforce#1. Could you merge it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes its done
Fix backward of cholesky
tests/chainer_tests/functions_tests/math_tests/test_cholesky.py
Outdated
Show resolved
Hide resolved
tests/chainer_tests/functions_tests/math_tests/test_cholesky.py
Outdated
Show resolved
Hide resolved
tests/chainer_tests/functions_tests/math_tests/test_cholesky.py
Outdated
Show resolved
Hide resolved
Co-Authored-By: Toshiki Kataoka <tos.lunar@gmail.com>
Co-Authored-By: Toshiki Kataoka <tos.lunar@gmail.com>
Co-Authored-By: Toshiki Kataoka <tos.lunar@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- In order to add the link to the function, could you edit
docs/source/reference/functions.rst
? - On the backprop, I changed my mind and let's return a symmetric matrix. Please wait and see Document properties of computed gradients in
cholesky
andeigh
#8312. F.cholesky
could callchainerx.linalg.cholesky
by overridingforward_chainerx
:
def forward_chainerx(self, inputs):
return chainerx.linalg.cholesky(*inputs),
I have added the points 1 and 3 from your review. I will wait for #8312 and change accordingly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#8312 is merged. Could you align F.cholesky
with chainerx.linalg.cholesky
?
return y_expect.astype(self.dtype), | ||
|
||
def forward(self, inputs, device): | ||
a, = inputs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Insert a = 0.5 * (a + a.T)
to make the perturbation symmetric, like the test code for chainerx.linalg.cholesky
:
chainer/tests/chainerx_tests/unit_tests/routines_tests/test_linalg.py
Lines 504 to 514 in c8e3b4f
def forward_xp(self, inputs, xp): | |
a, = inputs | |
if (_numpy_does_not_support_0d_input113 and a.size == 0): | |
pytest.skip('Older NumPy versions do not work with empty arrays') | |
# Input has to be symmetrized for backward test to work | |
a = (a + a.T)/2. + 1e-3 * xp.eye(*self.shape) | |
L = xp.linalg.cholesky(a) | |
return L, |
It can be also tested that the returned gradient is symmetric. (Not mandatory in this PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also fix TestCholesky.forward
? xp
means numpy
or cupy
(or chainerx
) in Chainer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I have added this fix
Co-Authored-By: Toshiki Kataoka <tos.lunar@gmail.com>
I'm extremely sorry for the late response 🙁 : I had my exams in college and hence I wasn't able to work on this. Have a look and let me know if any more modifications are necessary 🙂 |
return y_expect.astype(self.dtype), | ||
|
||
def forward(self, inputs, device): | ||
a, = inputs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also fix TestCholesky.forward
? xp
means numpy
or cupy
(or chainerx
) in Chainer.
Co-Authored-By: Toshiki Kataoka <tos.lunar@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Jenkins & flexCI, test this please. |
Jenkins CI test (for commit a496ded, target branch master) failed with status FAILURE. |
The error seems to be from ChainerX |
This PR aims to add Cholesky Decomposition as per the issue #1448
Route taken to complete this feature -