From 4370a91a70e4fcb0524de64e9e9df8d3e53aa598 Mon Sep 17 00:00:00 2001 From: Xiaoxu Chen Date: Tue, 10 Jan 2023 21:01:34 +0800 Subject: [PATCH] reorganize the prim unittests struct (#49679) --- .../fluid/tests/unittests/prim/CMakeLists.txt | 4 +-- .../fluid/tests/unittests/prim/README.txt | 34 +++++++++++++++++++ .../prim/{api/prim => comp}/CMakeLists.txt | 1 - .../prim/{api => prim}/CMakeLists.txt | 4 +-- .../{api/comp => prim/vjp}/CMakeLists.txt | 5 ++- .../vjp/eager}/CMakeLists.txt | 0 .../vjp/eager}/test_eager_tanh_grad_comp.py | 0 .../vjp/static}/CMakeLists.txt | 0 .../vjp/static}/test_tanh_grad_comp.py | 0 9 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 python/paddle/fluid/tests/unittests/prim/README.txt rename python/paddle/fluid/tests/unittests/prim/{api/prim => comp}/CMakeLists.txt (83%) rename python/paddle/fluid/tests/unittests/prim/{api => prim}/CMakeLists.txt (71%) rename python/paddle/fluid/tests/unittests/prim/{api/comp => prim/vjp}/CMakeLists.txt (69%) rename python/paddle/fluid/tests/unittests/prim/{api/comp/eager_test => prim/vjp/eager}/CMakeLists.txt (100%) rename python/paddle/fluid/tests/unittests/prim/{api/comp/eager_test => prim/vjp/eager}/test_eager_tanh_grad_comp.py (100%) rename python/paddle/fluid/tests/unittests/prim/{api/comp/static_test => prim/vjp/static}/CMakeLists.txt (100%) rename python/paddle/fluid/tests/unittests/prim/{api/comp/static_test => prim/vjp/static}/test_tanh_grad_comp.py (100%) diff --git a/python/paddle/fluid/tests/unittests/prim/CMakeLists.txt b/python/paddle/fluid/tests/unittests/prim/CMakeLists.txt index b3799684a9b..9ec3cf15454 100644 --- a/python/paddle/fluid/tests/unittests/prim/CMakeLists.txt +++ b/python/paddle/fluid/tests/unittests/prim/CMakeLists.txt @@ -3,10 +3,10 @@ file( RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "test_*.py") string(REPLACE ".py" "" TEST_OPS "${TEST_OPS}") -set(GC_ENVS FLAGS_eager_delete_tensor_gb=0.0) foreach(TEST_OP ${TEST_OPS}) py_test_modules(${TEST_OP} MODULES ${TEST_OP} ENVS ${GC_ENVS}) endforeach() -add_subdirectory(api) +add_subdirectory(comp) +add_subdirectory(prim) diff --git a/python/paddle/fluid/tests/unittests/prim/README.txt b/python/paddle/fluid/tests/unittests/prim/README.txt new file mode 100644 index 00000000000..ed047326355 --- /dev/null +++ b/python/paddle/fluid/tests/unittests/prim/README.txt @@ -0,0 +1,34 @@ +# Prim + +Test composite and primitive API and related autodiff rules. + + +## Package Structure + +- comp(abbr for composite): + + Test composite API which is composed of primitive api, but not include the autodiff rules for primitive api. + +- prim(abbr for primitive): + + Test primitive api and autodiff rules. + + - vjp: Test vjp rules. + + - eager: Test vjp rules in eager mode. + - static: Test vjp rules in static mode. + + - jvp(TODO): Test jvp rules. + + +## How to + +- Forward API and First-rder Autodiff + + Compare numerical value with raw phi operators using tools such as `np.testing.assert_allclose` + + +- Higher-order Autodiff + + Compare numerical value with the result computed by finite difference. Tool + used for computing Higher-order finite difference will be provided in the future. diff --git a/python/paddle/fluid/tests/unittests/prim/api/prim/CMakeLists.txt b/python/paddle/fluid/tests/unittests/prim/comp/CMakeLists.txt similarity index 83% rename from python/paddle/fluid/tests/unittests/prim/api/prim/CMakeLists.txt rename to python/paddle/fluid/tests/unittests/prim/comp/CMakeLists.txt index 863a484c466..72c6bbd7d05 100644 --- a/python/paddle/fluid/tests/unittests/prim/api/prim/CMakeLists.txt +++ b/python/paddle/fluid/tests/unittests/prim/comp/CMakeLists.txt @@ -3,7 +3,6 @@ file( RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "test_*.py") string(REPLACE ".py" "" TEST_OPS "${TEST_OPS}") -set(GC_ENVS FLAGS_eager_delete_tensor_gb=0.0) foreach(TEST_OP ${TEST_OPS}) py_test_modules(${TEST_OP} MODULES ${TEST_OP} ENVS ${GC_ENVS}) diff --git a/python/paddle/fluid/tests/unittests/prim/api/CMakeLists.txt b/python/paddle/fluid/tests/unittests/prim/prim/CMakeLists.txt similarity index 71% rename from python/paddle/fluid/tests/unittests/prim/api/CMakeLists.txt rename to python/paddle/fluid/tests/unittests/prim/prim/CMakeLists.txt index 49b11c74857..db4822bce3f 100644 --- a/python/paddle/fluid/tests/unittests/prim/api/CMakeLists.txt +++ b/python/paddle/fluid/tests/unittests/prim/prim/CMakeLists.txt @@ -3,11 +3,9 @@ file( RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "test_*.py") string(REPLACE ".py" "" TEST_OPS "${TEST_OPS}") -set(GC_ENVS FLAGS_eager_delete_tensor_gb=0.0) foreach(TEST_OP ${TEST_OPS}) py_test_modules(${TEST_OP} MODULES ${TEST_OP} ENVS ${GC_ENVS}) endforeach() -add_subdirectory(comp) -add_subdirectory(prim) +add_subdirectory(vjp) diff --git a/python/paddle/fluid/tests/unittests/prim/api/comp/CMakeLists.txt b/python/paddle/fluid/tests/unittests/prim/prim/vjp/CMakeLists.txt similarity index 69% rename from python/paddle/fluid/tests/unittests/prim/api/comp/CMakeLists.txt rename to python/paddle/fluid/tests/unittests/prim/prim/vjp/CMakeLists.txt index 1cf6c11760f..d71096db0a1 100644 --- a/python/paddle/fluid/tests/unittests/prim/api/comp/CMakeLists.txt +++ b/python/paddle/fluid/tests/unittests/prim/prim/vjp/CMakeLists.txt @@ -3,11 +3,10 @@ file( RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "test_*.py") string(REPLACE ".py" "" TEST_OPS "${TEST_OPS}") -set(GC_ENVS FLAGS_eager_delete_tensor_gb=0.0) foreach(TEST_OP ${TEST_OPS}) py_test_modules(${TEST_OP} MODULES ${TEST_OP} ENVS ${GC_ENVS}) endforeach() -add_subdirectory(eager_test) -add_subdirectory(static_test) +add_subdirectory(eager) +add_subdirectory(static) diff --git a/python/paddle/fluid/tests/unittests/prim/api/comp/eager_test/CMakeLists.txt b/python/paddle/fluid/tests/unittests/prim/prim/vjp/eager/CMakeLists.txt similarity index 100% rename from python/paddle/fluid/tests/unittests/prim/api/comp/eager_test/CMakeLists.txt rename to python/paddle/fluid/tests/unittests/prim/prim/vjp/eager/CMakeLists.txt diff --git a/python/paddle/fluid/tests/unittests/prim/api/comp/eager_test/test_eager_tanh_grad_comp.py b/python/paddle/fluid/tests/unittests/prim/prim/vjp/eager/test_eager_tanh_grad_comp.py similarity index 100% rename from python/paddle/fluid/tests/unittests/prim/api/comp/eager_test/test_eager_tanh_grad_comp.py rename to python/paddle/fluid/tests/unittests/prim/prim/vjp/eager/test_eager_tanh_grad_comp.py diff --git a/python/paddle/fluid/tests/unittests/prim/api/comp/static_test/CMakeLists.txt b/python/paddle/fluid/tests/unittests/prim/prim/vjp/static/CMakeLists.txt similarity index 100% rename from python/paddle/fluid/tests/unittests/prim/api/comp/static_test/CMakeLists.txt rename to python/paddle/fluid/tests/unittests/prim/prim/vjp/static/CMakeLists.txt diff --git a/python/paddle/fluid/tests/unittests/prim/api/comp/static_test/test_tanh_grad_comp.py b/python/paddle/fluid/tests/unittests/prim/prim/vjp/static/test_tanh_grad_comp.py similarity index 100% rename from python/paddle/fluid/tests/unittests/prim/api/comp/static_test/test_tanh_grad_comp.py rename to python/paddle/fluid/tests/unittests/prim/prim/vjp/static/test_tanh_grad_comp.py -- GitLab