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

[SOT] Avoid breakgraph when setitem and iterate paddle defined layerlist #71039

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
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,8 @@ def str_endswith(
operator.setitem,
(
"VariableBase",
"int | str | ConstantVariable | TensorVariable",
"int | str | ConstantVariable | TensorVariable",
"int | str | ConstantVariable | TensorVariable | ContainerVariable",
"VariableBase",
),
lambda var, key, value: var.setitem(add_guard(key).get_py_value(), value),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,13 @@ def main_info(self) -> dict[str, Any]:

@VariableFactory.register_from_value(successor="PaddleLayerVariable")
def from_value(value: Any, graph: FunctionGraph, tracker: Tracker):
if isinstance(value, PD_ALL_CONTAINERS):
# For Sequential and LayerList, we need to wrap them as ContainerLayerVariable
# to ensure inner layers are correctly tracked.
# But if user defined a container class and override the forward method,
# we should not wrap it as ContainerLayerVariable. Such as: RNNBase
if isinstance(value, PD_ALL_CONTAINERS) and value.__class__.forward in (
cls.forward for cls in PD_ALL_CONTAINERS
):
return ContainerLayerVariable(value, graph, tracker)
return None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,20 +837,19 @@ def _reconstruct(self, codegen: PyCodeGen):

def flatten_inner_vars(self):
items = self.get_wrapped_items()
return reduce(
operator.add,
(
return [
inner_var
for key in items.keys()
for key_var in [
VariableFactory.from_value(
key, self.graph, tracker=ConstTracker(key)
)
]
for inner_var in (
key_var.flatten_inner_vars()
+ self[key_var].flatten_inner_vars()
for key in items.keys()
for key_var in [
VariableFactory.from_value(
key, self.graph, tracker=ConstTracker(key)
)
]
),
[],
)
)
]

def get_wrapped_items(self):
items = {}
Expand Down
16 changes: 6 additions & 10 deletions python/paddle/jit/sot/opcode_translator/executor/variables/iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,13 @@ def get_iter(self):
return self

def flatten_inner_vars(self) -> list[VariableBase]:
holds = self.hold
if not isinstance(holds, list):
holds = [holds]
return [
var
for item_list in (
self.hold.get_wrapped_items()
if isinstance(self.hold, (ContainerVariable, IterVariable))
else [self.hold]
)
for item in (
item_list if isinstance(item_list, list) else [item_list]
)
for var in item.flatten_inner_vars()
inner_var
for hold in holds
for inner_var in hold.flatten_inner_vars()
]


Expand Down
12 changes: 6 additions & 6 deletions tools/check_file_diff_approvals.sh
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ fi
TEST_FILE_ADDED_LINES=$(git diff -U0 upstream/$BRANCH -- test |grep "^+")
ENABLE_TO_STATIC_CHECK=`echo "$TEST_FILE_ADDED_LINES" | grep "enable_to_static(" || true`
if [ "${ENABLE_TO_STATIC_CHECK}" != "" ] && [ "${GIT_PR_ID}" != "" ]; then
echo_line="You must have one RD (SigureMo, zrr1999 or gouzil) approval for using 'paddle.jit.enable_to_static', we recommend using 'enable_to_static_guard' in the related test files.\n"
check_approval 1 SigureMo zrr1999 gouzil
echo_line="You must have one RD (SigureMo, DrRyanHuang, zrr1999 or gouzil) approval for using 'paddle.jit.enable_to_static', we recommend using 'enable_to_static_guard' in the related test files.\n"
check_approval 1 SigureMo DrRyanHuang zrr1999 gouzil
fi

HAS_MODIFIED_DY2ST_TEST_FILES=$(git diff --name-only --diff-filter=ACMR upstream/$BRANCH | grep "test/dygraph_to_static/test_" || true)
Expand All @@ -321,15 +321,15 @@ if [ "${HAS_MODIFIED_DY2ST_TEST_FILES}" != "" ] && [ "${GIT_PR_ID}" != "" ]; the
echo_line=${echo_line}${error_lines}"\n"
echo_line=${echo_line}"You can run following command to fix the errors:\n"
echo_line=${echo_line}" python test/dygraph_to_static/check_approval.py "$(echo ${HAS_MODIFIED_DY2ST_TEST_FILES} | tr "\n" " ")"\n"
echo_line=${echo_line}"If you believe this is a false positive, please request one of the RD (SigureMo, zrr1999 or gouzil) approval for the changes.\n"
check_approval 1 SigureMo zrr1999 gouzil
echo_line=${echo_line}"If you believe this is a false positive, please request one of the RD (SigureMo, DrRyanHuang, zrr1999 or gouzil) approval for the changes.\n"
check_approval 1 SigureMo DrRyanHuang zrr1999 gouzil
fi
fi

HAS_MODIFIED_DY2ST_TEST_TENSOR_ATTR_CONSISTENCY=$(git diff --name-only upstream/$BRANCH | grep "test/dygraph_to_static/test_tensor_attr_consistency.py" || true)
if [ "${HAS_MODIFIED_DY2ST_TEST_TENSOR_ATTR_CONSISTENCY}" != "" ] && [ "${GIT_PR_ID}" != "" ]; then
echo_line="You must have one RD (SigureMo, zrr1999 or gouzil) approval for file changes in test/dygraph_to_static/test_tensor_attr_consistency.py.\n"
check_approval 1 SigureMo zrr1999 gouzil
echo_line="You must have one RD (SigureMo, DrRyanHuang, zrr1999 or gouzil) approval for file changes in test/dygraph_to_static/test_tensor_attr_consistency.py.\n"
check_approval 1 SigureMo DrRyanHuang zrr1999 gouzil
fi

HAS_USED_AUTO_PARALLEL_ALIGN_MODE=`git diff -U0 upstream/$BRANCH |grep -o -m 1 "auto_parallel_align_mode" || true`
Expand Down