MCPcopy Create free account
hub / github.com/NVIDIA/FasterTransformer / bert_triton_example

Function bert_triton_example

examples/cpp/bert/bert_triton_example.cc:148–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146
147template<typename T>
148int 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]));

Callers

nothing calls this directly

Calls 15

initializeFunction · 0.85
getCommWorldRankFunction · 0.85
getCommWorldSizeFunction · 0.85
getDeviceCountFunction · 0.85
INIReaderClass · 0.85
fmtstrFunction · 0.85
GetIntegerMethod · 0.80
GetMethod · 0.80
createNcclParamsMethod · 0.80
clearMethod · 0.80
atMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected