Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

adaptation to Python 3.9 #109

Merged
merged 21 commits into from
Jun 6, 2023
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
15 changes: 9 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@ on:

jobs:
Test:
runs-on: ubuntu-latest
name: Run unit tests and examples
strategy:
fail-fast: false
Copy link
Member Author

@gouzil gouzil Jun 2, 2023

Choose a reason for hiding this comment

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

如果任何矩阵作业失败,GitHub 将不会取消所有正在进行的作业, 说明链接

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

- name: Install python
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: |
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
Expand Down
42 changes: 41 additions & 1 deletion symbolic_trace/opcode_translator/executor/opcode_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -691,6 +690,15 @@ 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
right, left = self.pop(), 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()
Expand Down Expand Up @@ -925,6 +933,38 @@ 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
self._stack[-instr.arg].update(dict_value)

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)
if result is not None:
raise InnerError(
f"got multiple values for keyword argument '{key}'"
)
self._stack[-instr.arg].update(dict_value)

def LIST_EXTEND(self, instr):
list_value = self.pop()
assert instr.argval > 0
self._stack[-instr.arg].extend(list_value)

def LIST_TO_TUPLE(self, instr):
list_value = self.pop()
self.push(
TupleVariable(
list_value.get_wrapped_items(),
self._graph,
DummyTracker([instr.argval]),
)
)

def RETURN_VALUE(self, instr):
assert (
len(self._stack) == 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ def __delitem__(self, key):
)
del self.value[key]

def override_method_extend(self, data):
self.value.extend(data.get_wrapped_items())
return self

@VariableFactory.register_from_value()
def from_value(value: Any, graph: FunctionGraph | None, tracker: Tracker):
if isinstance(value, list):
Expand Down Expand Up @@ -314,6 +318,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):
from .callable import DirectlyCallMethodVariable

Expand Down
12 changes: 11 additions & 1 deletion tests/run_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
export PYTHONPATH=$PYTHONPATH:../
export STRICT_MODE=1

failed_tests=()

for file in ./test_*.py; do
# 检查文件是否为 Python 文件
if [ -f "$file" ]; then
Expand All @@ -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
4 changes: 4 additions & 0 deletions tests/test_10_build_unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
# BUILD_TUPLE_UNPACK_WITH_CALL (new)
# CALL_FUNCTION_EX (new)
# BUILD_MAP_UNPACK (new)
# LIST_EXTEND (new)
# LIST_TO_TUPLE (new)
# DICT_UPDATE (new)
# DICT_MERGE (new)

from __future__ import annotations

Expand Down