From 6e4c3d3f505ffec9aecf6052052a8f8caf1ffe6c Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Thu, 1 Jun 2023 23:15:10 +0800 Subject: [PATCH 01/18] [opcode][executor] add [DICT_UPDATE, LIST_EXTEND, LIST_TO_TUPLE] --- .github/workflows/test.yaml | 10 +++++++--- .../opcode_translator/executor/opcode_executor.py | 15 ++++++++++++++- tests/run_all.sh | 12 +++++++++++- tests/test_10_build_unpack.py | 12 +++++++++++- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2bdfd3555..e63ea034e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -8,8 +8,12 @@ on: jobs: Test: - runs-on: ubuntu-latest - name: Run unit tests and examples + runs-on: ${{ matrix.python-version }} + name: ${{ matrix.os }} - python ${{ matrix.python-version }} + strategy: + matrix: + os: [ubuntu-latest] + python-version: ['3.8','3.9'] steps: - name: Checkout uses: actions/checkout@v3 @@ -18,7 +22,7 @@ jobs: uses: actions/setup-python@v4 with: # Currently, we only support Python 3.8 - python-version: '3.8' + python-version: ${{ matrix.python-version }} - name: Install dependencies run: | diff --git a/symbolic_trace/opcode_translator/executor/opcode_executor.py b/symbolic_trace/opcode_translator/executor/opcode_executor.py index 3b42fb21e..1f97d1b72 100644 --- a/symbolic_trace/opcode_translator/executor/opcode_executor.py +++ b/symbolic_trace/opcode_translator/executor/opcode_executor.py @@ -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." @@ -925,6 +924,20 @@ def FORMAT_VALUE(self, instr): else: raise UnsupportError(f"Do not support format {type(value)} now") + def DICT_UPDATE(self, instr): + v = self.pop() + assert instr.argval > 0 + dict.update(self._stack[-instr.arg].value, v) + + 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]))) + def RETURN_VALUE(self, instr): assert ( len(self._stack) == 1 diff --git a/tests/run_all.sh b/tests/run_all.sh index e8d30186c..2c40dd3c0 100644 --- a/tests/run_all.sh +++ b/tests/run_all.sh @@ -2,6 +2,8 @@ export PYTHONPATH=$PYTHONPATH:../ export STRICT_MODE=1 +failed_tests=() + for file in ./test_*.py; do # 检查文件是否为 Python 文件 if [ -f "$file" ]; then @@ -10,7 +12,15 @@ for file in ./test_*.py; do python "$file" if [ $? -ne 0 ]; then echo "run $file failed" - exit 1 + failed_tests+=("$file") fi fi done + +if [ ${#failed_tests[@]} -ne 0 ]; then + echo "failed tests file:" + for failed_test in "${failed_tests[@]}"; do + echo "$failed_test" + done + exit 1 +fi diff --git a/tests/test_10_build_unpack.py b/tests/test_10_build_unpack.py index 1e8505878..d3fac758e 100644 --- a/tests/test_10_build_unpack.py +++ b/tests/test_10_build_unpack.py @@ -3,6 +3,9 @@ # BUILD_TUPLE_UNPACK_WITH_CALL (new) # CALL_FUNCTION_EX (new) # BUILD_MAP_UNPACK (new) +# LIST_EXTEND (new) +# LIST_TO_TUPLE (new) +# DICT_UPDATE (new) from __future__ import annotations @@ -58,7 +61,7 @@ def build_map_unpack_with_call( class TestExecutor(TestCaseBase): - def test_simple(self): + def test_simple_list(self): a = paddle.to_tensor(1) b = paddle.to_tensor(2) c = paddle.to_tensor(3) @@ -67,6 +70,11 @@ def test_simple(self): self.assert_results(build_tuple_unpack, (a, b), (c, d)) self.assert_results(build_list_unpack, [a, b], [c, d]) self.assert_results(build_tuple_unpack_with_call, (a, b), (c, d)) + def test_simple_dict(self): + a = paddle.to_tensor(1) + b = paddle.to_tensor(2) + c = paddle.to_tensor(3) + d = paddle.to_tensor(4) self.assert_results( build_map_unpack, {"a": a, "b": b}, {"c": c, "d": d} ) @@ -76,4 +84,6 @@ def test_simple(self): if __name__ == "__main__": + # t = TestExecutor() + # t.test_simple() unittest.main() From 783bc8e5e25a0f001ab3025c25c36a7a322360b0 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Thu, 1 Jun 2023 23:31:43 +0800 Subject: [PATCH 02/18] pre-commit --- .github/workflows/test.yaml | 2 +- .../opcode_translator/executor/opcode_executor.py | 6 +++++- tests/test_10_build_unpack.py | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e63ea034e..48b0f60ca 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,7 +10,7 @@ jobs: Test: runs-on: ${{ matrix.python-version }} name: ${{ matrix.os }} - python ${{ matrix.python-version }} - strategy: + strategy: matrix: os: [ubuntu-latest] python-version: ['3.8','3.9'] diff --git a/symbolic_trace/opcode_translator/executor/opcode_executor.py b/symbolic_trace/opcode_translator/executor/opcode_executor.py index 1f97d1b72..d8135264b 100644 --- a/symbolic_trace/opcode_translator/executor/opcode_executor.py +++ b/symbolic_trace/opcode_translator/executor/opcode_executor.py @@ -936,7 +936,11 @@ def LIST_EXTEND(self, instr): def LIST_TO_TUPLE(self, instr): list_value = self.pop() - self.push(TupleVariable(list_value.value, self._graph, DummyTracker([instr.argval]))) + self.push( + TupleVariable( + list_value.value, self._graph, DummyTracker([instr.argval]) + ) + ) def RETURN_VALUE(self, instr): assert ( diff --git a/tests/test_10_build_unpack.py b/tests/test_10_build_unpack.py index d3fac758e..417a94f3c 100644 --- a/tests/test_10_build_unpack.py +++ b/tests/test_10_build_unpack.py @@ -70,6 +70,7 @@ def test_simple_list(self): self.assert_results(build_tuple_unpack, (a, b), (c, d)) self.assert_results(build_list_unpack, [a, b], [c, d]) self.assert_results(build_tuple_unpack_with_call, (a, b), (c, d)) + def test_simple_dict(self): a = paddle.to_tensor(1) b = paddle.to_tensor(2) From b83b2e829d6d42b7eb6a37b1e50079babeb04e9b Mon Sep 17 00:00:00 2001 From: Nyakku Shigure Date: Fri, 2 Jun 2023 01:55:22 +0800 Subject: [PATCH 03/18] add a whitespace --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 48b0f60ca..3fc019506 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -13,7 +13,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python-version: ['3.8','3.9'] + python-version: ['3.8', '3.9'] steps: - name: Checkout uses: actions/checkout@v3 From 845562b590177cd33fb0b1ea25c6227353c866cf Mon Sep 17 00:00:00 2001 From: Nyakku Shigure Date: Fri, 2 Jun 2023 01:55:37 +0800 Subject: [PATCH 04/18] remove outdated comment --- .github/workflows/test.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3fc019506..bb7c884a8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -21,7 +21,6 @@ jobs: - name: Install python uses: actions/setup-python@v4 with: - # Currently, we only support Python 3.8 python-version: ${{ matrix.python-version }} - name: Install dependencies From c5b0cde26f6c64d7f3d35b1e438f885e7d9de5a2 Mon Sep 17 00:00:00 2001 From: Nyakku Shigure Date: Fri, 2 Jun 2023 01:58:13 +0800 Subject: [PATCH 05/18] fix ci `runs-on` --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index bb7c884a8..6af0bee22 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -8,12 +8,12 @@ on: jobs: Test: - runs-on: ${{ matrix.python-version }} - name: ${{ matrix.os }} - python ${{ matrix.python-version }} strategy: matrix: os: [ubuntu-latest] python-version: ['3.8', '3.9'] + runs-on: ${{ matrix.os }} + name: ${{ matrix.os }} - python ${{ matrix.python-version }} steps: - name: Checkout uses: actions/checkout@v3 From c16ab862c670af01c2be8d166bd418c7c742ec6d Mon Sep 17 00:00:00 2001 From: SigureMo Date: Fri, 2 Jun 2023 02:04:44 +0800 Subject: [PATCH 06/18] update wheel to nightly build --- .github/workflows/test.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 82198710f..5ac764802 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -25,8 +25,7 @@ jobs: - name: Install dependencies run: | - wget https://paddle-ci.gz.bcebos.com/dy2st/fallback/linux-whl/paddlepaddle_gpu-0.0.0-cp38-cp38-linux_x86_64.whl - pip install paddlepaddle_gpu-0.0.0-cp38-cp38-linux_x86_64.whl + python -m pip install paddlepaddle==0.0.0 -f https://www.paddlepaddle.org.cn/whl/linux/cpu-mkl/develop.html pip install -r requirements.txt - name: Run unit tests From ea6e242ad56a3619016cfa3800c91c6f01571c53 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Fri, 2 Jun 2023 13:06:07 +0800 Subject: [PATCH 07/18] add override_method_update --- .../opcode_translator/executor/opcode_executor.py | 6 +++++- symbolic_trace/opcode_translator/executor/variables.py | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/symbolic_trace/opcode_translator/executor/opcode_executor.py b/symbolic_trace/opcode_translator/executor/opcode_executor.py index d8135264b..15c9eedb6 100644 --- a/symbolic_trace/opcode_translator/executor/opcode_executor.py +++ b/symbolic_trace/opcode_translator/executor/opcode_executor.py @@ -924,10 +924,14 @@ 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): v = self.pop() assert instr.argval > 0 - dict.update(self._stack[-instr.arg].value, v) + self._stack[-instr.arg] = self._stack[-instr.arg].update(v) + + # Like DICT_UPDATE but raises an exception for duplicate keys. + DICT_MERGE = DICT_UPDATE def LIST_EXTEND(self, instr): list_value = self.pop() diff --git a/symbolic_trace/opcode_translator/executor/variables.py b/symbolic_trace/opcode_translator/executor/variables.py index 1cb939e71..8f0e4cdac 100644 --- a/symbolic_trace/opcode_translator/executor/variables.py +++ b/symbolic_trace/opcode_translator/executor/variables.py @@ -679,6 +679,13 @@ def override_method_items(self): item_list, self.graph, DummyTracker([item_list]) ) + def override_method_update(self, data): + print(self.tracker) + self.value.update(data.value) + return DictVariable( + self.value, graph=self.graph, tracker=DummyTracker([self]) + ) + def __getattr__(self, name): name_ = "override_method_" + name if hasattr(self, name_): From 6203fe1317973492043343a9cf62b2699849d488 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Fri, 2 Jun 2023 15:29:11 +0800 Subject: [PATCH 08/18] [opcode] fix DICT_UPDATE;[test] Restore single test --- .../opcode_translator/executor/opcode_executor.py | 11 +++++++++-- .../opcode_translator/executor/variables.py | 7 ------- tests/test_10_build_unpack.py | 7 +------ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/symbolic_trace/opcode_translator/executor/opcode_executor.py b/symbolic_trace/opcode_translator/executor/opcode_executor.py index 15c9eedb6..476c028de 100644 --- a/symbolic_trace/opcode_translator/executor/opcode_executor.py +++ b/symbolic_trace/opcode_translator/executor/opcode_executor.py @@ -926,9 +926,16 @@ def FORMAT_VALUE(self, instr): # NOTE: This operation will generate SideEffects, and the mechanism has not been completed yet def DICT_UPDATE(self, instr): - v = self.pop() + dict_value = self.pop() assert instr.argval > 0 - self._stack[-instr.arg] = self._stack[-instr.arg].update(v) + 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) + ) # Like DICT_UPDATE but raises an exception for duplicate keys. DICT_MERGE = DICT_UPDATE diff --git a/symbolic_trace/opcode_translator/executor/variables.py b/symbolic_trace/opcode_translator/executor/variables.py index 8f0e4cdac..1cb939e71 100644 --- a/symbolic_trace/opcode_translator/executor/variables.py +++ b/symbolic_trace/opcode_translator/executor/variables.py @@ -679,13 +679,6 @@ def override_method_items(self): item_list, self.graph, DummyTracker([item_list]) ) - def override_method_update(self, data): - print(self.tracker) - self.value.update(data.value) - return DictVariable( - self.value, graph=self.graph, tracker=DummyTracker([self]) - ) - def __getattr__(self, name): name_ = "override_method_" + name if hasattr(self, name_): diff --git a/tests/test_10_build_unpack.py b/tests/test_10_build_unpack.py index 417a94f3c..c3aba67e6 100644 --- a/tests/test_10_build_unpack.py +++ b/tests/test_10_build_unpack.py @@ -6,6 +6,7 @@ # LIST_EXTEND (new) # LIST_TO_TUPLE (new) # DICT_UPDATE (new) +# DICT_MERGE (new) from __future__ import annotations @@ -70,12 +71,6 @@ def test_simple_list(self): self.assert_results(build_tuple_unpack, (a, b), (c, d)) self.assert_results(build_list_unpack, [a, b], [c, d]) self.assert_results(build_tuple_unpack_with_call, (a, b), (c, d)) - - def test_simple_dict(self): - a = paddle.to_tensor(1) - b = paddle.to_tensor(2) - c = paddle.to_tensor(3) - d = paddle.to_tensor(4) self.assert_results( build_map_unpack, {"a": a, "b": b}, {"c": c, "d": d} ) From fa14cd50323c5b4799915e027032491d97f3caf9 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Fri, 2 Jun 2023 15:40:06 +0800 Subject: [PATCH 09/18] update ci --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5ac764802..0cef7b696 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -9,6 +9,7 @@ on: jobs: Test: strategy: + fail-fast: false matrix: os: [ubuntu-latest] python-version: ['3.8', '3.9'] From 817285f6313de1ee029144fd70911674ac5c60dd Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Fri, 2 Jun 2023 16:33:41 +0800 Subject: [PATCH 10/18] [tests] clean tests --- tests/test_10_build_unpack.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_10_build_unpack.py b/tests/test_10_build_unpack.py index c3aba67e6..edb8021e5 100644 --- a/tests/test_10_build_unpack.py +++ b/tests/test_10_build_unpack.py @@ -62,7 +62,7 @@ def build_map_unpack_with_call( class TestExecutor(TestCaseBase): - def test_simple_list(self): + def test_simple(self): a = paddle.to_tensor(1) b = paddle.to_tensor(2) c = paddle.to_tensor(3) @@ -80,6 +80,4 @@ def test_simple_list(self): if __name__ == "__main__": - # t = TestExecutor() - # t.test_simple() unittest.main() From a44b0bccb659495e67788f887b0f87bcd932ffac Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Fri, 2 Jun 2023 18:24:57 +0800 Subject: [PATCH 11/18] [opcode] add IS_OP --- .../opcode_translator/executor/opcode_executor.py | 10 ++++++++++ symbolic_trace/utils/paddle_api_config.py | 3 +++ 2 files changed, 13 insertions(+) diff --git a/symbolic_trace/opcode_translator/executor/opcode_executor.py b/symbolic_trace/opcode_translator/executor/opcode_executor.py index 476c028de..248813a09 100644 --- a/symbolic_trace/opcode_translator/executor/opcode_executor.py +++ b/symbolic_trace/opcode_translator/executor/opcode_executor.py @@ -690,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() + 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() diff --git a/symbolic_trace/utils/paddle_api_config.py b/symbolic_trace/utils/paddle_api_config.py index 86890a1b2..f7a55d158 100644 --- a/symbolic_trace/utils/paddle_api_config.py +++ b/symbolic_trace/utils/paddle_api_config.py @@ -24,6 +24,9 @@ def get_paddle_api(): for fn_name in getattr(module, "__all__", []): fn = getattr(module, fn_name) if inspect.isfunction(fn): + # NOTE: Maybe add a whitelist list + if fn.__name__ == "in_dygraph_mode": + continue paddle_api_list.append(fn) return list(set(paddle_api_list)) From c677746a8fd024d0b135cd7045e696b5d0cf5324 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Fri, 2 Jun 2023 18:47:20 +0800 Subject: [PATCH 12/18] RollBACK --- symbolic_trace/utils/paddle_api_config.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/symbolic_trace/utils/paddle_api_config.py b/symbolic_trace/utils/paddle_api_config.py index 5f952fdcb..331cf8491 100644 --- a/symbolic_trace/utils/paddle_api_config.py +++ b/symbolic_trace/utils/paddle_api_config.py @@ -41,9 +41,6 @@ def get_paddle_api(): for fn_name in getattr(module, "__all__", []): fn = getattr(module, fn_name) if inspect.isfunction(fn): - # NOTE: Maybe add a whitelist list - if fn.__name__ == "in_dygraph_mode": - continue paddle_api_list.append(fn) return list(set(paddle_api_list) - set(non_operator_related_apis)) From 6b9b0471a02683ca84ba2399a233d6ceab8c6536 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Fri, 2 Jun 2023 22:26:36 +0800 Subject: [PATCH 13/18] [variables] add override_method_extend, override_method_update.[opcode] fix DICT_MERGE --- .../executor/opcode_executor.py | 24 +++++++++---------- .../opcode_translator/executor/variables.py | 8 +++++++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/symbolic_trace/opcode_translator/executor/opcode_executor.py b/symbolic_trace/opcode_translator/executor/opcode_executor.py index 248813a09..e8d4853f4 100644 --- a/symbolic_trace/opcode_translator/executor/opcode_executor.py +++ b/symbolic_trace/opcode_translator/executor/opcode_executor.py @@ -938,28 +938,28 @@ def FORMAT_VALUE(self, instr): 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) - ) + self._stack[-instr.arg].update(dict_value) - # Like DICT_UPDATE but raises an exception for duplicate keys. - DICT_MERGE = DICT_UPDATE + def DICT_MERGE(self, instr): + dict_value = self.pop() + assert instr.argval > 0 + for key in dict_value.get_wrapped_items().keys(): + result = self._stack[-instr.arg].get_wrapped_items().get(key, None) + assert result is None, f"Repeat key: {key}" + self._stack[-instr.arg].update(dict_value) def LIST_EXTEND(self, instr): list_value = self.pop() assert instr.argval > 0 - list.extend(self._stack[-instr.arg].value, list_value) + self._stack[-instr.arg].extend(list_value) def LIST_TO_TUPLE(self, instr): list_value = self.pop() self.push( TupleVariable( - list_value.value, self._graph, DummyTracker([instr.argval]) + list_value.get_wrapped_items(), + self._graph, + DummyTracker([instr.argval]), ) ) diff --git a/symbolic_trace/opcode_translator/executor/variables.py b/symbolic_trace/opcode_translator/executor/variables.py index 1cb939e71..6eb4cdf6d 100644 --- a/symbolic_trace/opcode_translator/executor/variables.py +++ b/symbolic_trace/opcode_translator/executor/variables.py @@ -489,6 +489,10 @@ def __delitem__(self, key): ) del self.value[key] + def override_method_extend(self, data): + self.value.extend(data) + return self + @VariableFactory.register_from_value def from_value(value: Any, graph: FunctionGraph | None, tracker: Tracker): if isinstance(value, list): @@ -679,6 +683,10 @@ def override_method_items(self): item_list, self.graph, DummyTracker([item_list]) ) + def override_method_update(self, data): + self.value.update(data.get_wrapped_items()) + return self + def __getattr__(self, name): name_ = "override_method_" + name if hasattr(self, name_): From 197c204d0f31be01cac80a9c484775f8c39e9221 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Fri, 2 Jun 2023 23:07:56 +0800 Subject: [PATCH 14/18] [opcode] fix LIST_EXTEND --- symbolic_trace/opcode_translator/executor/opcode_executor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/symbolic_trace/opcode_translator/executor/opcode_executor.py b/symbolic_trace/opcode_translator/executor/opcode_executor.py index e8d4853f4..59f8580eb 100644 --- a/symbolic_trace/opcode_translator/executor/opcode_executor.py +++ b/symbolic_trace/opcode_translator/executor/opcode_executor.py @@ -951,7 +951,7 @@ def DICT_MERGE(self, instr): def LIST_EXTEND(self, instr): list_value = self.pop() assert instr.argval > 0 - self._stack[-instr.arg].extend(list_value) + self._stack[-instr.arg].extend(list_value.get_wrapped_items()) def LIST_TO_TUPLE(self, instr): list_value = self.pop() From 1d57fe48371d3580b13c73cb9c37787bce282840 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Fri, 2 Jun 2023 23:09:36 +0800 Subject: [PATCH 15/18] [opcode] fix LIST_EXTEND --- symbolic_trace/opcode_translator/executor/opcode_executor.py | 2 +- symbolic_trace/opcode_translator/executor/variables.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/symbolic_trace/opcode_translator/executor/opcode_executor.py b/symbolic_trace/opcode_translator/executor/opcode_executor.py index 59f8580eb..e8d4853f4 100644 --- a/symbolic_trace/opcode_translator/executor/opcode_executor.py +++ b/symbolic_trace/opcode_translator/executor/opcode_executor.py @@ -951,7 +951,7 @@ def DICT_MERGE(self, instr): def LIST_EXTEND(self, instr): list_value = self.pop() assert instr.argval > 0 - self._stack[-instr.arg].extend(list_value.get_wrapped_items()) + self._stack[-instr.arg].extend(list_value) def LIST_TO_TUPLE(self, instr): list_value = self.pop() diff --git a/symbolic_trace/opcode_translator/executor/variables.py b/symbolic_trace/opcode_translator/executor/variables.py index 6eb4cdf6d..794ab5d6c 100644 --- a/symbolic_trace/opcode_translator/executor/variables.py +++ b/symbolic_trace/opcode_translator/executor/variables.py @@ -490,7 +490,7 @@ def __delitem__(self, key): del self.value[key] def override_method_extend(self, data): - self.value.extend(data) + self.value.extend(data.get_wrapped_items()) return self @VariableFactory.register_from_value From 8fdd415262639018f7cb49443b92dfb9895b52f7 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Sat, 3 Jun 2023 18:16:41 +0800 Subject: [PATCH 16/18] [opcode]Modify error prompt --- symbolic_trace/opcode_translator/executor/opcode_executor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/symbolic_trace/opcode_translator/executor/opcode_executor.py b/symbolic_trace/opcode_translator/executor/opcode_executor.py index e8d4853f4..e40ef2c47 100644 --- a/symbolic_trace/opcode_translator/executor/opcode_executor.py +++ b/symbolic_trace/opcode_translator/executor/opcode_executor.py @@ -945,7 +945,10 @@ def DICT_MERGE(self, instr): assert instr.argval > 0 for key in dict_value.get_wrapped_items().keys(): result = self._stack[-instr.arg].get_wrapped_items().get(key, None) - assert result is None, f"Repeat key: {key}" + if result is None: + raise InnerError( + f"got multiple values for keyword argument '{key}'" + ) self._stack[-instr.arg].update(dict_value) def LIST_EXTEND(self, instr): From fbff686cea4f525f6ff25dba2e5bb38633f371d9 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Sat, 3 Jun 2023 18:29:49 +0800 Subject: [PATCH 17/18] [opcode] fix InnerError --- symbolic_trace/opcode_translator/executor/opcode_executor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/symbolic_trace/opcode_translator/executor/opcode_executor.py b/symbolic_trace/opcode_translator/executor/opcode_executor.py index e40ef2c47..de592e62e 100644 --- a/symbolic_trace/opcode_translator/executor/opcode_executor.py +++ b/symbolic_trace/opcode_translator/executor/opcode_executor.py @@ -945,7 +945,7 @@ def DICT_MERGE(self, instr): assert instr.argval > 0 for key in dict_value.get_wrapped_items().keys(): result = self._stack[-instr.arg].get_wrapped_items().get(key, None) - if result is None: + if result is not None: raise InnerError( f"got multiple values for keyword argument '{key}'" ) From 6b25123ab53fe0d7fb7f68b4a816c8e1d9671833 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Tue, 6 Jun 2023 16:49:32 +0800 Subject: [PATCH 18/18] [opcode] fix IS_OP --- symbolic_trace/opcode_translator/executor/opcode_executor.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/symbolic_trace/opcode_translator/executor/opcode_executor.py b/symbolic_trace/opcode_translator/executor/opcode_executor.py index 2f16f2368..bce0555e0 100644 --- a/symbolic_trace/opcode_translator/executor/opcode_executor.py +++ b/symbolic_trace/opcode_translator/executor/opcode_executor.py @@ -693,8 +693,7 @@ def COMPARE_OP(self, instr): 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() + right, left = self.pop(), self.pop() if instr.argval == 0: self.push(SUPPORT_COMPARE_OP["is"](left, right)) else: