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

Method forward

examples/pytorch/bart/utils/ft_decoding.py:327–360  ·  view source on GitHub ↗
(self, input_ids, attention_mask, inputs_embeds, beam_size, max_seq_len,
                top_k, top_p, beam_search_diversity_rate,
                temperature=1.0, len_penalty=0.0, repetition_penalty=1.0, random_seed=0,
                is_return_output_log_probs=False, is_return_cum_log_probs=False, is_return_cross_attentions=False)

Source from the content-addressed store, hash-verified

325 self.decoding = decoding
326
327 def forward(self, input_ids, attention_mask, inputs_embeds, beam_size, max_seq_len,
328 top_k, top_p, beam_search_diversity_rate,
329 temperature=1.0, len_penalty=0.0, repetition_penalty=1.0, random_seed=0,
330 is_return_output_log_probs=False, is_return_cum_log_probs=False, is_return_cross_attentions=False):
331
332 input_ids = input_ids.to("cuda").type(torch.int32)
333 mem_seq_len = torch.sum(attention_mask, dim=1).type(torch.int32).to("cuda")
334
335 ft_encoder_outputs = self.encoder.forward(input_ids, mem_seq_len, inputs_embeds)
336 results = self.decoding.forward(beam_size, # optional, can be None
337 max_seq_len,
338 top_k, # optional, can be None
339 top_p, # optional, can be None
340 beam_search_diversity_rate, # optional, can be None
341 temperature, # optional, can be None
342 len_penalty, # optional, can be None
343 repetition_penalty, # optional, can be None
344 random_seed, # optional, can be None
345 is_return_output_log_probs, # optional, can be None
346 is_return_cum_log_probs, # optional, can be None
347 is_return_cross_attentions, # optional, can be None
348 ft_encoder_outputs,
349 mem_seq_len)
350 return_dict = {}
351 return_dict['output_ids'] = results.pop(0).reshape([-1, beam_size, max_seq_len]).cpu().numpy()
352 return_dict['sequence_lengths'] = results.pop(0).reshape([-1, beam_size]).cpu().numpy()
353 if is_return_output_log_probs:
354 return_dict['output_log_probs'] = results.pop(0).cpu().numpy()
355 if is_return_cum_log_probs:
356 return_dict['cum_log_probs'] = results.pop(0).cpu().numpy()
357 if is_return_cross_attentions:
358 return_dict['cross_attentions'] = results.pop(0).cpu().numpy()
359
360 return return_dict

Callers 1

forwardMethod · 0.45

Calls 1

toMethod · 0.45

Tested by

no test coverage detected