-
-
Notifications
You must be signed in to change notification settings - Fork 985
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 jitter to Cholesky factorization in Gaussian ops #3151
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
be0e68d
Attempt to add jitter to Gaussian ops
fritzo 102abf5
Isolate changes to pyro.ops.tensor_utils
fritzo ae184e8
Add a warning
fritzo fd40b54
Simplify
fritzo d78b83c
Simplify
fritzo d542b83
Simplify to fixed jitter based on finfo.eps
fritzo 2f5e184
Simplify
fritzo fdb1be1
Rename cholesky -> safe_cholesky
fritzo 2da3c75
Allow disabling jitter
fritzo 152b913
Address review comment
fritzo 3e273e7
Switch to column-wise max, increase jitter
fritzo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do you intend to clamp by
(CHOLESKY_JITTER * finfo(x.dtype).eps) ** 2
here?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 intention was to scale by about
finfo(x.dtype).eps * x.max()
so that the jitter was just barely detectable by the largest matrix entry before Cholesky factorizing. That way if we setRELATIVE_CHOLESKY_JITTER = 1/2
then jitter will only affect matrix entries less than half the size of the max. And it kindof makes sense to me that each additional bit of precision would mean we would need to add half as much jitter, thus jitter would be proportional tofinfo(x.dtype).eps
. Mostly the proportional think helps us keep a constantRELATIVE_CHOLESKY_JITTER
across float32 and float64.What's your intuition behind the square here, is that to keep constant error post-Cholesky-factorization?
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.
I missed the
x_max
term in the above comment. Using square seems to be more consistent w.r.t. to casesx.size(-1) > 1
- but I like your clamp bytiny
better.Re
x_max
: using globalmax
makes sense, but I feel that it might be better to usemax
of rows instead, e.g. considering the diagonal matrix[0.0001, 10000]
, the global jitter is large w.r.t. the first diagonal term.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.
Nice idea! I've switched to using a row-wise max. This required increasing
CHOLESKY_RELATIVE_JITTER
from 1.0 to 4.0, but this way still seems better 👍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.
is this really preferred? this changes the eigenvalues and eigenvectors as opposed to jitter that is proportional to the identity (which only changes eigenvalues)
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.
@martinjankowiak that's a good point, I didn't know about eigenvector preservation. I'd be ok with either version.
One thing I like about @fehiepsi's solution is that users can on their side rotate the system before performing Gaussian ops, e.g. I'm approximately diagonalizing via QR
which shrinks my diagonal perturbations