Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Moved generation activation during generation of TorchGeneratorAgent #4700

Merged
merged 1 commit into from
Aug 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion parlai/core/torch_generator_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,9 @@ def get_prefix_tokens(self, batch: Batch) -> Optional[torch.LongTensor]:
"""
return None

def _generation_activation(self, score: torch.Tensor) -> torch.float32:
return F.log_softmax(score, dim=-1, dtype=torch.float32)

def _generate(
self,
batch: Batch,
Expand Down Expand Up @@ -1214,7 +1217,7 @@ def _generate(
if self.temperature != 1.0:
score.div_(self.temperature)
# force to fp32 to avoid overflow issues during search calculations
score = F.log_softmax(score, dim=-1, dtype=torch.float32) # type: ignore
score = self._generation_activation(score) # type: ignore
if prefix_tokens is not None and _ts < prefix_tokens.size(1):
# generate prefix_tokens for every timestep that they exist
# achieve by setting score of all other tokens to be -inf
Expand Down