Text-to-Speech
Transformers
Safetensors
parler_tts
text2text-generation
annotation

AttributeError: 'Tensor' object has no attribute '_pad_token_tensor'

#2
by 04RR - opened

Getting this error when running the code given in the sample -

import time
import torch
import soundfile as sf
from transformers import AutoTokenizer
from parler_tts import ParlerTTSForConditionalGeneration


device = "cuda:0" if torch.cuda.is_available() else "cpu"
model_path = "./model_ckpt/"

model = ParlerTTSForConditionalGeneration.from_pretrained(model_path).to(device)
tokenizer = AutoTokenizer.from_pretrained(model_path)
description_tokenizer = AutoTokenizer.from_pretrained(
    model.config.text_encoder._name_or_path
)

prompt = "Hey, how are you doing today?"
description = "A female speaker with a British accent delivers a slightly expressive and animated speech with a moderate speed and pitch. The recording is of very high quality, with the speaker's voice sounding clear and very close up."

input_ids = description_tokenizer(description, return_tensors="pt").input_ids.to(device)
prompt_input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(device)

st = time.time()
generation = model.generate(input_ids=input_ids, prompt_input_ids=prompt_input_ids)
audio_arr = generation.cpu().numpy().squeeze()
sf.write("indic_tts_out.wav", audio_arr, model.config.sampling_rate)
print(f"Time taken: {time.time() - st:.2f}s")

Error -

Traceback (most recent call last):
  File "/mnt/d/rr/active_diary/infer.py", line 24, in <module>
    generation = model.generate(input_ids=input_ids, prompt_input_ids=prompt_input_ids)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rohit/miniconda3/envs/diary/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/rohit/miniconda3/envs/diary/lib/python3.12/site-packages/parler_tts/modeling_parler_tts.py", line 3422, in generate
    model_kwargs["attention_mask"] = self._prepare_attention_mask_for_generation(
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rohit/miniconda3/envs/diary/lib/python3.12/site-packages/transformers/generation/utils.py", line 585, in _prepare_attention_mask_for_generation
    pad_token_id = generation_config._pad_token_tensor
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Tensor' object has no attribute '_pad_token_tensor'
AI4Bharat org

Hey @04RR , I think the code snippet are not up-to-date, we should also pass the attention_mask and promt_attention_mask, like done here. Would you like to open a PR to correct this?

AI4Bharat org

Nevermind, I've done it here ! https://huggingface.co./ai4bharat/indic-parler-tts/discussions/3
Let me know if that works for you

Sign up or log in to comment