Files
pyannote-audio/tests/tasks/test_reproducibility.py
ea18bc70d8 Align audio CI and releases; require Python 3.11 (#2081)
* feat(cli): add --subfolder option to benchmark command (#2063)
* fix(utils): fix `SpeakerDiarizationMixin.optimal_mapping` when `reference` is a mapping
* fix(task): fix `balance` option crashing training with `KeyError: 'metadata'` (#2067)
* fix(io): fix `Audio.crop` raising when an in-memory waveform is cropped up to its very end (#2068)
* fix(model): make Model.default_activation return identity for unsupported tasks
* fix: compute sample duration from preloaded waveform
* fix(pipeline): omit unset runtime options from model references (#2080)

Co-authored-by: abeeranajam31 <128603901+abeeranajam31@users.noreply.github.com>
Co-authored-by: antoinelaurent <antoinelaurent@me.com>
Co-authored-by: Kayvan Zahiri <123409429+Kayvan-Zahiri@users.noreply.github.com>
Co-authored-by: Mohammad Hijjawi <51020382+MohammadHijjawi97@users.noreply.github.com>
2026-10-22 15:07:01 +02:00

64 lines
1.7 KiB
Python

import torch
from lightning import seed_everything
from pyannote.database import FileFinder, registry
from pyannote.audio.models.segmentation.debug import SimpleSegmentationModel
from pyannote.audio.tasks import VoiceActivityDetection
def setup_tasks(task):
protocol = registry.get_protocol(
"Debug.SpeakerDiarization.Debug", preprocessors={"audio": FileFinder()}
)
vad = task(protocol, duration=0.2, batch_size=32, num_workers=4)
return protocol, vad
def create_dl(model, task):
m = model(task=task)
m.prepare_data()
m.setup()
return task.train_dataloader()
def get_next5(dl):
last5 = []
it = iter(dl)
for i in range(5):
last5.append(next(it))
return last5
def test_seeding_ensures_data_loaders():
"Setting a global seed for the dataloaders ensures that we get data back in the same order"
seed_everything(1)
_protocol, vad = setup_tasks(VoiceActivityDetection)
dl = create_dl(SimpleSegmentationModel, vad)
last5a = get_next5(dl)
seed_everything(1)
__protocol, vad = setup_tasks(VoiceActivityDetection)
dl = create_dl(SimpleSegmentationModel, vad)
last5b = get_next5(dl)
for i in range(len(last5b)):
assert torch.equal(last5a[i]["X"], last5b[i]["X"])
def test_different_seeds():
"Changing the global seed will change the order of the data that loads"
_protocol, vad = setup_tasks(VoiceActivityDetection)
seed_everything(4)
dl = create_dl(SimpleSegmentationModel, vad)
last5a = get_next5(dl)
__protocol, vad = setup_tasks(VoiceActivityDetection)
seed_everything(5)
dl = create_dl(SimpleSegmentationModel, vad)
last5b = get_next5(dl)
for i in range(5):
assert not torch.equal(last5a[i]["X"], last5b[i]["X"])