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

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

Closed
2 of 4 tasks
erew123 opened this issue Jan 22, 2024 · 15 comments
Closed
2 of 4 tasks

Comments

@erew123
Copy link

erew123 commented Jan 22, 2024

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.

@amyeroberts
Copy link
Collaborator

cc @gante

@YellowRoseCx
Copy link

Just encountered this error and found this thread by google searching it

@kunibald413
Copy link

Confirm this happens on 4.37.0

@wahibzakraoui
Copy link

Me too, literally just happened. I'll try downgrading first.

@Pamdi8888
Copy link

Pamdi8888 commented Jan 23, 2024

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

@wahibzakraoui
Copy link

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

@amyeroberts
Copy link
Collaborator

@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.

@amyeroberts
Copy link
Collaborator

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.

@erew123
Copy link
Author

erew123 commented Jan 23, 2024

@amyeroberts Thanks for looking into this Amy & @gante its very appreciated!

@juandsep
Copy link

transformers==4.33.0 works for me.

@Huarong
Copy link

Huarong commented Jan 24, 2024

transformers will import transformers_stream_generator, while transformers_stream_generator has the following import

from transformers.generation.utils import GenerateOutput, SampleOutput, logger

But in transformers>=4.37, SampleOutput was removed and transformers will raise ImportError although transformers_stream_generator has already been installed.

ImportError: This modeling file requires the following packages that were not found in your environment: transformers_stream_generator. Run pip install transformers_stream_generator

@amyeroberts
Copy link
Collaborator

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.

@erew123
Copy link
Author

erew123 commented Jan 24, 2024

@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.

@erew123
Copy link
Author

erew123 commented Jan 24, 2024

@amyeroberts Actually managed to give it a quick go now and everything loads up fine again! Awesome stuff! Ill close off the ticket. Again, thanks so much!

@erew123 erew123 closed this as completed Jan 24, 2024
@amyeroberts
Copy link
Collaborator

@erew123 Great - thanks for confirming!

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

9 participants