pyannote-audio icon indicating copy to clipboard operation
pyannote-audio copied to clipboard

AttributeError: 'PyanNet' object has no attribute 'example_output' when loading speaker diarization pipeline

Open pweglik opened this issue 1 year ago • 10 comments
trafficstars

Tested versions

pyannote.audio==3.1.1

System information

Ubuntu 20.04

Issue description

My code:

from pyannote.audio import Pipeline
from pyannote.audio.pipelines import SpeakerDiarization
from pyannote.core import Annotation
import torch

pipeline: SpeakerDiarization = Pipeline.from_pretrained(
  "pyannote/speaker-diarization-3.1",
  use_auth_token="TOKEN").to(torch.device("cuda"))

results in:


	"name": "AttributeError",
	"message": "'PyanNet' object has no attribute 'example_output'",
	"stack": "---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[1], line 6
   3 from pyannote.core import Annotation
   4 import torch
----> 6 pipeline: SpeakerDiarization = Pipeline.from_pretrained(
   7   \"pyannote/speaker-diarization-3.1\",
   8   use_auth_token=\"TOKEN\").to(torch.device(\"cuda\"))

File ~/przemek/miniconda3/envs/meeting_summarizer/lib/python3.11/site-packages/pyannote/audio/core/pipeline.py:137, in Pipeline.from_pretrained(cls, checkpoint_path, hparams_file, use_auth_token, cache_dir)
 135 params.setdefault(\"use_auth_token\", use_auth_token)
 136 print(config)
--> 137 pipeline = Klass(**params)
 139 # freeze  parameters
 140 if \"freeze\" in config:

File ~/przemek/miniconda3/envs/meeting_summarizer/lib/python3.11/site-packages/pyannote/audio/pipelines/speaker_diarization.py:152, in SpeakerDiarization.__init__(self, segmentation, segmentation_step, embedding, embedding_exclude_overlap, clustering, embedding_batch_size, segmentation_batch_size, der_variant, use_auth_token)
 144 self._segmentation = Inference(
 145     model,
 146     duration=segmentation_duration,
(...)
 149     batch_size=segmentation_batch_size,
 150 )
 151 print(model)
--> 152 self._frames: SlidingWindow = self._segmentation.model.example_output.frames
 154 if self._segmentation.model.specifications.powerset:
 155     self.segmentation = ParamDict(
 156         min_duration_off=Uniform(0.0, 1.0),
 157     )

File ~/przemek/miniconda3/envs/meeting_summarizer/lib/python3.11/site-packages/torch/nn/modules/module.py:1614, in Module.__getattr__(self, name)
1612     if name in modules:
1613         return modules[name]
-> 1614 raise AttributeError(\"'{}' object has no attribute '{}'\".format(
1615     type(self).__name__, name))

AttributeError: 'PyanNet' object has no attribute 'example_output'"

Minimal reproduction example (MRE)

pweglik avatar Jan 16 '24 13:01 pweglik

I've dived down into the implementation and foudn out the problematic line was rearrange function in forward method of PyanNet. It crashed without leaving any trace. When I swapped :

rearrange(outputs, "batch feature frame -> batch frame feature")

to

torch.permute(outputs, (0, 2, 1))

model loaded correctly. Not sure what caused it, but might be something worth looking at. In einops repo I found similar issue: https://github.com/pytorch/pytorch/issues/94598

pweglik avatar Jan 16 '24 14:01 pweglik

Would you mind sharing a link to a Google Colab that one can just click and run to reproduce the issue?

hbredin avatar Jan 18 '24 09:01 hbredin

Sorry, I don't have time now and I'm not sure if you're allowed to install your own versions of everything on google collab. But for anyone looking working setup for me is:

python 3.10.13
torch==2.0.0+cu117
pyannote.pipeline==3.0.1

The bug was caused by python 3.11 and it occurred in einops library, so the bug is on their side. This may be an incentive to use torch.permute instead of einops.rearrange (it would remove unnecessary dependency)

pweglik avatar Jan 23 '24 12:01 pweglik

Adding cannot_reproduce label because, well, I cannot reproduce it.

hbredin avatar Jan 23 '24 13:01 hbredin

i'm getting the same error while trying to load the model

KickItLikeShika avatar Apr 03 '24 00:04 KickItLikeShika

I am getting the same issue.

palvinderbhatia avatar Apr 18 '24 10:04 palvinderbhatia

I also have the same issue

yoesak avatar May 09 '24 00:05 yoesak

@hbredin here is how I ran into it on Ubuntu 24.04; I hope it helps with reproducing the issue

  • Install Ubuntu 24.04 on WSL with VS Code (let me know if you need more info on this)
  • Update the Ubuntu packages and add Python (Python 3.12.x is currently the default in Ubuntu 24.04) sudo apt-get update && sudo apt-get upgrade -y and sudo apt install python-is-python3 python3-pip python3.12-venv git
  • In your project folder create a venv python3 -m venv myPythonEnv and activate it source myPythonEnv/bin/activate
  • pip install (I may have missed some of the other dependencies I installed)
pip install ipywidgets
pip install pyannote.audio
pip install ipython
  • Launch VS code from your project folder in WSL console using code . , create a notebook and pick myPythonEnv kernel Add the following to the notebook and run them:
from huggingface_hub import HfApi
available_pipelines = [p.modelId for p in HfApi().list_models(filter="pyannote-audio-pipeline")]
list(filter(lambda p: p.startswith("pyannote/"), available_pipelines))
from huggingface_hub import notebook_login
notebook_login()
from pyannote.audio import Pipeline
pipeline = Pipeline.from_pretrained(
    "pyannote/speaker-diarization-3.1", use_auth_token=True)

YasharF avatar Jul 04 '24 09:07 YasharF

Workaround solution: Use Python 3.10 Adding to my prior comment, the issue is compatibility with the newer versions of Python. I was able to get around this by switching to Python 3.10. After the above steps freeze the dependencies with pip freeze > requirements.txt and then

Install Python 3.10 in WSL/Ubuntu

 sudo add-apt-repository ppa:deadsnakes/ppa
 sudo apt-get update && sudo apt-get upgrade -y
 sudo apt install python3.10 python3.10-venv

Create a new venv with python 3.10, install the dependencies and reopen VS code

python3.10 -m venv p310venv
source p310venv/bin/activate
pip install -r requirements.txt
code .

Then pick the p310venv as the kernel and rerun the blocks in the notebook.

YasharF avatar Jul 04 '24 16:07 YasharF