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.

LEDForSequenceClassification fine-tuning model gives: IndexError: index out of range in self

See original GitHub issue

System Info

transformers - 4.21.1 Python - 3.8.13 torch - 1.12.0+cu113

Who can help?

@patrickvonplaten

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

I’m trying to fine-tune the LED model for the SequenceClassification task.

It works when I use max_sequence_length = 1024 but it doesn’t when it goes beyond these numbers. D

After debugging, I found a similar issue #14312, and tried applying the proposed solution by adding decoder_input_ids even though it doesn’t make sense to me that we really need this as an input.

To reproduce:

from transformers import LEDTokenizer, LEDForSequenceClassification
  
tokenizer = LEDTokenizer.from_pretrained("allenai/led-base-16384")
model = LEDForSequenceClassification.from_pretrained("allenai/led-base-16384")

# this works (tokens < 1024)
inputs = tokenizer("HuggingFace"*1000, return_tensors="pt")
with torch.no_grad():
      model(**input)

# this does not work! (tokens > 1024)
inputs = tokenizer("HuggingFace"*2048, return_tensors="pt")
with torch.no_grad():
      model(**input)

# this does not work as well! (tokens > 1024)
inputs = tokenizer("HuggingFace"*2048, return_tensors="pt")
inputs['decoder_input_ids'] = inputs['input_ids'][:512]
with torch.no_grad():
      model(**input)

Without adding decoder_input_ids to tokenized inputs, It simply complains of Index out of range while calling torch.embedding.

with decoder_input_ids as suggested in the reference issue above, It throws an IndexError: The Shape of the mask [1, 1026] at index 1 does not match the shape of the indexed tensor [1, 512, 768] at index 1

Expected behavior

As LEDForSequenceClassification should work for a sequence length of more than 1024 tokens.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
patrickvonplatencommented, Sep 14, 2022

Hey @darshan2203,

Sorry I won’t be free anytime soon to look into this issue - @ArthurZucker do you want to give it a try?

1reaction
ArthurZuckercommented, Sep 16, 2022

Oh right! Sorry will have a look asap 🤗

Read more comments on GitHub >

github_iconTop Results From Across the Web

LEDForSequenceClassification fine-tuning model gives ...
LEDForSequenceClassification fine-tuning model gives: IndexError: index out of range in self #19019. Closed. 2 of 4 tasks.
Read more >
BERT finetuning "index out of range in self" - Intermediate
Hello everyone, I am trying to build a Multiclass Classifier with a pretrained BERT model. I am completely new to the topic.
Read more >
IndexError: index out of range in self while try to fine tune ...
I am trying to fine tune a Roberta model ...
Read more >
Error while saving the model - list index out of range - Kaggle
I'm trying to fine-tune a pre-trained DistilBERT model from Huggingface using Tensorflow. Everything runs smoothly and the model builds and trains without ...
Read more >
index out of range: 0" Executing an Essbase Mapping in ODI
Oracle Data Integrator - Version 12.2.1.4.0 and later: "IndexError: index out of range: 0" Executing an Essbase Mapping in ODI.
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