| 140 | |
| 141 | template<typename T> |
| 142 | void gpt_example(const INIReader reader) |
| 143 | { |
| 144 | const std::string model_name = reader.Get("ft_instance_hyperparameter", "model_name"); |
| 145 | const size_t max_batch_size = reader.GetInteger("ft_instance_hyperparameter", "max_batch_size"); |
| 146 | const size_t max_seq_len = reader.GetInteger("ft_instance_hyperparameter", "max_seq_len"); |
| 147 | const size_t beam_width = reader.GetInteger("ft_instance_hyperparameter", "beam_width"); |
| 148 | const uint top_k = (uint)reader.GetInteger("ft_instance_hyperparameter", "top_k"); |
| 149 | const float top_p = reader.GetFloat("ft_instance_hyperparameter", "top_p"); |
| 150 | const float temperature = reader.GetFloat("ft_instance_hyperparameter", "temperature"); |
| 151 | const float repetition_penalty = reader.GetFloat("ft_instance_hyperparameter", "repetition_penalty", 1.0f); |
| 152 | const float presence_penalty = reader.GetFloat("ft_instance_hyperparameter", "presence_penalty", 0.0f); |
| 153 | const int min_length = reader.GetInteger("ft_instance_hyperparameter", "min_length", 0); |
| 154 | const std::string model_dir = std::string(reader.Get("ft_instance_hyperparameter", "model_dir")); |
| 155 | const bool sparse = static_cast<bool>(reader.GetInteger("ft_instance_hyperparameter", "sparse")); |
| 156 | const float shared_contexts_ratio = reader.GetFloat("ft_instance_hyperparameter", "shared_contexts_ratio", 1.0f); |
| 157 | const float len_penalty = reader.GetFloat("ft_instance_hyperparameter", "len_penalty"); |
| 158 | const float beam_search_diversity_rate = |
| 159 | reader.GetFloat("ft_instance_hyperparameter", "beam_search_diversity_rate"); |
| 160 | const unsigned long long int random_seed = 0; |
| 161 | |
| 162 | FT_CHECK_WITH_INFO( |
| 163 | repetition_penalty == 1.0f || presence_penalty == 0.0f, |
| 164 | fmtstr("Found ambiguous parameters repetition_penalty (%f) and presence_penalty (%f) " |
| 165 | "which are mutually exclusive. Please remove one of repetition_penalty or presence_penalty " |
| 166 | "or set to a default value.", |
| 167 | repetition_penalty, |
| 168 | presence_penalty)); |
| 169 | |
| 170 | const size_t head_num = reader.GetInteger(model_name, "head_num"); |
| 171 | const size_t size_per_head = reader.GetInteger(model_name, "size_per_head"); |
| 172 | const size_t vocab_size = reader.GetInteger(model_name, "vocab_size"); |
| 173 | const size_t decoder_layers = reader.GetInteger(model_name, "decoder_layers"); |
| 174 | const size_t hidden_units = head_num * size_per_head; |
| 175 | const size_t inter_size = 4 * hidden_units; |
| 176 | |
| 177 | const size_t request_batch_size = reader.GetInteger("request", "request_batch_size"); |
| 178 | // The length of tokens we hope this model to generate |
| 179 | const int request_output_len = reader.GetInteger("request", "request_output_len"); |
| 180 | // Whether to return the log probabilities of outputs. |
| 181 | const bool is_return_log_probs = reader.GetBoolean("request", "return_log_probs", false); |
| 182 | // Whether to include input contexts in computing the cumulative log probabilities. |
| 183 | const bool is_return_context_cum_log_probs = reader.GetBoolean("request", "context_log_probs", false); |
| 184 | if (is_return_log_probs && !is_return_context_cum_log_probs) { |
| 185 | FT_LOG_WARNING("context_log_probs will be ignored since return_log_probs is disabled."); |
| 186 | } |
| 187 | |
| 188 | const int start_id = 50256; |
| 189 | const int end_id = 50256; |
| 190 | |
| 191 | const int rank = 0; |
| 192 | |
| 193 | // Read ids of request from file. |
| 194 | int max_input_len = -1; |
| 195 | std::vector<int> v_start_lengths; |
| 196 | std::vector<int> v_start_ids; |
| 197 | read_start_ids(request_batch_size, &v_start_lengths, &v_start_ids, max_input_len, end_id, 1); |
| 198 | |
| 199 | int* d_input_ids; |
nothing calls this directly
no test coverage detected