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

tensor_array slice in PIR #60503

Merged
merged 2 commits into from
Jan 5, 2024
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
21 changes: 15 additions & 6 deletions python/paddle/base/variable_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,19 @@ def slice_is_same_to_original(start, end, step):


def parse_index(x, indices):
advanced_index = [None] * 2 * len(x.shape) # content is (dim, index)
from .framework import in_pir_mode

if in_pir_mode():
is_tensor_array = x.is_dense_tensor_array_type()
else:
is_tensor_array = (
hasattr(x, "desc")
and x.desc.type() == core.VarDesc.VarType.LOD_TENSOR_ARRAY
)

advanced_index = (
[] if is_tensor_array else [None] * 2 * len(x.shape)
) # content is (dim, index)
# for set_value / slice / strided_slice OP
decrease_axes = []
axes = []
Expand All @@ -267,11 +279,6 @@ def parse_index(x, indices):
indices = replace_ellipsis(x, indices)
indices, none_axes = replace_none(indices)

is_tensor_array = (
hasattr(x, "desc")
and x.desc.type() == core.VarDesc.VarType.LOD_TENSOR_ARRAY
)

estimated_dim = 0
dim = 0
for i, slice_item in enumerate(indices):
Expand Down Expand Up @@ -740,6 +747,8 @@ def get_tensor_with_basic_indexing(
if isinstance(end, (list, tuple)):
if paddle.utils._contain_var(end):
end = paddle.utils.get_int_tensor_list(end)
if x.is_dense_tensor_array_type():
return paddle._pir_ops.slice_array_dense(x, st)
out = paddle._C_ops.slice(
x,
axes,
Expand Down
1 change: 1 addition & 0 deletions test/dygraph_to_static/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ def init_dygraph_func(self):
test_list_pop_in_while_loop,
]

# TODO(zhangbo): Refine BuildOpFrom for op with sub_block
def train(self, to_static=False):
with base.dygraph.guard():
if to_static:
Expand Down