xref: /aosp_15_r20/external/pytorch/torch/csrc/autograd/utils/error_messages.h (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #pragma once
2 
3 #include <sstream>
4 
5 namespace torch::autograd::utils {
6 
requires_grad_leaf_error(bool requires_grad)7 inline 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