Skip to content
Open
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
6 changes: 3 additions & 3 deletions .gitmodules
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
31 changes: 23 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
# ------------------------------------------------------------------------------
Expand All @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

这里是否可以删除


# eigen
if(USE_OMP)
Expand All @@ -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/.*")
Copy link
Contributor

Choose a reason for hiding this comment

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

这里的逻辑应该是

if(NOT USE_CUDA)
  list(FILTER SRC EXCLUDE REGEX ".*runtime/cuda/.*")
  list(FILTER SRC EXCLUDE REGEX ".*ccl/cuda/.*")
endif()

否则会出现编译错误

if(NOT USE_NCCL)
list(FILTER SRC EXCLUDE REGEX ".*infini_train/src/core/ccl/cuda/.*")
endif()
Expand Down Expand Up @@ -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()
20 changes: 20 additions & 0 deletions tests/CMakeLists.txt
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)
161 changes: 161 additions & 0 deletions tests/autograd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Autograd tests
Copy link
Contributor

Choose a reason for hiding this comment

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

这版的风险是新增测试的接入成本和漏配风险都比较高。新增一个普通 autograd CPU 测试,至少要手动写:

add_autograd_test(...)
add_test(...)
set_tests_properties(... LABELS ...)

建议简化。例如把功能整合到一个函数里,新增测试只调用一次;或者考虑使用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
)
Loading
Loading