Skip to content
Merged
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ To view available runtime options:
./build/llama3 --help
```

`--help` shows only the model's options. Use `--helpfull` to include all options
from third-party libraries.

### Getting Started

#### Prepare Datasets and Weights
Expand Down
2 changes: 1 addition & 1 deletion cmake/test_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ function(infini_train_add_privateuse1_test_suites)
GTEST_PREFIX PRIVATEUSE1
DEVICE_TYPE kPrivateUse1
DEVICE_INDEX ${PRIVATEUSE1_DEVICE_INDEX}
LABELS ${PRIVATEUSE1_BACKEND_NAME} accelerator hardware
LABELS ${PRIVATEUSE1_BACKEND_NAME}
TEST_MAIN_TARGET ${_privateuse1_main_target}
LINK_LIBRARIES ${PRIVATEUSE1_LINK_LIBRARIES}
${_privateuse1_timeout_args}
Expand Down
2 changes: 1 addition & 1 deletion docs/test_usage_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ infini_train_add_privateuse1_test_suites(
```

该调用为公共 suite 追加 `test_*_<BACKEND_NAME>` 目标;`DEVICE_INDEX` 默认为
`0`。例如 `BACKEND_NAME=maca` 使用 `maca;accelerator;hardware` CTest 标签:
`0`。例如 `BACKEND_NAME=maca` 使用 `maca` CTest 标签:

```bash
ctest -L maca --output-on-failure # MACA
Expand Down
24 changes: 24 additions & 0 deletions example/common/cli.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <cstdlib>

#include "gflags/gflags.h"

namespace infini_train::example {

inline void ParseModelFlags(int *argc, char ***argv, const char *model_path) {
gflags::ParseCommandLineNonHelpFlags(argc, argv, true);

// Keep gflags' --helpshort precedence and allow --helpfull to show all flags.
if (gflags::GetCommandLineFlagInfoOrDie("help").current_value == "true" &&
gflags::GetCommandLineFlagInfoOrDie("helpshort").current_value !=
"true" &&
gflags::GetCommandLineFlagInfoOrDie("helpfull").current_value != "true") {
gflags::ShowUsageWithFlagsRestrict((*argv)[0], model_path);
std::exit(1); // Match gflags' exit status for help output.
}

gflags::HandleCommandLineHelpFlags();
}

} // namespace infini_train::example
7 changes: 6 additions & 1 deletion example/gpt2/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "infini_train/include/utils/precision_check_config.h"
#include "infini_train/include/utils/precision_checker.h"

#include "example/common/cli.h"
#include "example/common/tiny_shakespeare_dataset.h"
#include "example/common/tokenizer.h"
#include "example/gpt2/checkpoint_loader.h"
Expand Down Expand Up @@ -727,12 +728,16 @@ void Train(const nn::parallel::Rank &rank) {
}

int main(int argc, char *argv[]) {
gflags::SetUsageMessage(
"Train a GPT-2 model with InfiniTrain.\nUsage: " + std::string(argv[0]) +
" --input_bin=<training.bin> [options]\n"
"Model options: --help\nAll options: --helpfull");
// Register provider metadata and implementations before gflags validates
// --device. The device runtime initializes lazily on first DeviceGuard use.
#ifdef INFINITRAIN_EXAMPLE_EXTERNAL_BACKEND_REGISTRAR
INFINITRAIN_EXAMPLE_EXTERNAL_BACKEND_REGISTRAR();
#endif
gflags::ParseCommandLineFlags(&argc, &argv, true);
example::ParseModelFlags(&argc, &argv, "example/gpt2/");
google::InitGoogleLogging(argv[0]);

auto precision_config =
Expand Down
7 changes: 6 additions & 1 deletion example/llama3/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "infini_train/include/profiler.h"
#endif

#include "example/common/cli.h"
#include "example/common/tiny_shakespeare_dataset.h"
#include "example/common/tokenizer.h"
#include "example/llama3/checkpoint_loader.h"
Expand Down Expand Up @@ -702,12 +703,16 @@ void Train(const nn::parallel::Rank &rank) {
}

int main(int argc, char *argv[]) {
gflags::SetUsageMessage("Train a LLaMA 3 model with InfiniTrain.\nUsage: " +
std::string(argv[0]) +
" --input_bin=<training.bin> [options]\n"
"Model options: --help\nAll options: --helpfull");
// Register provider metadata and implementations before gflags validates
// --device. The device runtime initializes lazily on first DeviceGuard use.
#ifdef INFINITRAIN_EXAMPLE_EXTERNAL_BACKEND_REGISTRAR
INFINITRAIN_EXAMPLE_EXTERNAL_BACKEND_REGISTRAR();
#endif
gflags::ParseCommandLineFlags(&argc, &argv, true);
example::ParseModelFlags(&argc, &argv, "example/llama3/");
google::InitGoogleLogging(argv[0]);

auto precision_config =
Expand Down
31 changes: 30 additions & 1 deletion example/mixtral/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include <tuple>
#include <vector>

#ifdef INFINITRAIN_EXAMPLE_EXTERNAL_BACKEND_WORKAROUNDS
#include <cstdlib>
#endif

#include "gflags/gflags.h"
#include "glog/logging.h"

Expand Down Expand Up @@ -49,6 +53,7 @@
#include "infini_train/include/profiler.h"
#endif

#include "example/common/cli.h"
#include "example/common/tiny_shakespeare_dataset.h"
#include "example/mixtral/checkpoint_loader.h"
#include "example/mixtral/config.h"
Expand Down Expand Up @@ -366,12 +371,16 @@ void Train(const nn::parallel::Rank &rank) {
}

int main(int argc, char *argv[]) {
gflags::SetUsageMessage("Train a Mixtral model with InfiniTrain.\nUsage: " +
std::string(argv[0]) +
" --input_bin=<training.bin> [options]\n"
"Model options: --help\nAll options: --helpfull");
// Register provider metadata and implementations before gflags validates
// --device. The device runtime initializes lazily on first DeviceGuard use.
#ifdef INFINITRAIN_EXAMPLE_EXTERNAL_BACKEND_REGISTRAR
INFINITRAIN_EXAMPLE_EXTERNAL_BACKEND_REGISTRAR();
#endif
gflags::ParseCommandLineFlags(&argc, &argv, true);
example::ParseModelFlags(&argc, &argv, "example/mixtral/");
google::InitGoogleLogging(argv[0]);

CHECK_GT(FLAGS_nthread_per_process, 0);
Expand Down Expand Up @@ -413,8 +422,28 @@ int main(int argc, char *argv[]) {
Train(rank);
}

#ifdef INFINITRAIN_EXAMPLE_EXTERNAL_BACKEND_WORKAROUNDS
// Capture the policy before shutting down gflags. Match the other external
// backend examples: MACA can fail during process-wide static destruction.
const bool skip_static_destruction =
INFINITRAIN_EXAMPLE_EXTERNAL_BACKEND_WORKAROUNDS &&
Device::ParseType(FLAGS_device).value() ==
Device::DeviceType::kPrivateUse1;
#endif

gflags::ShutDownCommandLineFlags();
google::ShutdownGoogleLogging();

#ifdef INFINITRAIN_EXAMPLE_EXTERNAL_BACKEND_WORKAROUNDS
if (skip_static_destruction) {
// Train() has returned and all workers have joined, so rank-local tensors
// and optimizers have already been destroyed. Flush before bypassing the
// remaining global/SDK teardown; _Exit does not flush C++ streams.
std::cout.flush();
std::cerr.flush();
std::_Exit(0);
}
#endif

return 0;
}
7 changes: 6 additions & 1 deletion example/mnist/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "infini_train/include/optimizer.h"
#include "infini_train/include/tensor.h"

#include "example/common/cli.h"
#include "example/mnist/dataset.h"
#include "example/mnist/net.h"

Expand All @@ -44,7 +45,11 @@ DEFINE_validator(device, [](const char *, const std::string &value) {
});

int main(int argc, char *argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
gflags::SetUsageMessage("Train a model on MNIST with InfiniTrain.\nUsage: " +
std::string(argv[0]) +
" --dataset=<dataset_dir> [options]\n"
"Model options: --help\nAll options: --helpfull");
example::ParseModelFlags(&argc, &argv, "example/mnist/");
google::InitGoogleLogging(argv[0]);

auto train_dataset = std::make_shared<MNISTDataset>(FLAGS_dataset, true);
Expand Down
7 changes: 6 additions & 1 deletion example/qwen3/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "infini_train/include/profiler.h"
#endif

#include "example/common/cli.h"
#include "example/common/tiny_shakespeare_dataset.h"
#include "example/common/tokenizer.h"
#include "example/qwen3/checkpoint_loader.h"
Expand Down Expand Up @@ -700,12 +701,16 @@ void Train(const nn::parallel::Rank &rank) {
}

int main(int argc, char *argv[]) {
gflags::SetUsageMessage(
"Train a Qwen3 model with InfiniTrain.\nUsage: " + std::string(argv[0]) +
" --input_bin=<training.bin> [options]\n"
"Model options: --help\nAll options: --helpfull");
// Register provider metadata and implementations before gflags validates
// --device. The device runtime initializes lazily on first DeviceGuard use.
#ifdef INFINITRAIN_EXAMPLE_EXTERNAL_BACKEND_REGISTRAR
INFINITRAIN_EXAMPLE_EXTERNAL_BACKEND_REGISTRAR();
#endif
gflags::ParseCommandLineFlags(&argc, &argv, true);
example::ParseModelFlags(&argc, &argv, "example/qwen3/");
google::InitGoogleLogging(argv[0]);

auto precision_config =
Expand Down
3 changes: 2 additions & 1 deletion infini_train/src/nn/parallel/ddp/distributed_optimizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ void DistributedOptimizer::BuildShardParamsAndBindGrads(
}

CHECK_GT(num_shard_params, 0)
<< "DistributedOptimizer: this DP rank owns no param pieces. "
<< "DistributedOptimizer: DP rank " << ddp_rank_
<< " owns no param pieces. "
<< "Check bucket padding/divisibility and param bucketing order.";
}

Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ if(USE_CUDA)
GTEST_PREFIX CUDA
DEVICE_TYPE kCUDA
DEVICE_INDEX 0
LABELS cuda accelerator hardware
LABELS cuda
ACCELERATOR
)
endif()
2 changes: 1 addition & 1 deletion tests/backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ infini_train_add_test(test_privateuse1_backend_validation
if(USE_CUDA)
infini_train_add_test(test_stream_guard_cuda
SOURCES test_stream_guard.cc
LABELS cuda accelerator hardware
LABELS cuda
BINARY_REGISTRATION
RUN_SERIAL
TEST_TIMEOUT 60
Expand Down
4 changes: 4 additions & 0 deletions tools/infini_run/infini_run.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ std::string GenerateLocalRunId() {
} // namespace

int main(int argc, char **argv) {
gflags::SetUsageMessage(
"Launch distributed training with InfiniTrain.\nUsage: " +
std::string(argv[0]) +
" [launcher options] <training program> [training options]");
const int train_program_index = FindTrainProgramIndex(argc, argv);
std::vector<char *> launcher_argv =
BuildLauncherArgv(train_program_index, argv);
Expand Down
Loading