1 #pragma once 2 3 #include <sstream> 4 5 namespace torch::autograd::utils { 6 requires_grad_leaf_error(bool requires_grad)7inline std::string requires_grad_leaf_error(bool requires_grad) { 8 std::ostringstream oss; 9 oss << "you can only change requires_grad flags of leaf variables."; 10 if (requires_grad == false) { 11 oss << " If you want to use a computed variable in a subgraph " 12 "that doesn't require differentiation use " 13 "var_no_grad = var.detach()."; 14 } 15 return oss.str(); 16 } 17 18 } // namespace torch::autograd::utils 19