IndexError: index 4 is out of range
Running this example code:
import torch
import soundfile as sf
from transformers import pipeline
synthesiser = pipeline("text-to-audio", "facebook/musicgen-stereo-small", device="cuda:0", torch_dtype=torch.float16)
music = synthesiser("lo-fi music with a soothing melody", forward_params={"max_new_tokens": 256})
sf.write("musicgen_out.wav", music["audio"][0].T, music["sampling_rate"])
I get this error:
python\lib\site-packages\torch\nn\modules\container.py", line 283, in _get_abs_string_index
raise IndexError(f'index {idx} is out of range')
IndexError: index 4 is out of range
Hey
@tintwotin
! Unfortunately, I am not able to reproduce on the latest version of transformers
. Could you kindly confirm that you are running the latest PyPi version (or installed from main
)?
pip install -U transformers
If you upgrade the library as detailed above, re-run the code-snippet, and the issue still persists, could you please post the output of the command:
transformers-cli env
Many thanks!
I had several python side-package installation folders on the hdd, and I needed to clean out all of them. And now it works. Thank you!
I ran into this issue too, and was able to resolve it by upgrading transformers from 4.35.2 to 4.36.0.dev0
Instead of installing transformer directly from pip pip install transformers
, I followed the readme and did pip install --upgrade git+https://github.com/huggingface/transformers.git
instead.
Hope this helps someone else!