Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion paddle/fluid/pybind/pir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ void BindProgram(py::module *m) {
})
.def("num_ops", [](Program &self) { return self.num_ops(); })
.def(
"state_dict",
"_state_dict",
[](std::shared_ptr<Program> self,
const std::string &mode = "all",
const framework::Scope &scope = framework::Scope()) {
Expand Down
14 changes: 14 additions & 0 deletions python/paddle/pir/program_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,22 @@ def _lr_schedule_guard(self, is_with_opt=False):
# be fixed in the future.
yield

def state_dict(self, mode="all", scope=None):
from paddle.base import core
from paddle.base.executor import global_scope

if scope is not None and not isinstance(scope, core._Scope):
raise TypeError(
f"`scope` should be None or `paddle.static.Scope'` type, but received {type(scope)}."
)

if scope is None:
scope = global_scope()
return self._state_dict(mode, scope)

program_attrs = {
"_lr_schedule_guard": _lr_schedule_guard,
"state_dict": state_dict,
}

global _already_patch_program
Expand Down