Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

[Text Generation] Avoid mutating the original logits in-place when mapping from logits to token.#1414

Merged
mgoin merged 1 commit into
mainfrom
feature/damian/logits_copy
Nov 20, 2023
Merged

[Text Generation] Avoid mutating the original logits in-place when mapping from logits to token.#1414
mgoin merged 1 commit into
mainfrom
feature/damian/logits_copy

Conversation

@dbogunowicz

@dbogunowicz dbogunowicz commented Nov 17, 2023

Copy link
Copy Markdown
Contributor

Feature Description

TokenGenerator.generate(logits: numpy.ndarray) takes a logits array and, if do_sample=True, optionally mutates them to enforce the appropriate sampling strategy.

This results in the correct generation of tokens, but an in-place modification of the logits array. Logits array is then returned to the user in the mutated form. This can be confusing for the users who are interested in logits value, specially when returned together with prompt logits:

image

First column before: the generated logits returned to the user are mutated (the distribution is spikier, arguably close to Dirac distribution)

Second column after: the generated logits are the non-mutatated, original logits, consistent with the prompt logits.

Comment thread src/deepsparse/transformers/utils/token_generator.py
@dbogunowicz dbogunowicz requested a review from mgoin November 20, 2023 09:54
@mgoin mgoin merged commit 9383653 into main Nov 20, 2023
@mgoin mgoin deleted the feature/damian/logits_copy branch November 20, 2023 14:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants