pytorch/torch/_export
Avik Chaudhuri 8db8ac700d line by line logging (#134298)
Summary:
Today there is no good mechanism to detect progress of non-strict export line-by-line in user code. This caused some pain recently in trying to find the exact line of user code that was triggering a bug where the process appeared stuck because deep down something was calling some symbolic shapes code that was suffering some exponential blowup.

This PR adds a environment variable for extended debugging that will log the line of user code corresponding to every torch function call. It only works in non-strict export for now. Prefix setting this environment variable with `TORCH_LOGS`  enabled for `export` logs at `DEBUG` level (i.e., with a `+` prefix), i.e.,.:

```
TORCHEXPORT_EXTENDED_DEBUG_CURRENT_LOC=1 TORCH_LOGS="+export" ...
```

This will show logs with something like:
```
...
prim::device called at .../example.py:4284 in foo
TensorBase.item called at .../example.py:4277 in bar
...
```

We already have an existing place to intercept torch functions where we process data-dependent errors in non-strict, so parking the logging there. An alternative place we could be doing this is where we add `stack_trace` metadata when generating code, but unfortunately at least the example that motivated this gets stuck before generating code, so that would be too late.

Test Plan: ran it on some sample commands

Differential Revision: D61692156

Pull Request resolved: https://github.com/pytorch/pytorch/pull/134298
Approved by: https://github.com/angelayi
2024-08-25 02:57:11 +00:00
..
db fix requirement for error classification (#133122) 2024-08-10 04:59:09 +00:00
pass_infra Flip default value for mypy disallow_untyped_defs [1/11] (#127838) 2024-06-08 18:16:33 +00:00
passes [export] Make move_to_device_pass function public (#134263) 2024-08-23 23:18:30 +00:00
serde [export] Schematize nn_module_stack serialization (#134049) 2024-08-23 21:50:01 +00:00
__init__.py [export][training ir migration] Fix getitem not exist (#134259) 2024-08-22 22:00:14 +00:00
converter.py [BE] typing for decorators - fx/_compatibility (part 1) (#134202) 2024-08-22 17:07:33 +00:00
error.py Fix global flake8 issues (#124771) 2024-04-26 15:35:53 +00:00
non_strict_utils.py line by line logging (#134298) 2024-08-25 02:57:11 +00:00
pass_base.py [BE] typing for decorators - fx/_compatibility (part 1) (#134202) 2024-08-22 17:07:33 +00:00
tools.py [report_exportability] Avoid re-exporting duplicated modules (#133930) 2024-08-20 22:11:57 +00:00
utils.py [export] basic auto dynamic shapes (#133620) 2024-08-23 22:56:39 +00:00
verifier.py [executorch] Refactor delegation code (#132773) 2024-08-15 22:52:12 +00:00
wrappers.py [hop] ban creating hop by directly instantiating HigherOrderOperator. (#133645) 2024-08-23 17:28:02 +00:00