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

nable to create tensor, you should probably activate padding with 'padding=True' to have batched tensors with the same length. #599

Open
anudeike opened this issue Sep 1, 2024 · 4 comments

Comments

@anudeike
Copy link

anudeike commented Sep 1, 2024

Hi.

I am attempting to get bark set up on my local machine.

Here are the following steps that I have done:

  1. Created an virtual environment and activated it
  2. I've installed transformers package suing pip install transformers
  3. Installed this library with pip install git+https://github.com/suno-ai/bark.git
  4. And then basically copy and pasted the starter code in the readme file:
from transformers import AutoProcessor, BarkModel
import scipy
import os 

os.environ["SUNO_OFFLOAD_CPU"] = "True"
os.environ["SUNO_USE_SMALL_MODELS"] = "True"

processor = AutoProcessor.from_pretrained("suno/bark")
model = BarkModel.from_pretrained("suno/bark")

voice_preset = "v2/en_speaker_6"

inputs = processor("Hello, my dog is cute", voice_preset=voice_preset)

audio_array = model.generate(**inputs)
audio_array = audio_array.cpu().numpy().squeeze()

# write to a wav file:
sample_rate = model.generation_config.sample_rate
scipy.io.wavfile.write("bark_out.wav", rate=sample_rate, data=audio_array)

When I run this, I get the following two errors:

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.1.0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last):  File "c:\Users\ikech\Documents\CodingProjects\BarkTextToSpeech\main.py", line 1, in <module>     
    from transformers import AutoProcessor, BarkModel
  File "C:\Users\ikech\Documents\CodingProjects\BarkTextToSpeech\.venv\Lib\site-packages\transformers\__init__.py", line 26, in <module>
    from . import dependency_versions_check
  File "C:\Users\ikech\Documents\CodingProjects\BarkTextToSpeech\.venv\Lib\site-packages\transformers\dependency_versions_check.py", line 16, in <module>
    from .utils.versions import require_version, require_version_core
  File "C:\Users\ikech\Documents\CodingProjects\BarkTextToSpeech\.venv\Lib\site-packages\transformers\utils\__init__.py", line 34, in <module>
    from .generic import (
  File "C:\Users\ikech\Documents\CodingProjects\BarkTextToSpeech\.venv\Lib\site-packages\transformers\utils\generic.py", line 462, in <module>
    import torch.utils._pytree as _torch_pytree
  File "C:\Users\ikech\Documents\CodingProjects\BarkTextToSpeech\.venv\Lib\site-packages\torch\__init__.py", line 2120, in <module>  
    from torch._higher_order_ops import cond
  File "C:\Users\ikech\Documents\CodingProjects\BarkTextToSpeech\.venv\Lib\site-packages\torch\_higher_order_ops\__init__.py", line 1, in <module>
    from .cond import cond
  File "C:\Users\ikech\Documents\CodingProjects\BarkTextToSpeech\.venv\Lib\site-packages\torch\_higher_order_ops\cond.py", line 5, in <module>
    import torch._subclasses.functional_tensor
  File "C:\Users\ikech\Documents\CodingProjects\BarkTextToSpeech\.venv\Lib\site-packages\torch\_subclasses\functional_tensor.py", line 42, in <module>
    class FunctionalTensor(torch.Tensor):
  File "C:\Users\ikech\Documents\CodingProjects\BarkTextToSpeech\.venv\Lib\site-packages\torch\_subclasses\functional_tensor.py", line 258, in FunctionalTensor
    cpu = _conversion_method_template(device=torch.device("cpu"))
C:\Users\ikech\Documents\CodingProjects\BarkTextToSpeech\.venv\Lib\site-packages\torch\_subclasses\functional_tensor.py:258: UserWarning: Failed to initialize NumPy: _ARRAY_API not found (Triggered internally at C:\actions-runner\_work\pytorch\pytorch\builder\windows\pytorch\torch\csrc\utils\tensor_numpy.cpp:84.)
  cpu = _conversion_method_template(device=torch.device("cpu"))
C:\Users\ikech\Documents\CodingProjects\BarkTextToSpeech\.venv\Lib\site-packages\torch\nn\utils\weight_norm.py:134: FutureWarning: `torch.nn.utils.weight_norm` is deprecated in favor of `torch.nn.utils.parametrizations.weight_norm`.
  WeightNorm.apply(module, name, dim)
C:\Users\ikech\Documents\CodingProjects\BarkTextToSpeech\.venv\Lib\site-packages\transformers\models\encodec\modeling_encodec.py:120: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
  self.register_buffer("padding_total", torch.tensor(kernel_size - stride, dtype=torch.int64), persistent=False)
Traceback (most recent call last):
  File "C:\Users\ikech\Documents\CodingProjects\BarkTextToSpeech\.venv\Lib\site-packages\transformers\feature_extraction_utils.py", line 190, in convert_to_tensors
    tensor = as_tensor(value)
             ^^^^^^^^^^^^^^^^
  File "C:\Users\ikech\Documents\CodingProjects\BarkTextToSpeech\.venv\Lib\site-packages\transformers\feature_extraction_utils.py", line 149, in as_tensor
    return torch.tensor(value)
           ^^^^^^^^^^^^^^^^^^^
RuntimeError: Could not infer dtype of numpy.int64

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\ikech\Documents\CodingProjects\BarkTextToSpeech\main.py", line 13, in <module>
    inputs = processor("Hello, my dog is cute", voice_preset=voice_preset)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ikech\Documents\CodingProjects\BarkTextToSpeech\.venv\Lib\site-packages\transformers\models\bark\processing_bark.py", line 271, in __call__
    voice_preset = BatchFeature(data=voice_preset, tensor_type=return_tensors)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ikech\Documents\CodingProjects\BarkTextToSpeech\.venv\Lib\site-packages\transformers\feature_extraction_utils.py", line 79, in __init__
    self.convert_to_tensors(tensor_type=tensor_type)
  File "C:\Users\ikech\Documents\CodingProjects\BarkTextToSpeech\.venv\Lib\site-packages\transformers\feature_extraction_utils.py", line 196, in convert_to_tensors
    raise ValueError(
ValueError: Unable to create tensor, you should probably activate padding with 'padding=True' to have batched tensors with the same length.

I'm a bit new to working with this library. Please assist if possible.

@anudeike
Copy link
Author

anudeike commented Sep 1, 2024

@goncastrum I'm not downloading a random file from mediafire. This will not fix my problem.

@bharattrader
Copy link

I think it is saying that numpy version should 1.x not 2.x. You can do a force uninstall and install.

@anudeike
Copy link
Author

anudeike commented Sep 9, 2024

@bharattrader Just checked my numpy version: it is 1.26.4

@hvt1609
Copy link

hvt1609 commented Sep 15, 2024

It worked for me. Just switch numpy version to 2.x.x by "pip install -U numpy"

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

4 participants
@anudeike @hvt1609 @bharattrader and others