transformers: 4.37 ImportError: cannot import name 'SampleOutput' from 'transformers.generation.utils'

System Info

I am a developer of AllTalk https://github.com/erew123/alltalk_tts/ which uses the Coqui TTS engine https://github.com/coqui-ai/TTS

As of the 4.37 update, I have users reporting this error:

Traceback (most recent call last):
File "/home/ai/alltalk_tts/tts_server.py", line 7, in
from TTS.tts.configs.xtts_config import XttsConfig
File "/home/ai/alltalk_tts/alltalk_environment/env/lib/python3.11/site-packages/TTS/tts/configs/xtts_config.py", line 5, in
from TTS.tts.models.xtts import XttsArgs, XttsAudioConfig
File "/home/ai/alltalk_tts/alltalk_environment/env/lib/python3.11/site-packages/TTS/tts/models/xtts.py", line 12, in
from TTS.tts.layers.xtts.stream_generator import init_stream_support
File "/home/ai/alltalk_tts/alltalk_environment/env/lib/python3.11/site-packages/TTS/tts/layers/xtts/stream_generator.py", line 24, in
from transformers.generation.utils import GenerateOutput, SampleOutput, logger
ImportError: cannot import name 'SampleOutput' from 'transformers.generation.utils' (/home/ai/alltalk_tts/alltalk_environment/env/lib/python3.11/site-packages/transformers/generation/utils.py)

The issue is mainly this:

ImportError: cannot import name 'SampleOutput' from 'transformers.generation.utils'

Downgrading to 4.36.2 of Transformers makes things work fine again.

I looked to see if this could be related to Remove support for torch 1.10 but can find no references to SampleOutput being a part of that.

Would you be able to confirm to me is this something that has been dropped in 4.37 or perhaps an omission that will be resolved in a future update?

Thanks

Who can help?

@sanchit-gandhi (Im guessing you may be the correct person as this is Speech, apologies if not).

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

Use transformers 4.37 with the Coqui TTS engine and try to import their XTTS model.

Expected behavior

Of course, for this model to import correctly.

About this issue

  • Original URL
  • State: closed
  • Created 5 months ago
  • Comments: 15

Most upvoted comments

This worked for me: Update your TTS requirements.txt look for transformers>=4.33.0 and replace it with: transformers==4.33.0

Run: pip install -r requirements.txt

@gante This seems to be due to SampleOutput being remove from generation.utils.py in #28494. I missed in the PR that the mapping were completely removed. I think the best thing to do is add back, with a patch and deprecation warning.

Encountered this error as well. Downgrading Transformers to 4.36.2 fixes it.

@amyeroberts Thanks so much Amy. I will give it a test at some point soon and feed back if there’s any issues. Really appreciate your help with that.

Hi all, a patch has been released which should resolve the issues here: SampleOutput can now be imported again as a type: https://github.com/huggingface/transformers/releases/tag/v4.37.1

You should be able to revert back to the original requirements.txt file, install the latest transformers and run your code with Coqui’s TTS.

transformers==4.33.0 works for me.

This worked for me: Update your TTS requirements.txt look for transformers>=4.33.0 and replace it with: transformers==4.33.0

Run: pip install -r requirements.txt

For anyone currently experiencing this issue - any version of transformers before 4.37 should still be fine i.e. setting transformers>=4.33.0,<4.37 in requirements.txt should work until a patch is released.