| 146 | |
| 147 | template<typename T> |
| 148 | int bert_triton_example(int argc, char* argv[]) |
| 149 | { |
| 150 | /* |
| 151 | Prepare the nccl ids, node id, device id and world size |
| 152 | by MPI or triton |
| 153 | */ |
| 154 | |
| 155 | ft::mpi::initialize(&argc, &argv); |
| 156 | int node_id = ft::mpi::getCommWorldRank(); |
| 157 | int node_num = ft::mpi::getCommWorldSize(); |
| 158 | |
| 159 | // Note: Only supports that all nodes have same gpu count |
| 160 | const int gpu_count = ft::getDeviceCount(); |
| 161 | const int world_size = node_num * gpu_count; |
| 162 | std::string ini_name = argc >= 2 ? std::string(argv[1]) : "../examples/cpp/bert/bert_config.ini"; |
| 163 | |
| 164 | // step 1: Create model |
| 165 | INIReader reader = INIReader(ini_name); |
| 166 | std::shared_ptr<AbstractTransformerModel> model = std::make_shared<BertTritonModel<T>>( |
| 167 | reader.GetInteger("ft_instance_hyperparameter", "tensor_para_size"), |
| 168 | reader.GetInteger("ft_instance_hyperparameter", "pipeline_para_size"), |
| 169 | reader.GetInteger("ft_instance_hyperparameter", "enable_custom_all_reduce", 0), |
| 170 | reader.Get("ft_instance_hyperparameter", "model_dir"), |
| 171 | reader.GetInteger("ft_instance_hyperparameter", "int8_mode"), |
| 172 | reader.GetInteger("ft_instance_hyperparameter", "is_sparse"), |
| 173 | reader.GetInteger("ft_instance_hyperparameter", "is_remove_padding")); |
| 174 | std::cout << model->toString(); |
| 175 | int tensor_para_size = model->getTensorParaSize(); |
| 176 | int pipeline_para_size = model->getPipelineParaSize(); |
| 177 | FT_CHECK_WITH_INFO(world_size == (tensor_para_size * pipeline_para_size), |
| 178 | ft::fmtstr("World Size(%d) != Tensor Parallel Size (%d) * Pipeline Parallel Size (%d) !", |
| 179 | world_size, |
| 180 | tensor_para_size, |
| 181 | pipeline_para_size)); |
| 182 | |
| 183 | // step 2: Initialize the NCCL |
| 184 | std::pair<std::vector<ft::NcclParam>, std::vector<ft::NcclParam>> nccl_params = model->createNcclParams(node_id); |
| 185 | cudaDeviceSynchronize(); |
| 186 | |
| 187 | // Optional Step: create custom all reduce comm |
| 188 | std::vector<std::shared_ptr<ft::AbstractCustomComm>> custom_all_reduce_comms; |
| 189 | model->createCustomComms(&custom_all_reduce_comms, world_size); |
| 190 | |
| 191 | // step 3: Create model instances |
| 192 | std::vector<std::unique_ptr<AbstractTransformerModelInstance>> model_instances((size_t)gpu_count); |
| 193 | std::vector<std::thread> threads; |
| 194 | |
| 195 | threads.clear(); |
| 196 | |
| 197 | for (int device_id = 0; device_id < gpu_count; device_id++) { |
| 198 | const int rank = node_id * gpu_count + device_id; |
| 199 | threads.push_back(std::thread(threadCreateModelInstances, |
| 200 | model, |
| 201 | &model_instances, |
| 202 | device_id, |
| 203 | rank, |
| 204 | nccl_params, |
| 205 | custom_all_reduce_comms[rank])); |
nothing calls this directly
no test coverage detected