Skip to content

cache traceback together with exceptions#6748

Merged
pmeier merged 1 commit intopytorch:mainfrom
pmeier:exc-cache
Oct 12, 2022
Merged

cache traceback together with exceptions#6748
pmeier merged 1 commit intopytorch:mainfrom
pmeier:exc-cache

Conversation

@pmeier
Copy link
Copy Markdown
Contributor

@pmeier pmeier commented Oct 12, 2022

We are caching the scripting of kernels inside our prototype tests:

@cache
def script(fn):

We do this because the test

def test_scripted_vs_eager(self, info, args_kwargs, device):

is run multiple times for the same kernel, but with different sample inputs. In fact, we only have 78 KernelInfo's but the test is run 7826 times. Meaning, in 99% of the runs, we script the kernel without any information gain whatsoever.

However, with the current implementation of @cache, the traceback of re-raised cached exceptions is not cleaned properly by pytest. TL;DR: the traceback of an exception is mutable. By re-raising, the pytest frames are getting appended over and over again, but pytest only removes them once. For a detailed explanation see pytest-dev/pytest#10363.

This leads to ginormous tracebacks that drown the actual information in the noise. For example, I intentionally made pad_bounding_box non-scriptable:

pytest -q test/test_prototype_transforms_functional.py::TestKernels::test_scripted_vs_eager -k pad_bounding_box | wc -l
  • main: 499510
  • PR: 3790
  • main without @cache: 3358

The few extra lines stem from the fact that the @cache wrapper adds minimal traceback itself.

Copy link
Copy Markdown
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

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

Kind of ugly but we already use a similar logic for caching the output... I'm approving as I agree that seeing the actual exceptions is necessary for debugging (I was left quite a few times scratching my head to find out what went wrong on tests) but I'm hoping we can adopt a better solution soon.

@pmeier pmeier merged commit 0bfbabc into pytorch:main Oct 12, 2022
@pmeier pmeier deleted the exc-cache branch October 12, 2022 09:47
facebook-github-bot pushed a commit that referenced this pull request Oct 17, 2022
Reviewed By: NicolasHug

Differential Revision: D40427479

fbshipit-source-id: 8783039e680fc74328ddd8d8ccf3fe39658345a2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants