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

Function gptneox_example

examples/cpp/gptneox/gptneox_example.cc:72–504  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70
71template<typename T>
72void gptneox_example(const INIReader reader)
73{
74 const std::string model_name = reader.Get("ft_instance_hyperparameter", "model_name");
75 std::string model_dir = std::string(reader.Get("ft_instance_hyperparameter", "model_dir"));
76
77 int tensor_para_size = reader.GetInteger("ft_instance_hyperparameter", "tensor_para_size");
78 int pipeline_para_size = reader.GetInteger("ft_instance_hyperparameter", "pipeline_para_size");
79
80 const size_t head_num = reader.GetInteger(model_name, "head_num");
81 const size_t size_per_head = reader.GetInteger(model_name, "size_per_head");
82 const size_t vocab_size = reader.GetInteger(model_name, "vocab_size");
83 const size_t decoder_layers = reader.GetInteger(model_name, "decoder_layers");
84 const size_t rotary_embedding_dim = reader.GetInteger(model_name, "rotary_embedding");
85 const int start_id = reader.GetInteger(model_name, "start_id");
86 const int end_id = reader.GetInteger(model_name, "end_id");
87
88 const size_t hidden_units = head_num * size_per_head;
89 const size_t inter_size = 4 * hidden_units;
90
91 const size_t beam_width = reader.GetInteger("request", "beam_width");
92 const uint top_k = (uint)reader.GetInteger("request", "top_k");
93 const float top_p = reader.GetFloat("request", "top_p");
94 const float temperature = reader.GetFloat("request", "temperature");
95 const float repetition_penalty = reader.GetFloat("request", "repetition_penalty", 1.0f);
96 const float presence_penalty = reader.GetFloat("request", "presence_penalty", 0.0f);
97 const float len_penalty = reader.GetFloat("request", "len_penalty");
98 const float beam_search_diversity_rate = reader.GetFloat("request", "beam_search_diversity_rate");
99 const int min_length = reader.GetInteger("request", "min_length", 0);
100 const size_t request_batch_size = reader.GetInteger("request", "request_batch_size");
101 // The length of tokens we hope this model to generate
102 const int request_output_len = reader.GetInteger("request", "request_output_len");
103
104 FT_CHECK(head_num % tensor_para_size == 0);
105 FT_CHECK(decoder_layers % pipeline_para_size == 0);
106 FT_CHECK_WITH_INFO(
107 repetition_penalty == 1.0f || presence_penalty == 0.0f,
108 fmtstr("Found ambiguous parameters repetition_penalty (%f) and presence_penalty (%f) "
109 "which are mutually exclusive. Please remove one of repetition_penalty or presence_penalty "
110 "or set to a default value.",
111 repetition_penalty,
112 presence_penalty));
113
114 // Prepare the parallelism parameters
115 int rank = mpi::getCommWorldRank();
116 int world_size = mpi::getCommWorldSize();
117 if (rank == 0) {
118 printf("Total ranks: %d.\n", world_size);
119 }
120 int device, device_count;
121 check_cuda_error(cudaGetDeviceCount(&device_count));
122 check_cuda_error(cudaSetDevice(rank % device_count));
123 check_cuda_error(cudaGetDevice(&device));
124
125 struct cudaDeviceProp prop;
126 check_cuda_error(cudaGetDeviceProperties(&prop, device));
127 printf("Device %s\n", prop.name);
128
129 printf("P%d is running with GPU #%d.\n", rank, device);

Callers

nothing calls this directly

Calls 15

fmtstrFunction · 0.85
getCommWorldRankFunction · 0.85
getCommWorldSizeFunction · 0.85
ftNcclInitializeFunction · 0.85
read_word_listFunction · 0.85
getDeviceFunction · 0.85
cublasMMWrapperClass · 0.85
bcastFunction · 0.85
getSMVersionFunction · 0.85
print_mem_usageFunction · 0.85
setScopeFunction · 0.85
resetScopeFunction · 0.85

Tested by

no test coverage detected