[jit] Remove graph() call from abstract Function interface. (#65967)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/65967

Graph is an implementation detail. If user wants to get access to the
underlying graph, they should be able to explicitly dynamic cast instead.
ghstack-source-id: 141659819

Test Plan: no behavior change.

Reviewed By: gmagogsfm

Differential Revision: D31326153

fbshipit-source-id: a0e984f57c6013494b92a7095bf5bb660035eb84
This commit is contained in:
Zhengxu Chen
2021-10-27 11:52:48 -07:00
committed by Facebook GitHub Bot
parent 7c48b9ee25
commit b55a2500d2
43 changed files with 324 additions and 261 deletions

View File

@ -92,7 +92,7 @@ struct PythonResolver : public Resolver {
std::shared_ptr<SugaredValue> resolveValue(
const std::string& name,
Function& m,
GraphFunction& m,
const SourceRange& loc) override {
pybind11::gil_scoped_acquire ag;
py::object obj = rcb_(name);
@ -531,7 +531,7 @@ static std::shared_ptr<Graph> _propagate_and_assign_input_shapes(
void addFunctionToModule(Module& module, const StrongFunctionPtr& func) {
// Make a graph with a fake self argument
auto graph = func.function_->graph()->copy();
auto graph = toGraphFunction(*func.function_).graph()->copy();
auto v = graph->insertInput(0, "self");
v->setType(module._ivalue()->type());
const auto name = QualifiedName(*module.type()->name(), "forward");
@ -1414,11 +1414,13 @@ void initJitScriptBindings(PyObject* module) {
py::arg("_extra_files") = ExtraFilesMap())
.def_property_readonly(
"graph",
[](const StrongFunctionPtr& self) { return self.function_->graph(); })
[](const StrongFunctionPtr& self) {
return toGraphFunction(*self.function_).graph();
})
.def_property_readonly(
"inlined_graph",
[](const StrongFunctionPtr& self) {
auto g = self.function_->graph()->copy();
auto g = toGraphFunction(*self.function_).graph()->copy();
Inline(*g);
return g;
})
@ -1479,7 +1481,7 @@ void initJitScriptBindings(PyObject* module) {
.def_property_readonly(
"inlined_graph",
[](const Method& self) {
auto g = self.function().graph()->copy();
auto g = toGraphFunction(self.function()).graph()->copy();
Inline(*g);
return g;
})