question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can we add an augment `min_new_tokens` to the `generate` function?

See original GitHub issue

Feature request

Can we add a new parameter min_new_tokens to the generate function to limit the length of newly generated tokens? The current parameter min_length limits the length of prompt + newly generated tokens, not the length of newly generated tokens.

Motivation

We already have max_new_tokens to limit the max length of the generated tokens, i.e., max_length = max_new_tokens + prompt.

Why not add the min_new_token to limit the min length of the generated tokens? (i.e., min_length = min_new_tokens + prompt)

I know this is kind like an other syntax sugar, but it will be much convenient if we have this parameter.

Your contribution

I can sumbit a PR.

Issue Analytics

  • State:open
  • Created 9 months ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
silverrivercommented, Dec 7, 2022

@PanQiWei I agree, but I think it is impossible to change the current implementation of max_length and min_length for the conern of back compatibility.

0reactions
PanQiWeicommented, Dec 6, 2022

For my understanding, in the current implementation, min_length set the length limit of len(promt) + len(generated tokens)

See the implementation of MinLengthLogitsProcessor:

    def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor) -> torch.FloatTensor:
        cur_len = input_ids.shape[-1]
        if cur_len < self.min_length:
            scores[:, self.eos_token_id] = -float("inf")
        return scores

input_ids in the previous code block refers to prompt + generated tokens. For example, see the implemented of some decoding method for how logits processors are called. (See beam_search() or greedy_decoding())

It will be more convenient if we set an argument min_new_tokens to only limit the length of generated tokens, not prompt + generated tokens.

Please correct me if I have missed something

@silverriver yes you are right, its my mistake 😂

But I still think min_new_tokens and min_length should mean the same thing and also to max_new_tokens and max_length (though they are actually different now), because most people who use model.generate would think min_length means to ‘at least generate min_length tokens’ and max_length means to ‘generate tokens no more than max_length’

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to activate an Augment in Fortnite and Augments list
You need to activate an Augment in Fortnite Chapter 4 Season 1 in order to gain some helpful buffs, as well as unlock...
Read more >
Augmenting Function.prototype and make a method ...
I learned from Douglas Crockford's book that if you augment Function.prototype, you can make a method available to all functions.
Read more >
Fortnite: All Augments And How They Work
First Assault - The first bullet in the magazine of your Assault Rifle deals bonus damage. Forecast - You can always see the...
Read more >
Augmenting Types - JavaScript: The Good Parts [Book]
In Chapter 3, we saw that adding a method to Object.prototype makes that method ... For example, by augmenting Function.prototype , we can...
Read more >
Augmentation Libraries - dart-lang/language
Augmentations can add new top-level declarations, inject new members into classes, and wrap functions and variables in additional code.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found