mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/19986 ghimport-source-id: 67f5fec4b5b2114f2922505a7743ed27e6d7e6cc Differential Revision: D15160820 Pulled By: ZolotukhinM fbshipit-source-id: e39238db8f30a8809891bff8a2fe39977124f6ca
23 lines
502 B
C++
23 lines
502 B
C++
#pragma once
|
|
#include <pybind11/pybind11.h>
|
|
#include <pybind11/stl.h>
|
|
#include <torch/csrc/jit/script/module.h>
|
|
|
|
namespace py = pybind11;
|
|
|
|
namespace torch {
|
|
namespace jit {
|
|
namespace script {
|
|
|
|
inline std::shared_ptr<Module> as_module(const py::object& obj) {
|
|
if (py::isinstance(
|
|
obj, py::module::import("torch.jit").attr("ScriptModule"))) {
|
|
return py::cast<std::shared_ptr<Module>>(obj.attr("_c"));
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
} // namespace script
|
|
} // namespace jit
|
|
} // namespace torch
|