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

Function gpt_example

examples/cpp/gpt_fp8/gpt_fp8_example.cc:127–425  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125
126template<typename T1, typename T2>
127void gpt_example(const INIReader reader)
128{
129 const std::string model_name = reader.Get("ft_instance_hyperparameter", "model_name");
130 const size_t max_batch_size = reader.GetInteger("ft_instance_hyperparameter", "max_batch_size");
131 const size_t max_seq_len = reader.GetInteger("ft_instance_hyperparameter", "max_seq_len");
132 const size_t beam_width = reader.GetInteger("ft_instance_hyperparameter", "beam_width");
133 const int top_k = reader.GetInteger("ft_instance_hyperparameter", "top_k");
134 const float top_p = reader.GetFloat("ft_instance_hyperparameter", "top_p");
135 const float temperature = reader.GetFloat("ft_instance_hyperparameter", "temperature");
136 const float repetition_penalty = reader.GetFloat("ft_instance_hyperparameter", "repetition_penalty");
137 const std::string model_dir = std::string(reader.Get("ft_instance_hyperparameter", "model_dir"));
138 const float len_penalty = 1.0f;
139 const float beam_search_diversity_rate = 0.0f;
140 const unsigned long long int random_seed = 0;
141
142 const int tensor_para_size = reader.GetInteger("ft_instance_hyperparameter", "tensor_para_size");
143 const int pipeline_para_size = reader.GetInteger("ft_instance_hyperparameter", "pipeline_para_size");
144
145 const size_t head_num = reader.GetInteger(model_name, "head_num");
146 const size_t size_per_head = reader.GetInteger(model_name, "size_per_head");
147 const size_t vocab_size = reader.GetInteger(model_name, "vocab_size");
148 const size_t decoder_layers = reader.GetInteger(model_name, "decoder_layers");
149 const size_t hidden_units = head_num * size_per_head;
150 const size_t inter_size = 4 * hidden_units;
151
152 const size_t request_batch_size = reader.GetInteger("request", "request_batch_size");
153 // The length of tokens we hope this model to generate
154 const int request_output_len = reader.GetInteger("request", "request_output_len");
155
156 const int start_id = 50256;
157 const int end_id = 50256;
158
159 FT_CHECK(head_num % tensor_para_size == 0);
160 FT_CHECK(decoder_layers % pipeline_para_size == 0);
161
162 // Prepare the parallelism parameters
163 int rank = mpi::getCommWorldRank();
164 int world_size = mpi::getCommWorldSize();
165
166 if (rank == 0) {
167 FT_LOG_INFO("Total ranks: %d.", world_size);
168 }
169 int device, device_count;
170 check_cuda_error(cudaGetDeviceCount(&device_count));
171 check_cuda_error(cudaSetDevice(rank % device_count));
172 check_cuda_error(cudaGetDevice(&device));
173
174 struct cudaDeviceProp prop;
175 check_cuda_error(cudaGetDeviceProperties(&prop, device));
176 FT_LOG_INFO("Device %s", prop.name);
177 FT_LOG_INFO("P%d is running with %d GPU.", rank, device);
178
179 FT_CHECK_WITH_INFO(tensor_para_size * pipeline_para_size == world_size,
180 fmtstr("[ERROR] tensor_para_size (%d) * pipeline_para_size (%d) should equal to world_size (%d)",
181 tensor_para_size,
182 pipeline_para_size,
183 world_size));
184

Callers

nothing calls this directly

Calls 15

getCommWorldRankFunction · 0.85
getCommWorldSizeFunction · 0.85
fmtstrFunction · 0.85
ftNcclInitializeFunction · 0.85
getDeviceFunction · 0.85
cublasFP8MMWrapperClass · 0.85
print_mem_usageFunction · 0.85
setScopeFunction · 0.85
resetScopeFunction · 0.85
GetMethod · 0.80
GetIntegerMethod · 0.80
GetFloatMethod · 0.80

Tested by

no test coverage detected