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

TypeError: 'NoneType' object is not subscriptable #43

Open
Kuchiriel opened this issue Jan 16, 2024 · 0 comments
Open

TypeError: 'NoneType' object is not subscriptable #43

Kuchiriel opened this issue Jan 16, 2024 · 0 comments

Comments

@Kuchiriel
Copy link

Error: TypeError Traceback (most recent call last)
in <cell line: 73>()
95 if DEVICE == "cuda":
96 with amp.autocast():
---> 97 result = pipe(
98 prompt,
99 max_new_tokens=1024,

8 frames
/usr/local/lib/python3.10/dist-packages/attention_sinks/generation/utils.py in _update_model_kwargs_for_generation(self, outputs, model_kwargs, is_encoder_decoder, standardize_cache_format)
30 # Only this branch is changed, it's required to stop the attention_mask from extending itself too far
31 attention_mask_size = model_kwargs["attention_mask"].size(-1)
---> 32 past_key_values_size = model_kwargs["past_key_values"][0][0].size(2)
33 if attention_mask_size == past_key_values_size:
34 model_kwargs["attention_mask"] = torch.cat(

TypeError: 'NoneType' object is not subscriptable

The error is caused by a missing past_key_values argument in the _update_model_kwargs_for_generation function. This argument is required for the attention_sinks model, which uses a different attention mechanism than the standard Transformer model.

To fix the error, you can add the past_key_values argument to the function definition and then pass it to the function when you call it. For example:

def _update_model_kwargs_for_generation(self, outputs, model_kwargs, is_encoder_decoder, standardize_cache_format):
if is_encoder_decoder:
model_kwargs["encoder_past"] = outputs["encoder_past"]
if self.config.is_attention_sink:
model_kwargs["past_key_values"] = outputs["past_key_values"]
attention_mask_size = model_kwargs["attention_mask"].size(-1)
past_key_values_size = model_kwargs["past_key_values"][0][0].size(2)
if attention_mask_size == past_key_values_size:
model_kwargs["attention_mask"] = torch.cat(
(model_kwargs["attention_mask"], torch.zeros((1, past_key_values_size), dtype=torch.int64)), dim=-1
)
return model_kwargs

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