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

Hide PyTorch trace compilation warnings #185

Merged
merged 3 commits into from
Oct 26, 2023

Conversation

FHof
Copy link
Collaborator

@FHof FHof commented Sep 10, 2023

Description

The test execution shows warnings about traces being potentially incorrect because the Python3 control flow is not completely recorded.
This includes conditions on the shape of the integration domain tensor.
Since the only arguments of the compiled integration function are the integrand and integration domain,
and the dimensionality of this integration domain is constant,
we can ignore the warnings.

After this change, the two get_jit_compiled_integrate functions hide PyTorch trace compilation warnings with warnings.filterwarnings.

Alternatively, it is possible to hide the warnings only at the code locations where they appear, but this would significantly increase the code complexity I think, see for example this diff to hide a subset of the warnings.

Resolved Issues

How Has This Been Tested?

Execution of pytest before and after the changes

@FHof FHof force-pushed the hofmeier/torch_hide_tracer_warnings branch from c45fcc4 to 3b5f6c8 Compare September 10, 2023 13:24
@gomezzz gomezzz self-requested a review October 9, 2023 12:39
@FHof FHof force-pushed the hofmeier/torch_hide_tracer_warnings branch from 3b5f6c8 to fb32846 Compare October 14, 2023 08:26
Copy link
Collaborator

@gomezzz gomezzz left a comment

Choose a reason for hiding this comment

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

Just a minor comment since ideally I would avoid having the same function defined in two places but probably unavoidable here due to imports?

Comment on lines 201 to 208
# The PyTorch trace compilation warnings contain many false
# positives, so we hide all trace compiler warnings
def trace_without_warnings(*args, **kwargs):
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", category=torch.jit.TracerWarning
)
return torch.jit.trace(*args, **kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess you are not making this function a dedicated file in the utils folder to avoid the torch import if possible, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've moved it to the utils.py file now, which also contains helper functions.

@FHof FHof force-pushed the hofmeier/torch_hide_tracer_warnings branch from fb32846 to f561a61 Compare October 18, 2023 14:55
@FHof
Copy link
Collaborator Author

FHof commented Oct 18, 2023

Just a minor comment since ideally I would avoid having the same function defined in two places but probably unavoidable here due to imports?

I think the function can be moved into the utils.py file without import problems but not the utils folder.

@FHof FHof changed the base branch from develop to main October 18, 2023 14:56
The test execution shows warnings about traces being potentially incorrect because the Python3 control flow is not completely recorded.
This includes conditions on the shape of the integration domain tensor.
Since the only arguments of the compiled integration function are the integrand and integration domain,
and the dimensionality of this integration domain is constant,
we can ignore the warnings.

After this change,
the two `get_jit_compiled_integrate` functions hide PyTorch trace compilation warnings with `warnings.filterwarnings`.
@FHof FHof force-pushed the hofmeier/torch_hide_tracer_warnings branch from f561a61 to b088aec Compare October 18, 2023 14:57
@gomezzz gomezzz merged commit 8e29b1d into esa:main Oct 26, 2023
3 checks passed
@gomezzz gomezzz deleted the hofmeier/torch_hide_tracer_warnings branch October 26, 2023 09:28
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 this pull request may close these issues.

2 participants