Skip to content

Commit

Permalink
improve(ux): improve error message on missing specifications
Browse files Browse the repository at this point in the history
  • Loading branch information
clement-pages authored Feb 25, 2024
1 parent d83c0f8 commit 99ed3d6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
10 changes: 1 addition & 9 deletions pyannote/audio/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,7 @@ def specifications(self) -> Union[Specifications, Tuple[Specifications]]:
) from e

else:
try:
specifications = self.task.specifications

except AttributeError as e:
raise UnknownSpecificationsError(
"Task specifications are not available. This is most likely because they depend on "
"the content of the training subset. Use `model.prepare_data()` and `model.setup()` "
"to go over the training subset and fix this, or let lightning trainer do that for you in `trainer.fit(model)`."
) from e
specifications = self.task.specifications

return specifications

Expand Down
6 changes: 5 additions & 1 deletion pyannote/audio/core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,11 @@ def setup(self, stage=None):
def specifications(self) -> Union[Specifications, Tuple[Specifications]]:
# setup metadata on-demand the first time specifications are requested and missing
if not hasattr(self, "_specifications"):
self.setup()
raise UnknownSpecificationsError(
"Task specifications are not available. This is most likely because they depend on "
"the content of the training subset. Use `task.prepare_data()` and `task.setup()` "
"to go over the training subset and fix this, or let lightning trainer do that for you in `trainer.fit(model)`."
)
return self._specifications

@specifications.setter
Expand Down
27 changes: 27 additions & 0 deletions tests/tasks/test_specifications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pytest
from pyannote.database import FileFinder, get_protocol

from pyannote.audio.core.model import Model
from pyannote.audio.core.task import UnknownSpecificationsError
from pyannote.audio.tasks import SpeakerDiarization


@pytest.fixture()
def protocol():
return get_protocol(
"Debug.SpeakerDiarization.Debug", preprocessors={"audio": FileFinder()}
)


def test_unknown_specifications_error_raised_on_non_setup_task(protocol):
task = SpeakerDiarization(protocol=protocol)
with pytest.raises(UnknownSpecificationsError):
_ = task.specifications


def test_unknown_specifications_error_raised_on_non_setup_model_task(protocol):
task = SpeakerDiarization(protocol=protocol)
model = Model.from_pretrained("pyannote/ci-segmentation")
model.task = task
with pytest.raises(UnknownSpecificationsError):
_ = model.specifications

0 comments on commit 99ed3d6

Please sign in to comment.