-
Notifications
You must be signed in to change notification settings - Fork 44
【训练营】基于 CTest + gtest 的测试体系搭建与工程化集成 #120
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
3db2c1f
418aaab
3939679
4897962
3bbf2f2
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 |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| [submodule "third_party/glog"] | ||
| path = third_party/glog | ||
| url = git@github.com:google/glog.git | ||
| url = https://github.com/google/glog.git | ||
| [submodule "third_party/gflags"] | ||
| path = third_party/gflags | ||
| url = git@github.com:gflags/gflags.git | ||
| url = https://github.com/gflags/gflags.git | ||
| [submodule "third_party/eigen"] | ||
| path = third_party/eigen | ||
| url = git@github.com:InfiniTensor/eigen-mirror.git | ||
| url = https://github.com/eigenteam/eigen-git-mirror.git |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ option(USE_CUDA "Support NVIDIA CUDA" OFF) | |
| option(PROFILE_MODE "ENABLE PROFILE MODE" OFF) | ||
| option(USE_OMP "Use OpenMP as backend for Eigen" ON) | ||
| option(USE_NCCL "Build project for distributed running" ON) | ||
| option(BUILD_TEST "Build InfiniTrain tests" ON) | ||
|
|
||
| project(infini_train VERSION 0.5.0 LANGUAGES CXX) | ||
|
|
||
|
|
@@ -14,6 +15,21 @@ set(CMAKE_CXX_EXTENSIONS OFF) | |
| # Generate compile_commands.json | ||
| set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| # GoogleTest (FetchContent) | ||
| # ------------------------------------------------------------------------------ | ||
| if(BUILD_TEST) | ||
| include(FetchContent) | ||
| FetchContent_Declare( | ||
| googletest | ||
| GIT_REPOSITORY https://github.com/google/googletest.git | ||
| GIT_TAG v1.14.0 | ||
| ) | ||
| set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | ||
| FetchContent_MakeAvailable(googletest) | ||
| enable_testing() | ||
| endif() | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| # Third-party deps | ||
| # ------------------------------------------------------------------------------ | ||
|
|
@@ -26,7 +42,9 @@ include_directories(${gflags_SOURCE_DIR}/include) | |
| set(WITH_GFLAGS OFF CACHE BOOL "Disable glog finding system gflags" FORCE) | ||
| set(WITH_GTEST OFF CACHE BOOL "Disable glog finding system gtest" FORCE) | ||
| add_subdirectory(third_party/glog) | ||
| add_compile_definitions(GLOG_USE_GLOG_EXPORT=1) | ||
| include_directories(${glog_SOURCE_DIR}/src) | ||
| include_directories(${glog_BINARY_DIR}/glog) | ||
|
|
||
| # eigen | ||
| if(USE_OMP) | ||
|
|
@@ -48,6 +66,8 @@ endif() | |
| # Framework core sources (*.cc), excluding cpu kernels (they are built separately) | ||
| file(GLOB_RECURSE SRC ${PROJECT_SOURCE_DIR}/infini_train/src/*.cc) | ||
| list(FILTER SRC EXCLUDE REGEX ".*kernels/cpu/.*") | ||
| list(FILTER SRC EXCLUDE REGEX ".*runtime/cuda/.*") | ||
| list(FILTER SRC EXCLUDE REGEX ".*ccl/cuda/.*") | ||
|
Contributor
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(NOT USE_NCCL) | ||
| list(FILTER SRC EXCLUDE REGEX ".*infini_train/src/core/ccl/cuda/.*") | ||
| endif() | ||
|
|
@@ -190,13 +210,8 @@ add_executable(llama3 | |
| ) | ||
| link_infini_train_exe(llama3) | ||
|
|
||
| # Tools | ||
| add_subdirectory(tools/infini_run) | ||
| set_target_properties(infini_run PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) | ||
|
|
||
| # Tests | ||
| add_executable(test_hook test/hook/test_hook.cc) | ||
| target_link_libraries(test_hook infini_train) | ||
|
|
||
| add_executable(test_precision_check test/hook/test_precision_check.cc) | ||
| target_link_libraries(test_precision_check infini_train) | ||
| if(BUILD_TEST) | ||
| add_subdirectory(tests) | ||
| endif() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Tests CMakeLists.txt | ||
| # This file manages the test infrastructure for InfiniTrain | ||
|
|
||
| # Add test subdirectories | ||
| add_subdirectory(common) | ||
|
|
||
| # Tensor tests | ||
| add_subdirectory(tensor) | ||
|
|
||
| # Optimizer tests | ||
| add_subdirectory(optimizer) | ||
|
|
||
| # Autograd operator tests | ||
| add_subdirectory(autograd) | ||
|
|
||
| # Hook tests | ||
| add_subdirectory(hook) | ||
|
|
||
| # Slow label tests | ||
| add_subdirectory(slow) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| # Autograd tests | ||
|
Contributor
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. 这版的风险是新增测试的接入成本和漏配风险都比较高。新增一个普通 autograd CPU 测试,至少要手动写: 建议简化。例如把功能整合到一个函数里,新增测试只调用一次;或者考虑使用gtest_discover_tests,不用再手工写 add_test() 和 set_tests_properties() |
||
|
|
||
| # Helper function to add autograd test executable | ||
| function(add_autograd_test name sources) | ||
| add_executable(${name} ${sources}) | ||
| target_link_libraries(${name} | ||
| PRIVATE | ||
| GTest::gtest | ||
| GTest::gtest_main | ||
| ) | ||
| target_include_directories(${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../common) | ||
| target_link_libraries(${name} PRIVATE | ||
| "-Wl,--whole-archive" | ||
| infini_train | ||
| infini_train_cpu_kernels | ||
| "-Wl,--no-whole-archive" | ||
| ) | ||
| endfunction() | ||
|
|
||
| # Elementwise forward tests | ||
| add_autograd_test(test_autograd_elementwise_forward | ||
| test_autograd_elementwise_forward.cc | ||
| ) | ||
| add_test(NAME autograd_elementwise_forward COMMAND test_autograd_elementwise_forward) | ||
| set_tests_properties(autograd_elementwise_forward PROPERTIES LABELS "cpu") | ||
|
|
||
| # Elementwise backward tests | ||
| add_autograd_test(test_autograd_elementwise_backward | ||
| test_autograd_elementwise_backward.cc | ||
| ) | ||
| add_test(NAME autograd_elementwise_backward COMMAND test_autograd_elementwise_backward) | ||
| set_tests_properties(autograd_elementwise_backward PROPERTIES LABELS "cpu") | ||
|
|
||
| # Matmul forward tests | ||
| add_autograd_test(test_autograd_matmul_forward | ||
| test_autograd_matmul_forward.cc | ||
| ) | ||
| add_test(NAME autograd_matmul_forward COMMAND test_autograd_matmul_forward) | ||
| set_tests_properties(autograd_matmul_forward PROPERTIES LABELS "cpu") | ||
|
|
||
| # Matmul backward tests | ||
| add_autograd_test(test_autograd_matmul_backward | ||
| test_autograd_matmul_backward.cc | ||
| ) | ||
| add_test(NAME autograd_matmul_backward COMMAND test_autograd_matmul_backward) | ||
| set_tests_properties(autograd_matmul_backward PROPERTIES LABELS "cpu") | ||
|
|
||
| # Reduction forward tests | ||
| add_autograd_test(test_autograd_reduction_forward | ||
| test_autograd_reduction_forward.cc | ||
| ) | ||
| add_test(NAME autograd_reduction_forward COMMAND test_autograd_reduction_forward) | ||
| set_tests_properties(autograd_reduction_forward PROPERTIES LABELS "cpu") | ||
|
|
||
| # Reduction backward tests | ||
| add_autograd_test(test_autograd_reduction_backward | ||
| test_autograd_reduction_backward.cc | ||
| ) | ||
| add_test(NAME autograd_reduction_backward COMMAND test_autograd_reduction_backward) | ||
| set_tests_properties(autograd_reduction_backward PROPERTIES LABELS "cpu") | ||
|
|
||
| # Linear forward tests | ||
| add_autograd_test(test_autograd_linear_forward | ||
| test_autograd_linear_forward.cc | ||
| ) | ||
| add_test(NAME autograd_linear_forward COMMAND test_autograd_linear_forward) | ||
| set_tests_properties(autograd_linear_forward PROPERTIES LABELS "cpu") | ||
|
|
||
| # Linear backward tests | ||
| add_autograd_test(test_autograd_linear_backward | ||
| test_autograd_linear_backward.cc | ||
| ) | ||
| add_test(NAME autograd_linear_backward COMMAND test_autograd_linear_backward) | ||
| set_tests_properties(autograd_linear_backward PROPERTIES LABELS "cpu") | ||
|
|
||
| # Softmax forward tests | ||
| add_autograd_test(test_autograd_softmax_forward | ||
| test_autograd_softmax_forward.cc | ||
| ) | ||
| add_test(NAME autograd_softmax_forward COMMAND test_autograd_softmax_forward) | ||
| set_tests_properties(autograd_softmax_forward PROPERTIES LABELS "cpu") | ||
|
|
||
| # Softmax backward tests | ||
| add_autograd_test(test_autograd_softmax_backward | ||
| test_autograd_softmax_backward.cc | ||
| ) | ||
| add_test(NAME autograd_softmax_backward COMMAND test_autograd_softmax_backward) | ||
| set_tests_properties(autograd_softmax_backward PROPERTIES LABELS "cpu") | ||
|
|
||
| # Transform forward tests | ||
| add_autograd_test(test_autograd_transform_forward | ||
| test_autograd_transform_forward.cc | ||
| ) | ||
| add_test(NAME autograd_transform_forward COMMAND test_autograd_transform_forward) | ||
| set_tests_properties(autograd_transform_forward PROPERTIES LABELS "cpu") | ||
|
|
||
| # Transform backward tests | ||
| add_autograd_test(test_autograd_transform_backward | ||
| test_autograd_transform_backward.cc | ||
| ) | ||
| add_test(NAME autograd_transform_backward COMMAND test_autograd_transform_backward) | ||
| set_tests_properties(autograd_transform_backward PROPERTIES LABELS "cpu") | ||
|
|
||
| # Normalization forward tests | ||
| add_autograd_test(test_autograd_normalization_forward | ||
| test_autograd_normalization_forward.cc | ||
| ) | ||
| add_test(NAME autograd_normalization_forward COMMAND test_autograd_normalization_forward) | ||
| set_tests_properties(autograd_normalization_forward PROPERTIES LABELS "cpu") | ||
|
|
||
| # Normalization backward tests | ||
| add_autograd_test(test_autograd_normalization_backward | ||
| test_autograd_normalization_backward.cc | ||
| ) | ||
| add_test(NAME autograd_normalization_backward COMMAND test_autograd_normalization_backward) | ||
| set_tests_properties(autograd_normalization_backward PROPERTIES LABELS "cpu") | ||
|
|
||
| # Legacy combined tests (for backward compatibility) | ||
| add_executable(test_autograd_legacy | ||
| test_autograd.cc | ||
| ) | ||
| target_link_libraries(test_autograd_legacy | ||
| PRIVATE | ||
| GTest::gtest | ||
| GTest::gtest_main | ||
| ) | ||
| target_include_directories(test_autograd_legacy PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../common) | ||
| target_link_libraries(test_autograd_legacy PRIVATE | ||
| "-Wl,--whole-archive" | ||
| infini_train | ||
| infini_train_cpu_kernels | ||
| "-Wl,--no-whole-archive" | ||
| ) | ||
| add_test(NAME autograd_forward_legacy COMMAND test_autograd_legacy --gtest_filter=AutogradForwardTest.*) | ||
| set_tests_properties(autograd_forward_legacy PROPERTIES LABELS "cpu") | ||
| add_test(NAME autograd_backward_legacy COMMAND test_autograd_legacy --gtest_filter=AutogradBackwardTest.*) | ||
| set_tests_properties(autograd_backward_legacy PROPERTIES LABELS "cpu") | ||
| add_test(NAME autograd_cuda_legacy COMMAND test_autograd_legacy --gtest_filter=AutogradCudaTest.*) | ||
| set_tests_properties(autograd_cuda_legacy PROPERTIES LABELS "cuda") | ||
| add_test(NAME autograd_distributed_legacy COMMAND test_autograd_legacy --gtest_filter=AutogradDistributedTest.*) | ||
| set_tests_properties(autograd_distributed_legacy PROPERTIES LABELS "cuda;distributed") | ||
|
|
||
| # Aggregate target for convenient builds | ||
| add_custom_target(test_autograd | ||
| DEPENDS | ||
| test_autograd_elementwise_forward | ||
| test_autograd_elementwise_backward | ||
| test_autograd_matmul_forward | ||
| test_autograd_matmul_backward | ||
| test_autograd_reduction_forward | ||
| test_autograd_reduction_backward | ||
| test_autograd_linear_forward | ||
| test_autograd_linear_backward | ||
| test_autograd_softmax_forward | ||
| test_autograd_softmax_backward | ||
| test_autograd_transform_forward | ||
| test_autograd_transform_backward | ||
| test_autograd_normalization_forward | ||
| test_autograd_normalization_backward | ||
| test_autograd_legacy | ||
| ) | ||
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.
这里是否可以删除