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
37 changes: 25 additions & 12 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)

# eigen
if(USE_OMP)
Expand All @@ -48,6 +66,10 @@ 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/.*")
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,17 +212,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)
link_infini_train_exe(test_hook)

add_executable(test_precision_check test/hook/test_precision_check.cc)
link_infini_train_exe(test_precision_check)

add_executable(test_lora test/lora/test_lora.cc)
link_infini_train_exe(test_lora)

if(BUILD_TEST)
add_subdirectory(tests)
endif()
26 changes: 26 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Tests CMakeLists.txt
# This file manages the test infrastructure for InfiniTrain

# Include shared test macros (must be before any test subdirectory)
include(${CMAKE_CURRENT_SOURCE_DIR}/common/test_macros.cmake)

# Common test utilities
add_subdirectory(common)

# Tensor tests
add_subdirectory(tensor)

# Optimizer tests
add_subdirectory(optimizer)

# Autograd operator tests
add_subdirectory(autograd)

# LoRA tests
add_subdirectory(lora)

# Hook tests
add_subdirectory(hook)

# Slow label tests
add_subdirectory(slow)
56 changes: 56 additions & 0 deletions tests/autograd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# ============================================================================
# Autograd tests
# ============================================================================
# 重构版本:使用 infini_train_add_test 宏简化配置
#
# 新增测试只需 1 行:
# infini_train_add_test(test_name SOURCES test_name.cc LABELS cpu)
# ============================================================================

# -----------------------------------------------------------------------------
# Elementwise tests
# -----------------------------------------------------------------------------
infini_train_add_test(test_autograd_elementwise_forward SOURCES test_autograd_elementwise_forward.cc LABELS cpu)
infini_train_add_test(test_autograd_elementwise_backward SOURCES test_autograd_elementwise_backward.cc LABELS cpu)

# -----------------------------------------------------------------------------
# Matmul tests
# -----------------------------------------------------------------------------
infini_train_add_test(test_autograd_matmul_forward SOURCES test_autograd_matmul_forward.cc LABELS cpu)
infini_train_add_test(test_autograd_matmul_backward SOURCES test_autograd_matmul_backward.cc LABELS cpu)

# -----------------------------------------------------------------------------
# Reduction tests
# -----------------------------------------------------------------------------
infini_train_add_test(test_autograd_reduction_forward SOURCES test_autograd_reduction_forward.cc LABELS cpu)
infini_train_add_test(test_autograd_reduction_backward SOURCES test_autograd_reduction_backward.cc LABELS cpu)

# -----------------------------------------------------------------------------
# Linear tests
# -----------------------------------------------------------------------------
infini_train_add_test(test_autograd_linear_forward SOURCES test_autograd_linear_forward.cc LABELS cpu)
infini_train_add_test(test_autograd_linear_backward SOURCES test_autograd_linear_backward.cc LABELS cpu)

# -----------------------------------------------------------------------------
# Softmax tests
# -----------------------------------------------------------------------------
infini_train_add_test(test_autograd_softmax_forward SOURCES test_autograd_softmax_forward.cc LABELS cpu)
infini_train_add_test(test_autograd_softmax_backward SOURCES test_autograd_softmax_backward.cc LABELS cpu)

# -----------------------------------------------------------------------------
# Transform tests
# -----------------------------------------------------------------------------
infini_train_add_test(test_autograd_transform_forward SOURCES test_autograd_transform_forward.cc LABELS cpu)
infini_train_add_test(test_autograd_transform_backward SOURCES test_autograd_transform_backward.cc LABELS cpu)

# -----------------------------------------------------------------------------
# Normalization tests
# -----------------------------------------------------------------------------
infini_train_add_test(test_autograd_normalization_forward SOURCES test_autograd_normalization_forward.cc LABELS cpu)
infini_train_add_test(test_autograd_normalization_backward SOURCES test_autograd_normalization_backward.cc LABELS cpu)

# -----------------------------------------------------------------------------
# Legacy combined tests
# 注意:使用 gtest_discover_tests,所有 TEST_F 都会被自动发现
# -----------------------------------------------------------------------------
infini_train_add_test(test_autograd_legacy SOURCES test_autograd.cc LABELS cpu cuda distributed)
Loading