Skip to content

feat(server): add frequency penalty #1541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 8, 2024
Merged

Conversation

OlivierDehaene
Copy link
Contributor

No description provided.

Copy link
Contributor Author

@OlivierDehaene OlivierDehaene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

black messed up the PR..
@drbh, @Narsil should we add a pre-commit hook on black?

Comment on lines +160 to +167
def __call__(self, input_ids: torch.Tensor, scores: torch.Tensor) -> torch.Tensor:
score = torch.gather(scores, 1, input_ids)
# if score < 0 then penalty has to be multiplied to reduce the previous token probability
score = -torch.where(
score < 0, score * self.penalty_tensor, score / self.penalty_tensor
)

return scores.scatter_add_(1, input_ids, score)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Narsil I'm not 100% sure of this. This seems right when compared to https://platform.openai.com/docs/guides/text-generation/parameter-details

@OlivierDehaene OlivierDehaene merged commit 09b7c26 into main Feb 8, 2024
@OlivierDehaene OlivierDehaene deleted the feat/frequency_penalty branch February 8, 2024 17:41
kdamaszk pushed a commit to kdamaszk/tgi-gaudi that referenced this pull request Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants