| 181 | } |
| 182 | |
| 183 | std::vector<th::Tensor> FasterTransformerDecoding::forward(int64_t beam_width, |
| 184 | int64_t max_seq_len, |
| 185 | th::Tensor memory, |
| 186 | th::Tensor memory_seq_lens) |
| 187 | { |
| 188 | CHECK_INPUT(memory, _st); |
| 189 | CHECK_TH_CUDA(memory_seq_lens); |
| 190 | CHECK_CONTIGUOUS(memory_seq_lens); |
| 191 | TORCH_CHECK(memory_seq_lens.dtype() == torch::kInt32, "mem_seq_lens dtype should be int32"); |
| 192 | |
| 193 | int batch_size = (int)(memory.size(0) / beam_width); |
| 194 | auto output_ids = torch::empty({batch_size * beam_width * max_seq_len}, |
| 195 | torch::dtype(torch::kInt32).device(torch::kCUDA).requires_grad(false)); |
| 196 | auto parent_ids = torch::empty({batch_size * beam_width * max_seq_len}, |
| 197 | torch::dtype(torch::kInt32).device(torch::kCUDA).requires_grad(false)); |
| 198 | auto out_seq_lens = |
| 199 | torch::empty({batch_size * beam_width}, torch::dtype(torch::kInt32).device(torch::kCUDA).requires_grad(false)); |
| 200 | ftdecoding->forward( |
| 201 | (size_t)beam_width, (size_t)max_seq_len, memory, memory_seq_lens, output_ids, parent_ids, out_seq_lens); |
| 202 | return std::vector<th::Tensor>{output_ids, parent_ids, out_seq_lens}; |
| 203 | } |
| 204 | |
| 205 | std::vector<th::Tensor> FasterTransformerDecoding::get_pickle_info() const |
| 206 | { |