in lama/modules/gpt_connector.py [0:0]
def get_batch_generation(self, sentences_list, logger=None, try_cuda=True):
if try_cuda:
self.try_cuda()
src_tensor_list, dst_tensor_list, masked_indices_list, _ = zip(*[
self.__get_input_tensors(sentences) for sentences in sentences_list
])
src_tensor_batch = torch.nn.utils.rnn.pad_sequence(
src_tensor_list, batch_first=True)
# The model uses shared embedding space for tokens and positions. More
# precisely, the first len(vocab) indidices are reseved for words, the
# last n_special symbols are reserved for special symbols and the rest
# is used for positions. Softmax and embedding matrices are shared and
# as result some of output "symbols" correspond to positions. To fix
# that we have to manually remove logits for positions.
with torch.no_grad():
logits = self.gpt_model(src_tensor_batch.to(self._model_device))
logits = logits[..., :self.gpt_model.config.vocab_size]
log_probs = torch.nn.functional.log_softmax(logits, dim=-1).cpu()
token_ids_list = [
np.array(dst_tensor.numpy()) for dst_tensor in dst_tensor_list
]
return log_probs, token_ids_list, masked_indices_list