ValueError: The following `model_kwargs` are not used by the model: ['length']

See original GitHub issue

System Info

4.22.2

Who can help?

@SaulLu

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, …)
  • My own task or dataset (give details below)

Reproduction

            prompt = tokenizer(user_input, return_tensors='pt', return_length=True)
            prompt = {key: value.to(device) for key, value in prompt.items()}
            out = gpt.generate(**prompt, ...)

When using “return_length=True” with the tokenizer, the error is given. This is from a change in a recent version and did not happen in older versions.

ValueError: The following model_kwargs are not used by the model: ['length'] (note: typos in the generate arguments will also show up in this list)

Expected behavior

Model should not produce an error when “return_length” is set to True Downgrade to 4.21.0 fixes the problem and according to my googling this is what people are doing

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
tjysdsgcommented, Nov 20, 2022

@zzxslp

Change these line at https://github.com/salesforce/BLIP/blob/main/models/med.py#L932 as following:

from

    def prepare_inputs_for_generation(self, input_ids, past=None, attention_mask=None, **model_kwargs):
        input_shape = input_ids.shape
        # if model is used as a decoder in encoder-decoder model, the decoder attention mask is created on the fly
        if attention_mask is None:
            attention_mask = input_ids.new_ones(input_shape)

        # cut decoder_input_ids if past is used
        if past is not None:
            input_ids = input_ids[:, -1:]

        return {
            "input_ids": input_ids, 
            "attention_mask": attention_mask, 
            "past_key_values": past,
            "encoder_hidden_states": model_kwargs.get("encoder_hidden_states", None),
            "encoder_attention_mask": model_kwargs.get("encoder_attention_mask", None),
            "is_decoder": True,
        }

to

    def prepare_inputs_for_generation(self, input_ids, past=None, attention_mask=None, encoder_hidden_states=None, encoder_attention_mask=None, **model_kwargs):
        input_shape = input_ids.shape
        # if model is used as a decoder in encoder-decoder model, the decoder attention mask is created on the fly
        if attention_mask is None:
            attention_mask = input_ids.new_ones(input_shape)

        # cut decoder_input_ids if past is used
        if past is not None:
            input_ids = input_ids[:, -1:]

        return {
            "input_ids": input_ids, 
            "attention_mask": attention_mask, 
            "past_key_values": past,
            "encoder_hidden_states": encoder_hidden_states,
            "encoder_attention_mask": encoder_attention_mask,
            "is_decoder": True,
        }

Why: https://github.com/huggingface/transformers/blob/v4.23.1/src/transformers/generation_utils.py#L899

0reactions
ArthurZuckercommented, Dec 20, 2022

Well, in that case I just downloaded the model. You can usually initialize a random tiny model using a different configuration. Could you tell me why you need to set return_length=True. This has the effect of adding length to the list of inputs, and is not useful when generating. This argument is mostly used when training a fast tokenizer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: The following `model_kwargs` are not used by the ...
When I try to run my code for Donut for DocVQA model, I got the following error "" ...
Read more >
Source code for transformers.generation_utils - Hugging Face
LongTensor: is_pad_token_in_inputs_ids = (pad_token_id is not None) and ... maximul length if unfinished_sequences.max() == 0: break # update model kwargs ...
Read more >
Source code for statsmodels.tsa.statespace.dynamic_factor_mq
This does not include any lags, but it can be used with e.g. ... 0)): raise ValueError('The model must contain at least one...
Read more >
Source code for statsmodels.base.model
DataFrame` args : extra arguments These are passed to the model kwargs ... from `scipy.optimize` is used, and it can be chosen from...
Read more >
Source code for lenstronomy.ImSim.image2source_mapping
_deflection_scaling_list is not None: raise ValueError('deflection scaling for ... lens model kwargs list :param index_source: int, index of source model ...
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