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] migrate DataFeeder into pir #60434

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Changes from 1 commit
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
Next Next commit
update
  • Loading branch information
MarioLulab committed Dec 28, 2023
commit bf6eadfa05b757f331afec4bda0c038f3740aaa1
7 changes: 5 additions & 2 deletions paddle/fluid/pybind/pir.cc
Original file line number Diff line number Diff line change
@@ -582,15 +582,18 @@ const phi::DDim &GetValueDims(Value value) {
}

void BindValue(py::module *m) {
py::class_<Value> value(*m, "Value", R"DOC(
py::class_<Value> value(*m,
"Value",
R"DOC(
Value class represents the SSA value in the IR system. It is a directed edge
and a base class.

Notes:
The constructor of Value should not be invoked directly. Value can be automatically constructed
when build network.

)DOC");
)DOC",
pybind11::dynamic_attr());
g_ir_value_pytype = reinterpret_cast<PyTypeObject *>(value.ptr());
value.def(py::init<>())
.def_property_readonly(
47 changes: 35 additions & 12 deletions python/paddle/base/data_feeder.py
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@

import numpy as np

from paddle import pir

from ..pir import Value
from ..pir.core import ParameterMeta
from . import core
@@ -419,19 +421,40 @@ def __init__(self, feed_list, place, program=None):
self.feed_names = []
self.feed_shapes = []
self.feed_lod_level = []
if program is None:
program = default_main_program()
for each_var in feed_list:
if isinstance(each_var, str):
each_var = program.block(0).var(each_var)
if not isinstance(each_var, Variable):
raise TypeError("Feed list should contain a list of variable")
self.feed_dtypes.append(each_var.dtype)
self.feed_names.append(each_var.name)
self.feed_lod_level.append(each_var.lod_level)
self.feed_shapes.append(each_var.shape)

self.place = place
if in_pir_mode():
if program is None:
program = pir.core.default_main_program()
for each_var in feed_list:
if isinstance(each_var, str):
each_var = pir.core.get_value_by_name_from_block(
program.global_block(), each_var
)
if each_var is None:
raise ValueError(
"Value %s is not in program or can't be got name from Python."
% each_var
)
if not isinstance(each_var, Value):
raise TypeError("Feed list should contain a list of Value")
self.feed_dtypes.append(each_var.dtype)
self.feed_names.append(each_var.name)
self.feed_lod_level.append(each_var.lod_level)
self.feed_shapes.append(each_var.shape)
else:
if program is None:
program = default_main_program()
for each_var in feed_list:
if isinstance(each_var, str):
each_var = program.block(0).var(each_var)
if not isinstance(each_var, Variable):
raise TypeError(
"Feed list should contain a list of variable"
)
self.feed_dtypes.append(each_var.dtype)
self.feed_names.append(each_var.name)
self.feed_lod_level.append(each_var.lod_level)
self.feed_shapes.append(each_var.shape)

def feed(self, iterable):
"""
11 changes: 11 additions & 0 deletions python/paddle/pir/core.py
Original file line number Diff line number Diff line change
@@ -332,3 +332,14 @@ def static_op_arg_cast_guard(hook):
yield
finally:
set_static_op_arg_pre_cast_hook(original_callback)


def get_value_by_name_from_block(block, value_name):
for op in block.ops:
if op.name() == "pd_op.data":
if op.attr()["name"] == value_name:
return op.result(0)
elif op.name() == "builtin.parameter":
if op.attr()["parameter_name"] == value_name:
return op.result(0)
return None
1 change: 1 addition & 0 deletions python/paddle/static/input.py
Original file line number Diff line number Diff line change
@@ -134,6 +134,7 @@ def _reset_data_op_insertion_point():
ir_dtype = paddle.pir.core.convert_np_dtype_to_dtype_(dtype)
_reset_data_op_insertion_point()
out = paddle._pir_ops.data(name, shape, ir_dtype, core.Place())
out.lod_level = lod_level
paddle.pir.reset_insertion_point_to_end()
return out