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
53 changes: 12 additions & 41 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ 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/.*")
# CLI flags are opt-in: linking the core must not register names such as
# --device or --batch_size that applications may define themselves.
list(FILTER SRC EXCLUDE REGEX ".*/training/arguments\\.cc$")

# Exclude backend-specific runtime/ccl translation units when the corresponding
# backend is disabled. This keeps each build self-contained and avoids pulling
Expand Down Expand Up @@ -228,52 +231,20 @@ link_infini_train_exe(infini_train_executable)
add_library(InfiniTrain::infini_train_executable ALIAS infini_train_executable)
unset(_infini_train_executable_archives)

# ------------------------------------------------------------------------------
# Training CLI (opt-in for applications)
# ------------------------------------------------------------------------------

add_library(infini_train_training_cli STATIC infini_train/src/training/arguments.cc)
add_library(InfiniTrain::training_cli ALIAS infini_train_training_cli)
target_link_libraries(infini_train_training_cli PUBLIC InfiniTrain::infini_train)

# ------------------------------------------------------------------------------
# Examples
# ------------------------------------------------------------------------------

if(PROJECT_IS_TOP_LEVEL)
add_executable(mnist
example/mnist/main.cc
example/mnist/dataset.cc
example/mnist/net.cc
)
link_infini_train_exe(mnist)

add_executable(gpt2
example/gpt2/main.cc
example/common/tiny_shakespeare_dataset.cc
example/common/utils.cc
example/common/tokenizer.cc
example/gpt2/checkpoint_loader.cc
)
link_infini_train_exe(gpt2)

add_executable(mixtral
example/mixtral/main.cc
example/common/tiny_shakespeare_dataset.cc
example/common/utils.cc
example/mixtral/checkpoint_loader.cc
)
link_infini_train_exe(mixtral)

add_executable(llama3
example/llama3/main.cc
example/common/tiny_shakespeare_dataset.cc
example/common/utils.cc
example/common/tokenizer.cc
example/llama3/checkpoint_loader.cc
)
link_infini_train_exe(llama3)

add_executable(qwen3
example/qwen3/main.cc
example/common/tiny_shakespeare_dataset.cc
example/common/utils.cc
example/qwen3/checkpoint_loader.cc
example/common/tokenizer.cc
)
link_infini_train_exe(qwen3)
add_subdirectory(example)
endif()

# Tools
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ HF_TOKEN=hf_xxx \

#### Model Examples

GPT-2, LLaMA3, Qwen3, and Mixtral share the `pretrain_gpt` training program.
Model presets are selected with `--flagfile=example/<model>/train.flags`;
subsequent CLI options override preset values. The named executables load
`configs/<model>/train.flags` beside the binary automatically.

The generated files can be passed directly to the corresponding executables:

##### MNIST
Expand Down
51 changes: 51 additions & 0 deletions cmake/gpt_examples.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
include_guard(GLOBAL)

function(infini_train_add_gpt_executable target_name)
add_executable(${target_name})
target_link_libraries(${target_name} PRIVATE infini_train_gpt_sources InfiniTrain::training_cli)
# Keep the framework archives as direct link entries in their whole-archive
# group; transitive de-duplication can otherwise move the core outside it.
link_infini_train_exe(${target_name})
endfunction()

# Called by example/<model>/CMakeLists.txt. Each model contributes source files
# to the shared GPT program and declares a preset-loading executable.
function(infini_train_add_gpt_model model_name)
cmake_parse_arguments(MODEL "" "FLAGFILE" "SOURCES" ${ARGN})
if(MODEL_UNPARSED_ARGUMENTS OR MODEL_KEYWORDS_MISSING_VALUES)
message(FATAL_ERROR
"infini_train_add_gpt_model(${model_name}): invalid or incomplete arguments")
endif()
if(NOT MODEL_SOURCES OR NOT MODEL_FLAGFILE)
message(FATAL_ERROR
"infini_train_add_gpt_model(${model_name}): SOURCES and FLAGFILE are required")
endif()
if(NOT TARGET infini_train_gpt_sources)
message(FATAL_ERROR "GPT models must be declared from the example build")
endif()

# Absolute source paths retain the declaring directory's meaning when the
# interface sources are consumed by executables in other model directories.
foreach(source IN LISTS MODEL_SOURCES)
get_filename_component(source_path "${source}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
target_sources(infini_train_gpt_sources INTERFACE "${source_path}")
endforeach()
get_filename_component(flagfile "${MODEL_FLAGFILE}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
if(NOT EXISTS "${flagfile}" OR IS_DIRECTORY "${flagfile}")
message(FATAL_ERROR "Training preset not found: ${flagfile}")
endif()

infini_train_add_gpt_executable(${model_name})
target_compile_definitions(${model_name} PRIVATE
INFINITRAIN_GPT_DEFAULT_FLAGFILE="configs/${model_name}/train.flags")

# Target-file directories also cover multi-config generators and custom output
# locations. Preset edits are copied on the next build without recompilation.
add_custom_target(${model_name}_training_config
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:${model_name}>/configs/${model_name}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${flagfile}" "$<TARGET_FILE_DIR:${model_name}>/configs/${model_name}/train.flags"
VERBATIM
)
add_dependencies(${model_name} ${model_name}_training_config)
endfunction()
Loading
Loading