3 #include <torch/csrc/WindowsTorchApiMacro.h> 4 #include <torch/csrc/autograd/function.h> 5 #include <torch/csrc/autograd/variable.h> 6 #include <torch/csrc/utils/variadic.h> 14 namespace torch {
namespace autograd {
16 using function_constructor = std::function<std::shared_ptr<Function>(edge_list&&)>;
22 TORCH_API variable_list wrap_outputs(
const variable_list& inputs, tensor_list&& outputs,
23 const function_constructor& ctr);
27 TORCH_API
void check_input_variables(
const char* name,
const variable_list& inputs,
int args,
int required_args=-1);
33 const auto& var =
static_cast<const Variable&
>(tensor);
34 if (var.defined() && var.requires_grad()) {
38 bool short_circuit() {
43 template <
typename... Args>
44 inline bool compute_requires_grad(Args&&... args) {
45 if (!GradMode::is_enabled()) {
51 inline void set_history(
53 const std::shared_ptr<Function>& grad_fn) {
55 if (variable.defined()) {
57 grad_fn->add_input_metadata(variable);
60 grad_fn->add_input_metadata(Function::undefined_input());
65 inline void set_history(
66 std::vector<Variable>&& variables,
67 const std::shared_ptr<Function>& grad_fn) {
68 for (
auto& variable : variables) {
69 set_history(variable, grad_fn);
73 inline void set_history(
74 std::vector<Variable>& variables,
75 const std::shared_ptr<Function>& grad_fn) {
76 for (
auto& variable : variables) {
77 set_history(variable, grad_fn);
void set_gradient_edge(Edge edge) noexcept
Set the gradient edge – i.e.
Variable A Variable augments a Tensor with the ability to interact in our autograd machinery...