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
..
experimental [export] overwrite placeholder names when deepcopying (#133269) 2024-08-13 10:20:43 +00:00
passes [export] Make move_to_device_pass function public (#134263) 2024-08-23 23:18:30 +00:00
__init__.py remove dynamic_dim (#134211) 2024-08-23 04:13:03 +00:00
_remove_auto_functionalized_pass.py Flip default value for mypy disallow_untyped_defs [6/11] (#127843) 2024-06-08 18:49:29 +00:00
_remove_effect_tokens_pass.py [export][fx] More robust DCE pass (#132764) 2024-08-06 22:27:22 +00:00
_safeguard.py Flip default value for mypy disallow_untyped_defs [6/11] (#127843) 2024-06-08 18:49:29 +00:00
_trace.py line by line logging (#134298) 2024-08-25 02:57:11 +00:00
_tree_utils.py [export] do not use tree_flatten_spec (#118608) 2024-01-30 19:14:04 +00:00
_unlift.py [export] detach constant tensors when they're not registered as buffer or parameter in unlift (#133031) 2024-08-09 20:33:52 +00:00
custom_obj.py
dynamic_shapes.py [export] basic auto dynamic shapes (#133620) 2024-08-23 22:56:39 +00:00
exported_program.py [export] Implement common_getitem_elimination pass. (#133618) 2024-08-21 16:48:24 +00:00
graph_signature.py [export] refactor ExportGraphSignature construction (#134059) 2024-08-23 23:29:28 +00:00
unflatten.py [export] Fix unflattener to respect nn.Parameter requires_grad (#134353) 2024-08-23 22:49:34 +00:00