mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 12:54:11 +08:00
### Summary: NOTE: This is a re-export of https://github.com/pytorch/pytorch/pull/161994 ; the changes between these two PRs is exclusively to the buck/build files (Summary from #161994 ) Attempted rebase of https://github.com/pytorch/pytorch/pull/143712. This reverts commit 6c713ccb5e0df227dd5b630057cbccd373cbe7d6. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames Lucaskabela imported-using-ghimport Test Plan: Imported from OSS Differential Revision: D81524507 Pulled By: Lucaskabela Pull Request resolved: https://github.com/pytorch/pytorch/pull/163769 Approved by: https://github.com/dolpm Co-authored-by: Brian Hirsh <hirsheybar@fb.com>
37 lines
1.0 KiB
C++
37 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include <ATen/FunctionalStorageImpl.h>
|
|
|
|
#include <torch/csrc/python_headers.h>
|
|
#include <torch/csrc/utils/pybind.h>
|
|
|
|
namespace torch::functionalization {
|
|
|
|
// Creates the default bindings for `ViewMeta` specializations.
|
|
//
|
|
// Defines a constructor using the types in `SerializableTuple`, as well
|
|
// as pickle methods.
|
|
template <class T>
|
|
void create_binding_with_pickle(py::module m) {
|
|
py::class_<T, std::shared_ptr<T>, at::functionalization::ViewMeta>(
|
|
m, T::name())
|
|
.def(py::init<typename T::SerializableTuple>())
|
|
.def(
|
|
"as_tuple",
|
|
[](const std::shared_ptr<T>& meta) {
|
|
return meta->to_serializable_tuple();
|
|
})
|
|
.def(py::pickle(
|
|
[](const std::shared_ptr<T>& meta) {
|
|
return meta->to_serializable_tuple();
|
|
},
|
|
[](const typename T::SerializableTuple& tpl) {
|
|
return std::make_shared<T>(tpl);
|
|
}));
|
|
}
|
|
|
|
void initModule(PyObject* module);
|
|
void initGenerated(PyObject* module);
|
|
|
|
} // namespace torch::functionalization
|