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

Function main

examples/cpp/multi_gpu_gpt/multi_gpu_gpt_triton_example.cc:306–463  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

304}
305
306int main(int argc, char* argv[])
307{
308 /*
309 Prepare the nccl ids, node id, device id and world size
310 by MPI or triton
311 */
312
313 ft::mpi::initialize(&argc, &argv);
314 int node_id = ft::mpi::getCommWorldRank();
315 int node_num = ft::mpi::getCommWorldSize();
316
317 // Note: Only supports that all nodes have same gpu count
318 const int gpu_count = ft::getDeviceCount();
319 const int world_size = node_num * gpu_count;
320 std::string ini_name = argc >= 2 ? std::string(argv[1]) : "../examples/cpp/multi_gpu_gpt/gpt_config.ini";
321
322 // step 1: Create model
323 std::shared_ptr<AbstractTransformerModel> model = AbstractTransformerModel::createGptModel(ini_name);
324 int tensor_para_size = model->getTensorParaSize();
325 int pipeline_para_size = model->getPipelineParaSize();
326 FT_CHECK_WITH_INFO(world_size == (tensor_para_size * pipeline_para_size),
327 ft::fmtstr("World Size (%d) != Tensor Parallel Size (%d) * Pipeline Parallel Size (%d).",
328 world_size,
329 tensor_para_size,
330 pipeline_para_size));
331
332 std::cout << model->toString();
333
334 // step 2: Initialize the NCCL
335 std::pair<std::vector<ft::NcclParam>, std::vector<ft::NcclParam>> nccl_comms = model->createNcclParams(node_id);
336 cudaDeviceSynchronize();
337
338 // Optional Step: create custom all reduce comm
339 std::vector<std::shared_ptr<ft::AbstractCustomComm>> custom_all_reduce_comms;
340 model->createCustomComms(&custom_all_reduce_comms, world_size);
341
342 // step 3: Create model instances
343 std::vector<std::unique_ptr<AbstractTransformerModelInstance>> model_instances((size_t)gpu_count);
344 std::vector<std::thread> threads;
345
346 threads.clear();
347
348 for (int device_id = 0; device_id < gpu_count; device_id++) {
349 const int rank = node_id * gpu_count + device_id;
350 threads.push_back(std::thread(threadCreateModelInstances,
351 model,
352 &model_instances,
353 device_id,
354 rank,
355 nccl_comms,
356 custom_all_reduce_comms[rank]));
357 }
358 for (auto& t : threads) {
359 t.join();
360 }
361
362 // step 4: prepare request
363 std::vector<void*> pointer_record; // Used to prevent the pointers are release after leaving functions

Callers

nothing calls this directly

Calls 15

initializeFunction · 0.85
getCommWorldRankFunction · 0.85
getCommWorldSizeFunction · 0.85
getDeviceCountFunction · 0.85
fmtstrFunction · 0.85
createNcclParamsMethod · 0.80
clearMethod · 0.80
atMethod · 0.80
getMethod · 0.80
prepareRequestFunction · 0.70
barrierFunction · 0.50
finalizeFunction · 0.50

Tested by

no test coverage detected