Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -742,12 +742,14 @@ def gen_load_deref(self, name):
idx = self.cell_free_storage.index(name)
return self.add_instr("LOAD_DEREF", arg=idx, argval=name)

def gen_load_attr(self, name: str):
def gen_load_attr(self, name: str, push_null=False):
if name not in self._code_options["co_names"]:
self._code_options["co_names"].append(name)
idx = self._code_options["co_names"].index(name)
if sys.version_info >= (3, 12):
idx <<= 1
if push_null:
idx |= 1
Copy link
Member

Choose a reason for hiding this comment

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

LOAD_GLOBAL 不同,LOAD_ATTR 在 3.12 的最后一位用于表示 is_method,所以变量名需要修改下

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

return self.add_instr("LOAD_ATTR", arg=idx, argval=name)

def gen_store_attr(self, name: str):
Expand Down
11 changes: 9 additions & 2 deletions python/paddle/jit/sot/opcode_translator/executor/side_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from __future__ import annotations

import sys
from typing import TYPE_CHECKING, Any, NamedTuple, TypeVar

from .mutable_data import MutableData
Expand Down Expand Up @@ -123,12 +124,18 @@ def pre_gen(self, codegen: PyCodeGen):
# Reference to the original dict.
# load old_dict.update and new_dict to stack.
self.var.reconstruct(codegen)
codegen.gen_load_method("update")
if sys.version_info >= (3, 12):
codegen.gen_load_attr("update", True)
else:
codegen.gen_load_method("update")
Copy link
Member

Choose a reason for hiding this comment

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

不建议在这里做版本分发,可以考虑在 gen_load_method 中将 3.12+ 行为分发到 gen_load_attr(name, is_method)

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

# Generate dict by each key-value pair.
self.var.reconstruct(codegen, use_tracker=False)
# load old_dict.clear to stack.
self.var.reconstruct(codegen)
codegen.gen_load_method("clear")
if sys.version_info >= (3, 12):
codegen.gen_load_attr("clear", True)
else:
codegen.gen_load_method("clear")

def post_gen(self, codegen: PyCodeGen):
# Call methods to apply side effects.
Expand Down
1 change: 0 additions & 1 deletion test/sot/skip_files_py312
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
./test_11_jumps.py
./test_12_for_loop.py
./test_21_global.py
./test_builtin_zip.py
./test_inplace_api.py
./test_min_graph_size.py
Expand Down