xref: /aosp_15_r20/external/pytorch/torch/csrc/jit/passes/remove_exceptions.h (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #pragma once
2 
3 #include <torch/csrc/jit/ir/ir.h>
4 
5 namespace torch::jit {
6 
7 // Considering prim::RaiseException nodes unreachable, simplify prim::If nodes
8 // when one of the branches contains prim::RaiseException.
9 //
10 // This pass is illegal in general case as the modified graph might not throw
11 // an exception that the original graph would throw. The purpose of the pass is
12 // to cleanup the graph in a "risky" way by removing pathways leading to
13 // RaiseExceptions nodes. In some sense, this pass could be considered as a
14 // "Release" mode, while the original graph was in a "Debug" mode.
15 // The pass should only be used when such transformation is guaranteed to be
16 // safe by some other mechanisms. For instance, when we know exact shapes of
17 // tensors flowing through the graph and tensors with such shapes never cause
18 // exceptions.
19 TORCH_API void EliminateExceptions(std::shared_ptr<Graph>& graph);
20 
21 } // namespace torch::jit
22