Skip to content
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

There is error on demo.ipynb #133

Open
gkswns3708 opened this issue Mar 2, 2023 · 0 comments
Open

There is error on demo.ipynb #133

gkswns3708 opened this issue Mar 2, 2023 · 0 comments

Comments

@gkswns3708
Copy link

Hello, I am a Korean college student studying the BLIP paper. Before to start my English is limited, there may be some incorrect translations.

In HuggingFace's generation_utils.py

def _validate_model_kwargs(self, model_kwargs: Dict[str, Any]):
...
if "kwargs" in model_args:
            model_args = set(inspect.signature(self.forward).parameters)
... 

They checking the unsued_model_args for validating model kwargs with "kwargs". But BLIP use "model_kwargs" on code like below

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,
    }

So my opinion is just modifies model_kwargs to kwargs like below

def prepare_inputs_for_generation(self, input_ids, past=None, attention_mask=None, **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": kwargs.get("encoder_hidden_states", None),
        "encoder_attention_mask": kwargs.get("encoder_attention_mask", None),
        "is_decoder": True,
    }

Thank you to read this issue

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

No branches or pull requests

1 participant