| 177 | |
| 178 | template<typename T> |
| 179 | Decoding<T>::Decoding(size_t max_batch_size, |
| 180 | size_t max_seq_len, |
| 181 | size_t mem_max_seq_len, |
| 182 | size_t beam_width, |
| 183 | size_t head_num, |
| 184 | size_t size_per_head, |
| 185 | size_t inter_size, |
| 186 | size_t num_layer, |
| 187 | size_t vocab_size, |
| 188 | int start_id, |
| 189 | int end_id, |
| 190 | float beam_search_diversity_rate, |
| 191 | uint top_k, |
| 192 | float top_p, |
| 193 | float temperature, |
| 194 | float len_penalty, |
| 195 | float repetition_penalty, |
| 196 | cudaStream_t stream, |
| 197 | cublasMMWrapper* cublas_wrapper, |
| 198 | IAllocator* allocator, |
| 199 | bool is_free_buffer_after_forward, |
| 200 | cudaDeviceProp* cuda_device_prop): |
| 201 | BaseLayer(stream, cublas_wrapper, allocator, is_free_buffer_after_forward, cuda_device_prop), |
| 202 | max_batch_size_(max_batch_size), |
| 203 | max_seq_len_(max_seq_len + 1), // allocater additional one to put the start token |
| 204 | mem_max_seq_len_(mem_max_seq_len), |
| 205 | beam_width_(beam_width), |
| 206 | head_num_(head_num), |
| 207 | size_per_head_(size_per_head), |
| 208 | inter_size_(inter_size), |
| 209 | num_layer_(num_layer), |
| 210 | vocab_size_(vocab_size), |
| 211 | start_id_(start_id), |
| 212 | end_id_(end_id), |
| 213 | beam_search_diversity_rate_(beam_search_diversity_rate), |
| 214 | hidden_units_(head_num_ * size_per_head), |
| 215 | top_k_(top_k), |
| 216 | top_p_(top_p), |
| 217 | temperature_(temperature), |
| 218 | len_penalty_(len_penalty), |
| 219 | repetition_penalty_(repetition_penalty) |
| 220 | { |
| 221 | vocab_size_padded_ = vocab_size_; |
| 222 | if (std::is_same<half, T>::value) { |
| 223 | vocab_size_padded_ = ((size_t)ceil(vocab_size_padded_ / 8.) * 8); |
| 224 | } |
| 225 | |
| 226 | initialize(); |
| 227 | } |
| 228 | |
| 229 | template<typename T> |
| 230 | Decoding<T>::Decoding(Decoding<T> const& decoding): |