Functions.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "torch/csrc/autograd/FunctionsManual.h"
  2. #include "torch/csrc/dynamo/compiled_autograd.h"
  3. // ${generated_comment}
  4. // The manual function definitions that used to be here are now in torch/csrc/autograd/FunctionsManual.cpp
  5. // This speeds up re-compilation and allow to share these implementations so that they can be
  6. // used for forward mode AD formulas as well.
  7. using namespace torch::autograd::generated::details;
  8. using at::Tensor;
  9. using at::Scalar;
  10. using at::IntArrayRef;
  11. using at::TensorList;
  12. namespace torch::autograd::generated {
  13. static at::IValue compute_output_metadata(const torch::autograd::edge_list& next_edges) {
  14. auto output_metadata = torch::dynamo::autograd::IValuePacker<
  15. std::vector<std::optional<InputMetadata>>>::pack(
  16. torch::dynamo::autograd::get_input_metadata(next_edges));
  17. return output_metadata;
  18. }
  19. static C10_NOINLINE variable_list compiled_autograd_apply_functional(
  20. const PackedArgs& packed_args,
  21. const edge_list& next_edges,
  22. SwapSavedVariables& saved,
  23. const variable_list& grads,
  24. const std::string& name) {
  25. auto output_metadata = compute_output_metadata(next_edges);
  26. const auto& pyinterface = torch::dynamo::autograd::getPyCompilerInterface();
  27. return pyinterface->call_function(
  28. saved.get_py_compiler(),
  29. "apply_functional",
  30. name,
  31. grads,
  32. packed_args.vec(),
  33. output_metadata);
  34. }
  35. ${autograd_function_definitions}
  36. } // namespace torch::autograd::generated