1 #pragma once 2 3 #include <string> 4 #include <vector> 5 6 #include <torch/csrc/lazy/core/tensor.h> 7 8 namespace torch { 9 namespace lazy { 10 11 TORCH_API std::function<std::vector<SourceLocation>()>& 12 GetPythonFramesFunction(); 13 14 TORCH_API std::string GetFirstUserFrameInPython(); 15 16 class TORCH_API DebugUtil { 17 public: 18 enum GraphFormat { 19 kText, 20 kDot, 21 kBackend, 22 }; 23 24 static GraphFormat GetDefaultGraphFormat(); 25 26 // Dumps the current Python frame and the IR Graph whose roots are the IR 27 // values held at the tensors. If indices is not nullptr, it selects the 28 // indices of the tensors whose graph will be emitted. 29 static std::string GetTensorsGraphInfo( 30 c10::ArrayRef<torch::lazy::LazyTensorPtr> tensors, 31 const std::vector<size_t>* indices, 32 GraphFormat format = GetDefaultGraphFormat()); 33 34 // If the environment variable LTC_SAVE_TENSORS_FILE is set to the proper 35 // output path, an instance of the report returned by GetTensorsGraphInfo() is 36 // saved. 37 static void SaveTensorsGraphInfo( 38 const char* name, 39 c10::ArrayRef<torch::lazy::LazyTensorPtr> tensors, 40 const std::vector<size_t>* indices, 41 GraphFormat format = GetDefaultGraphFormat()); 42 43 static bool ExperimentEnabled(const std::string& name); 44 }; 45 46 } // namespace lazy 47 } // namespace torch 48