-
Notifications
You must be signed in to change notification settings - Fork 96
[API Compatibility] Change compatibility apis to ChangePrefixMatcher, inject paddle.enable_compat(), fix test environment context pollution -part #895
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
base: master
Are you sure you want to change the base?
Changes from all commits
321f32b
9bf7bfb
204c7a1
edb4042
1ff4284
020ce44
e584efa
bfff52a
3dcd2a1
81a3c07
8170d4f
f04bbf3
9bef7f9
838a8a5
f7e1c04
5fe7de1
14d8aeb
e0808c4
6bd002d
f8f344a
961af0c
d8f6e9d
62739d7
7bb47d1
67be297
1f774a4
9c52c23
e39b042
8ee2f99
22d59d6
7f11a54
5362b97
1f99f24
d9a9a74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -395,7 +395,11 @@ def get_paddle_class_nodes(self, func, args, kwargs): | |
| if self.transformer.mode == "min": | ||
| self.paddle_api = astor.to_source(func).strip("\n") | ||
| else: | ||
| self.parse_func(func) | ||
| func_str = astor.to_source(func).strip("\n") | ||
| paddle_api = self.get_paddle_api() | ||
| paddle_class = func_str.rsplit(".", 1)[0] | ||
| paddle_class_api = paddle_api.rsplit(".", 1)[0] | ||
| self.paddle_api = paddle_api.replace(paddle_class_api, paddle_class, 1) | ||
|
|
||
| args = self.parse_args(args) | ||
| kwargs = self.parse_kwargs(kwargs, allow_none=True) | ||
|
|
@@ -5799,7 +5803,9 @@ def reduce_scatter_tensor(output, input, op, group, async_op): | |
| if input.shape[0] == world_size: | ||
| input_list = paddle.unstack(input, axis=0) | ||
| else: | ||
| input_list = paddle.split(input, num_or_sections=world_size, axis=0) | ||
| input_list = paddle.tensor.split( | ||
|
Collaborator
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. 这个又是有啥bug不修吗 |
||
| input, num_or_sections=world_size, axis=0 | ||
| ) | ||
| paddle.distributed.reduce_scatter(output, input_list, op, group, async_op) | ||
| """ | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,40 +39,40 @@ echo '************************************************************************** | |
| echo "Checking code gpu unit test by pytest ..." | ||
| set +e | ||
|
|
||
| ISOLATED_TESTS=( | ||
| tests/test_cuda_stream.py | ||
| tests/test_cuda_CUDAGraph.py | ||
| tests/test_cuda_set_stream.py | ||
| tests/test_set_num_interop_threads.py | ||
| ) | ||
|
|
||
| PYTEST_IGNORE=( | ||
|
Collaborator
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. 这里分两批跑,第一次跑特定名单,第二次跑其他的 |
||
| --ignore=tests/test_hub_download_url_to_file.py | ||
| --ignore=tests/test_hub_help.py | ||
| --ignore=tests/test_hub_list.py | ||
| --ignore=tests/test_hub_load.py | ||
| --ignore=tests/test_hub_load_state_dict_from_url.py | ||
| ) | ||
| for test_file in "${ISOLATED_TESTS[@]}"; do | ||
| PYTEST_IGNORE+=(--ignore="${test_file}") | ||
| done | ||
|
|
||
| # Run test_cuda_stream.py separately and FIRST (GPU state is clean), | ||
| # as it can segfault when run after other GPU tests (Paddle FullKernel issue). | ||
| # Running in isolation prevents the segfault from killing the entire test batch. | ||
| python -m pytest -v -s -p no:warnings tests/test_cuda_stream.py 2>&1 | tee pytest.log | ||
| stream_exit=${PIPESTATUS[0]} | ||
| python -m pytest -v -s -p no:warnings "${ISOLATED_TESTS[@]}" \ | ||
| -n 1 --reruns=3 2>&1 | tee pytest.log | ||
| isolated_errors=${PIPESTATUS[0]} | ||
|
|
||
| # Run test_cuda_CUDAGraph.py in its own process as well: CUDA graph | ||
| # capture/replay leaves Paddle GPU state that can natively crash later | ||
| # AMP tests (e.g. test_cuda_amp_GradScaler) in the same pytest worker. | ||
| python -m pytest -v -s -p no:warnings tests/test_cuda_CUDAGraph.py 2>&1 | tee -a pytest.log | ||
| cudagraph_exit=${PIPESTATUS[0]} | ||
|
|
||
| python -m pytest -v -s -p no:warnings "${PYTEST_IGNORE[@]}" --ignore=tests/test_cuda_stream.py --ignore=tests/test_cuda_CUDAGraph.py -n 1 --reruns=3 ./tests 2>&1 | tee -a pytest.log | ||
| python -m pytest -v -s -p no:warnings "${PYTEST_IGNORE[@]}" \ | ||
| -n 1 --reruns=3 ./tests 2>&1 | tee -a pytest.log | ||
| check_errors=${PIPESTATUS[0]} | ||
| if [ ${check_errors} -ne 0 ]; then | ||
| echo "Rerun GPU unit test" | ||
| python -m pytest -v -s -p no:warnings "${PYTEST_IGNORE[@]}" --ignore=tests/test_cuda_stream.py --ignore=tests/test_cuda_CUDAGraph.py -n 1 --lf ./tests 2>&1 | tee -a pytest.log | ||
| python -m pytest -v -s -p no:warnings "${PYTEST_IGNORE[@]}" \ | ||
| -n 1 --lf ./tests 2>&1 | tee -a pytest.log | ||
| check_errors=${PIPESTATUS[0]} | ||
| fi | ||
|
|
||
| # Propagate isolated test failures if any | ||
| if [ ${stream_exit} -ne 0 ]; then | ||
| check_errors=${stream_exit} | ||
| fi | ||
| if [ ${cudagraph_exit} -ne 0 ]; then | ||
| check_errors=${cudagraph_exit} | ||
| if [ ${isolated_errors} -ne 0 ]; then | ||
| check_errors=${isolated_errors} | ||
| fi | ||
|
|
||
| echo '******************************************************************************' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| import os | ||
| import re | ||
| import sys | ||
| from contextlib import nullcontext | ||
|
Collaborator
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. 现在为啥还需要搞这些guard?目前已经不影响torch的计算了吧 |
||
|
|
||
| import numpy as np | ||
|
|
||
|
|
@@ -24,6 +25,13 @@ | |
| from paconvert.converter import Converter | ||
|
|
||
|
|
||
| def _pytorch_exec_guard(): | ||
| paddle = sys.modules.get("paddle") | ||
| if paddle is None: | ||
| return nullcontext() | ||
| return paddle.use_compat_guard(enable=False) | ||
|
|
||
|
|
||
| class APIBase(object): | ||
| def __init__(self, pytorch_api) -> None: | ||
| """ | ||
|
|
@@ -87,51 +95,59 @@ def run( | |
| elif compared_tensor_names: | ||
| pytorch_ns = {} | ||
| try: | ||
| exec(pytorch_code, pytorch_ns) | ||
| with _pytorch_exec_guard(): | ||
| exec(pytorch_code, pytorch_ns) | ||
| except Exception as e: | ||
| raise RuntimeError(f"Failed to execute pytorch code:\n{e}") | ||
| pytorch_result = [pytorch_ns[name] for name in compared_tensor_names] | ||
| pytorch_ns.clear() | ||
|
|
||
| paddle_ns = {} | ||
| try: | ||
| exec(paddle_code, paddle_ns) | ||
| except Exception as e: | ||
| raise RuntimeError(f"Failed to execute paddle code:\n{e}") | ||
| paddle_result = [paddle_ns[name] for name in compared_tensor_names] | ||
| paddle_ns.clear() | ||
| import paddle | ||
|
|
||
| for i in range(len(compared_tensor_names)): | ||
| paddle_ns = {} | ||
| with paddle.use_compat_guard(enable=False): | ||
| try: | ||
| self.compare( | ||
| self.pytorch_api, | ||
| pytorch_result[i], | ||
| paddle_result[i], | ||
| check_value, | ||
| check_shape, | ||
| check_dtype, | ||
| check_stop_gradient, | ||
| rtol, | ||
| atol, | ||
| ) | ||
| exec(paddle_code, paddle_ns) | ||
| except Exception as e: | ||
| raise AssertionError(f"Unable to align results: {e}") | ||
| raise RuntimeError(f"Failed to execute paddle code:\n{e}") | ||
| paddle_result = [paddle_ns[name] for name in compared_tensor_names] | ||
| paddle_ns.clear() | ||
|
|
||
| for i in range(len(compared_tensor_names)): | ||
| try: | ||
| self.compare( | ||
| self.pytorch_api, | ||
| pytorch_result[i], | ||
| paddle_result[i], | ||
| check_value, | ||
| check_shape, | ||
| check_dtype, | ||
| check_stop_gradient, | ||
| rtol, | ||
| atol, | ||
| ) | ||
| except Exception as e: | ||
| raise AssertionError(f"Unable to align results: {e}") | ||
| else: | ||
| pytorch_ns = {} | ||
| try: | ||
| exec(pytorch_code, pytorch_ns) | ||
| with _pytorch_exec_guard(): | ||
| exec(pytorch_code, pytorch_ns) | ||
| except Exception as e: | ||
| raise RuntimeError(f"Failed to execute pytorch code:\n{e}") | ||
| finally: | ||
| pytorch_ns.clear() | ||
|
|
||
| import paddle | ||
|
|
||
| paddle_ns = {} | ||
| try: | ||
| exec(paddle_code, paddle_ns) | ||
| except Exception as e: | ||
| raise RuntimeError(f"Failed to execute paddle code:\n{e}") | ||
| finally: | ||
| paddle_ns.clear() | ||
| with paddle.use_compat_guard(enable=False): | ||
| try: | ||
| exec(paddle_code, paddle_ns) | ||
| except Exception as e: | ||
| raise RuntimeError(f"Failed to execute paddle code:\n{e}") | ||
| finally: | ||
| paddle_ns.clear() | ||
|
|
||
| def compare( | ||
| self, | ||
|
|
||
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.
你为啥不直接修正parse_func呢,修问题根源