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] update SIR export check, add _reconstruct for TensorDtypeVariable #61822

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -284,6 +284,10 @@ def get_py_type(self):
return paddle.pir.core.DataType
return super().get_py_type()

def _reconstruct(self, codegen: PyCodeGen):
# dtype of paddle.Tensor is hashable, we can just load it as const var
codegen.gen_load_const(self.value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里在 PIR 下应该也需要上面 get_py_value 和 get_py_type 一样的检查并 vartype_to_datatype 才行吧,不然应该组网会挂

另外这个没有加单测么?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


@property
def main_info(self) -> dict[str, Any]:
return {
Expand Down
25 changes: 15 additions & 10 deletions python/paddle/jit/sot/symbolic/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,27 @@ def gen_py_codes(self):
self.create_tail()
return self.roots_to_string()

def is_exportable_type(self, value):
if (
isinstance(value, (ConstTypes, Symbol, paddle.dtype))
or value is Ellipsis # NOINT
):
return True
if isinstance(value, slice):
return (
self.is_exportable_type(value.start)
and self.is_exportable_type(value.stop)
and self.is_exportable_type(value.step)
)
return False

def check_exportable(self):
for stmt in self.SIR.statements:
for inp in flatten(stmt.inputs):
if not isinstance(inp, ConstTypes) and not isinstance(
inp, Symbol
):
if not self.is_exportable_type(inp):
raise ExportError(
f"Not support create python file with input: {inp}"
)
for out in flatten(stmt.outputs):
if not isinstance(out, ConstTypes) and not isinstance(
out, Symbol
):
raise ExportError(
f"Not support create python file with output: {out}"
)

def create_header(self):
self.new_root(
Expand Down