# Error when using the forward() function of \`LongformerLayer\` class

**URL:** <https://discuss.huggingface.co/t/error-when-using-the-forward-function-of-longformerlayer-class/1531>\
**Category:** 🤗Transformers\
**Created:** [October 14, 2020, 3:56pm UTC](https://discuss.huggingface.co/t/error-when-using-the-forward-function-of-longformerlayer-class/1531 "2020-10-14T15:56:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![h56cho](https://avatars.discourse-cdn.com/v4/letter/h/c2a13f/32.png) [@h56cho](https://discuss.huggingface.co/u/h56cho)\
**Post date:** [October 14, 2020, 3:56pm UTC](https://discuss.huggingface.co/t/error-when-using-the-forward-function-of-longformerlayer-class/1531/1 "2020-10-14T15:56:15Z")

</div>

Hello,

Sorry if my question sounds a bit silly, but I just have a question:  
I am trying to use `LongformerForMultipleChoice` model for a multiple-choice question that has 4 options.

When I do:

```auto
my_Longformer_multiple_choice_model.encoder.layer[layer_index].forward(hidden_output, 
                                                 attention_mask=my_attention_mask,output_attention=False)

```

, an this error is generated:

```auto

  File "/Users/hyunjindominiquecho/opt/anaconda3/lib/python3.7/site-packages/transformers/modeling_longformer.py", line 384, in _sliding_chunks_query_key_matmul
    batch_size, seq_len, num_heads, head_dim = query.size()

ValueError: too many values to unpack (expected 4)

```

Here, `my_attention_mask` is the same attention mask that I would specify under the regular `LongformerForMultipleChoice` command:

```python
# I am using the LongformerForMultipleChoice model, where each multiple choice question has 4 options.
my_attention_mask = tensor([[[1, 1, 1, ..., 0, 0, 0],
         [1, 1, 1, ..., 0, 0, 0],
         [1, 1, 1, ..., 0, 0, 0],
         [1, 1, 1, ..., 0, 0, 0]]])
# I can use the my_attention_mask in the regular command as below:
longformer_output= my_Longformer_multiple_choice_model(input_ids=input_ids,....,attention_mask=my_attention_mask)

```

why is this value error generated? What should I pass for the `attention_mask` parameter in the command `my_Longformer_multiple_choice_model.encoder.layer[layer_index].forward(hidden_output, attention_mask,output_attention=False)`?

Thank you,

---

<div class="post-metadata">

**Author:** ![shainaraza](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/shainaraza/32/2854_2.png) [@shainaraza](https://discuss.huggingface.co/u/shainaraza)\
**Post date:** [October 14, 2020, 5:10pm UTC](https://discuss.huggingface.co/t/error-when-using-the-forward-function-of-longformerlayer-class/1531/2 "2020-10-14T17:10:59Z")

</div>

That seems to me error more related to the data structures rather than the longformer, may be you should check the format of input data first.

---

<div class="post-metadata">

**Author:** ![h56cho](https://avatars.discourse-cdn.com/v4/letter/h/c2a13f/32.png) [@h56cho](https://discuss.huggingface.co/u/h56cho)\
**Post date:** [October 14, 2020, 5:12pm UTC](https://discuss.huggingface.co/t/error-when-using-the-forward-function-of-longformerlayer-class/1531/3 "2020-10-14T17:12:50Z")

</div>

Yes, and this is why I am asking the Huggingface staffs what I should pass as the `attention_mask` parameter in my command.

---

<div class="post-metadata">

**Author:** ![shainaraza](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/shainaraza/32/2854_2.png) [@shainaraza](https://discuss.huggingface.co/u/shainaraza)\
**Post date:** [October 14, 2020, 5:26pm UTC](https://discuss.huggingface.co/t/error-when-using-the-forward-function-of-longformerlayer-class/1531/4 "2020-10-14T17:26:45Z")

</div>

> [@h56cho](#):
>
> attention\_mask

yes, in my case I passed a list and then pass list to the inputs:

> inputs = tokenizer.encode\_plus(example.text\_a, example.text\_b, add\_special\_tokens=True, max\_length=max\_length, pad\_to\_max\_length=True)
> 
> ```
> input_ids , attention_mask = inputs["input_ids"] , inputs["attention_mask"]
> 
> ```

not sure if that is the issue with yours work,  
can you please let me know what is yours batch size and which environment is better for such model, I am using a tiny dataset otherwise it crashes the google colab pro,

---

<div class="post-metadata">

**Author:** ![h56cho](https://avatars.discourse-cdn.com/v4/letter/h/c2a13f/32.png) [@h56cho](https://discuss.huggingface.co/u/h56cho)\
**Post date:** [October 14, 2020, 5:28pm UTC](https://discuss.huggingface.co/t/error-when-using-the-forward-function-of-longformerlayer-class/1531/5 "2020-10-14T17:28:57Z")

</div>

Please note that I am doing  
`my_Longformer_multiple_choice_model.encoder.layer[layer_index].forward(hidden_output, attention_mask,output_attention=False)`.

Please read my question carefully. `my_attention_mask` can be used in the command  
`my_Longformer_multiple_choice_model(input_ids=input_ids,....,attention_mask=my_attention_mask) ` without an error.

You are not doing  
`my_Longformer_multiple_choice_model.encoder.layer[layer_index].forward()`.

This has to do with HuggingFace code for the `.encoder.layer`.

---

<div class="post-metadata">

**Author:** ![h56cho](https://avatars.discourse-cdn.com/v4/letter/h/c2a13f/32.png) [@h56cho](https://discuss.huggingface.co/u/h56cho)\
**Post date:** [October 14, 2020, 5:50pm UTC](https://discuss.huggingface.co/t/error-when-using-the-forward-function-of-longformerlayer-class/1531/6 "2020-10-14T17:50:58Z")

</div>

Please disregard this post… I can’t quite delete it.

---

<div class="post-metadata">

**Author:** ![malcomvx](https://avatars.discourse-cdn.com/v4/letter/m/e480ec/32.png) [@malcomvx](https://discuss.huggingface.co/u/malcomvx)\
**Post date:** [May 26, 2021, 11:47am UTC](https://discuss.huggingface.co/t/error-when-using-the-forward-function-of-longformerlayer-class/1531/7 "2021-05-26T11:47:39Z")

</div>

> [@h56cho](#):
>
> `ValueError: too many values to unpack (expected 4)`

Python functions can return multiple variables . These variables can be stored in variables directly. This is a unique property of Python , other programming languages such as C++ or Java do not support this by default.

The valueerror: [too many values to unpack](http://net-informations.com/python/err/value.htm) occurs during a multiple-assignment where you either don’t have enough objects to assign to the variables or you have more objects to assign than variables. If for example myfunction() returned an iterable with three items instead of the expected two then you would have more objects than variables necessary to assign to.
