-
Notifications
You must be signed in to change notification settings - Fork 26
adaptation to Python 3.9 #109
Changes from 14 commits
6e4c3d3
783bc8e
b83b2e8
845562b
c5b0cde
8221705
c16ab86
ea6e242
6203fe1
fa14cd5
817285f
a44b0bc
918098d
c677746
6b9b047
197c204
1d57fe4
8fdd415
fbff686
0332cd5
6b25123
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -528,7 +528,6 @@ def build_map( | |
|
||
def BUILD_MAP(self, instr): | ||
map_size = instr.arg | ||
built_map = {} | ||
assert map_size * 2 <= len( | ||
self._stack | ||
), f"OpExecutor want BUILD_MAP with size {map_size} * 2, but current stack do not have enough elems." | ||
|
@@ -691,6 +690,16 @@ def COMPARE_OP(self, instr): | |
f"{instr} is not support. may be not a supported compare op." | ||
) | ||
|
||
def IS_OP(self, instr): | ||
# It will only be 0 or 1 | ||
assert instr.argval == 0 or instr.argval == 1 | ||
left = self.pop() | ||
right = self.pop() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里pop的顺序是不是有点问题?先pop出来的应该是right元素吧 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gouzil 编写字节码模拟执行代码时候可以参考 cpython 的 https://github.com/python/cpython/blob/3.9/Python/ceval.c#L3019-L3031 (虽然 IS_OP 左右应该没太大问题,但最好还是对齐比较好) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 是的是的,已修复,这个跟 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if instr.argval == 0: | ||
self.push(SUPPORT_COMPARE_OP["is"](left, right)) | ||
else: | ||
self.push(SUPPORT_COMPARE_OP["is not"](left, right)) | ||
|
||
def MAKE_FUNCTION(self, instr): | ||
fn_name = self.pop() | ||
codeobj = self.pop() | ||
|
@@ -925,6 +934,35 @@ def FORMAT_VALUE(self, instr): | |
else: | ||
raise UnsupportError(f"Do not support format {type(value)} now") | ||
|
||
# NOTE: This operation will generate SideEffects, and the mechanism has not been completed yet | ||
def DICT_UPDATE(self, instr): | ||
dict_value = self.pop() | ||
assert instr.argval > 0 | ||
retval = {} | ||
# new data | ||
dict.update(retval, dict_value.get_wrapped_items()) | ||
# raw data | ||
dict.update(retval, self._stack[-instr.arg].get_wrapped_items()) | ||
self._stack[-instr.arg] = DictVariable( | ||
retval, self._graph, DummyTracker(dict_value) | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 返回的 DictVariable 与原来的是不共享数据的吗?这是符合预期的吗? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 还是不建议在 OpCodeExecutor 里直接操作 value,这也做不到可复用,比如用户调用了 |
||
|
||
# Like DICT_UPDATE but raises an exception for duplicate keys. | ||
DICT_MERGE = DICT_UPDATE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
这一点是如何体现的呢?另外新增的字节码也应该增加单测来确保正确性 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DICT_MERGE文档, 这个 测试值为 按照之前的想法如果key重复会直接被 File "/Users/gouzi/Documents/git/paddle-symbolic-trace/symbolic_trace/opcode_translator/executor/opcode_executor.py", line 306, in run
is_stop = self.step(cur_instr)
File "/Users/gouzi/Documents/git/paddle-symbolic-trace/symbolic_trace/opcode_translator/executor/opcode_executor.py", line 314, in step
return getattr(self, instr.opname)(instr) # run single step.
File "/Users/gouzi/Documents/git/paddle-symbolic-trace/symbolic_trace/opcode_translator/executor/opcode_executor.py", line 669, in CALL_FUNCTION_EX
ret = fn(*args, **kwargs)
File "/Users/gouzi/Documents/git/paddle-symbolic-trace/symbolic_trace/opcode_translator/executor/variables.py", line 718, in __call__
return self.call_function(*args, **kwargs)
File "/Users/gouzi/Documents/git/paddle-symbolic-trace/symbolic_trace/opcode_translator/executor/variables.py", line 795, in call_function
inline_executor = OpcodeInlineExecutor(self, *args, **kwargs)
File "/Users/gouzi/Documents/git/paddle-symbolic-trace/symbolic_trace/opcode_translator/executor/opcode_inline_executor.py", line 47, in __init__
self._prepare_locals(*args, **kwargs)
File "/Users/gouzi/Documents/git/paddle-symbolic-trace/symbolic_trace/opcode_translator/executor/opcode_inline_executor.py", line 54, in _prepare_locals
bound_args = sig.bind(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 3045, in bind
return self._bind(args, kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 3015, in _bind
raise TypeError('missing a required argument: {arg!r}'. \
TypeError: missing a required argument: 'c' 已修复为: File "/Users/gouzi/Documents/git/paddle-symbolic-trace/symbolic_trace/opcode_translator/executor/opcode_executor.py", line 306, in run
is_stop = self.step(cur_instr)
File "/Users/gouzi/Documents/git/paddle-symbolic-trace/symbolic_trace/opcode_translator/executor/opcode_executor.py", line 314, in step
return getattr(self, instr.opname)(instr) # run single step.
File "/Users/gouzi/Documents/git/paddle-symbolic-trace/symbolic_trace/opcode_translator/executor/opcode_executor.py", line 948, in DICT_MERGE
assert result == None, f"Repeat key: {key}"
AssertionError: Repeat key: a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里报 InnerError 吧,我们之后会统一规范下报错体系书写方式 #114 另外,报错信息和运行时错误保持一致:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 其余 LGTM There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
def LIST_EXTEND(self, instr): | ||
list_value = self.pop() | ||
assert instr.argval > 0 | ||
list.extend(self._stack[-instr.arg].value, list_value) | ||
|
||
def LIST_TO_TUPLE(self, instr): | ||
list_value = self.pop() | ||
self.push( | ||
TupleVariable( | ||
list_value.value, self._graph, DummyTracker([instr.argval]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里同样可以 get_wrapped_items 一下确保 Tracker 保留 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
) | ||
) | ||
|
||
def RETURN_VALUE(self, instr): | ||
assert ( | ||
len(self._stack) == 1 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果任何矩阵作业失败,GitHub 将不会取消所有正在进行的作业, 说明链接