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

Method forward

src/fastertransformer/th_op/decoding/DecodingOp.cc:183–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181}
182
183std::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
205std::vector<th::Tensor> FasterTransformerDecoding::get_pickle_info() const
206{

Callers

nothing calls this directly

Calls 3

dtypeMethod · 0.45
sizeMethod · 0.45
deviceMethod · 0.45

Tested by

no test coverage detected