Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PIR] Add state_dict to program_patch to enable default paramater #70377

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions python/paddle/pir/program_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from paddle.base import core
from paddle.base.executor import global_scope
from paddle.base.wrapped_decorator import signature_safe_contextmanager

from . import Program
Expand All @@ -27,8 +29,19 @@ def _lr_schedule_guard(self, is_with_opt=False):
# be fixed in the future.
yield

def state_dict(self, mode="all", scope=None):
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