Remove SkipCodeRecursiveException and RecompileLimitExceeded, add frame_exec_strategy attribute (#171358)
Summary:
Replace exception-based control flow pattern with attribute-based approach for
SkipCodeRecursiveException and RecompileLimitExceeded.
Instead of using specific exception types for control flow, add a frame_exec_strategy
attribute to TorchDynamoException that allows exceptions to optionally specify how
convert_frame should handle them.
Benefits:
- Cleaner separation of concerns (exceptions for errors, attributes for control flow)
- More flexible - any exception can specify a frame execution strategy
- Easier to extend - no need for new exception types for new strategies
- Better type safety with isinstance(e, exc.TorchDynamoException) check
Changes:
- torch/_dynamo/exc.py:
* Add frame_exec_strategy attribute to TorchDynamoException with documentation
* Remove SkipCodeRecursiveException and RecompileLimitExceeded classes
- torch/_dynamo/convert_frame.py:
* Remove imports of removed exception classes
* Replace isinstance checks with frame_exec_strategy attribute check
* Set frame_exec_strategy on Unsupported exception in recompile limit handler
X-link: https://github.com/pytorch/pytorch/pull/171358
Approved by: https://github.com/Lucaskabela, https://github.com/guilhermeleobas
ghstack dependencies: #170587
Reviewed By: clee2000
Differential Revision: D89940827
fbshipit-source-id: afbaf97ec745211ea0aed6cd59807bb60cda95b3