AttributeError: 'SeamlessM4Tv2Model' object has no attribute 'sampling_rate'

#19
by skye0402 - opened

Dear experts,

I'm using the sample code under Linux

from transformers import AutoProcessor, SeamlessM4Tv2Model
import torchaudio
import scipy

processor = AutoProcessor.from_pretrained("facebook/seamless-m4t-v2-large")
model = SeamlessM4Tv2Model.from_pretrained("facebook/seamless-m4t-v2-large")

# from text
text_inputs = processor(text = "Hello, my dog is cute", src_lang="eng", return_tensors="pt")
audio_array_from_text = model.generate(**text_inputs, tgt_lang="rus")[0].cpu().numpy().squeeze()
pass
from IPython.display import Audio

sample_rate = model.sampling_rate

It errors out with

Traceback (most recent call last):
  File "/home/xxx/seemlessm4t/test-m4t01.py", line 14, in <module>
    sample_rate = model.sampling_rate
  File "/home/xxx/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1695, in __getattr__
    raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
AttributeError: 'SeamlessM4Tv2Model' object has no attribute 'sampling_rate'

What am I doing wrong?

Hi, @skye0402 ! can you try with sample_rate = model.config.sampling_rate.
Edit: I edited the README to use the correct attribute for the sampling rate.

Perfect! This solves the case, thank you @elbayadm

skye0402 changed discussion status to closed

Sign up or log in to comment