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

Add _LieGroupCheckContext setting for disabling internal warnings #669

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jacoblubecki
Copy link

Motivation and Context

Normalization in Lie group checks can be overly verbose in logging, it was identified that it could be an improvement if there was a way to selectively disable these checks in certain contexts (e.g. when implicit normalization is desired).

#486

How Has This Been Tested

Existing unit tests + manual testing in python REPL.

Example REPL test:

>>> non_se3 = torch.Tensor([[100, 0, 0, 0], [100, 100, 0, 0], [0, 0, 100, 0]]).unsqueeze(0)
>>> with enable_checks(), set_lie_group_check_enabled(True):
        th.SE3(tensor=non_se3)

~/Projects/theseus/theseus/theseus/geometry/manifold.py:141: UserWarning: The input tensor is not valid for SE3 and has been normalized.
  warnings.warn(
SE3(tensor=tensor([[[ 0.8944, -0.4472,  0.0000,  0.0000],
         [ 0.4472,  0.8944,  0.0000,  0.0000],
         [ 0.0000,  0.0000,  1.0000,  0.0000]]]), name=SE3__1)
>>> with enable_checks(), set_lie_group_check_enabled(True, silence_internal_warnings=True):
        th.SE3(tensor=non_se3)

SE3(tensor=tensor([[[ 0.8944, -0.4472,  0.0000,  0.0000],
         [ 0.4472,  0.8944,  0.0000,  0.0000],
         [ 0.0000,  0.0000,  1.0000,  0.0000]]]), name=SE3__2)

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes (no existing tests for this specific context manager, and code is covered in other existing tests)
  • All new and existing tests passed (***except CUDA tests which I could not run locally)

 ## Problem

The Manifold class will automatically normalize Tensors to make
them valid for their associated Lie group. A warning is emitted
when this occurs, which can be somewhat noisy and undesirable.

Issue: facebookresearch#486

 ## Solution

Add setting to _LieGroupCheckContext which, when set to True, can
be used in downstream code to suppress various warnings.

 ## Testing

Ensure existing unit tests pass.
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 9, 2024
cls.contexts.silence_internal_warnings = silence_internal_warnings


@contextmanager
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought using the @contextmanager decorator might help simplify the code a little bit -- I believe the functionality should be the same since no internal code was using any of the subclasses directly, and since this API is internal, downstream code shouldn't break, but if you'd prefer I leave the class-based approach, I am happy to revert back to that.

@luisenp
Copy link
Contributor

luisenp commented Nov 21, 2024

Hi @jacoblubecki, thanks for adding this! Sorry for the delay, I had this in my TODO stack but somehow two weeks passed!

I haven't tested the code yet, but the code and the example lgtm. What we want now is to turn on this new option under the hood when running an optimizer, so that intermediate Lie group operations don't throw this warning if there are numerical precision errors that are not necessarily the users' fault. The best place to do this should be this line. Let me know if you have any questions. x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants