From cc679dc7d661f130369f99e5771dc79883d4fd79 Mon Sep 17 00:00:00 2001 From: Anthony Date: Mon, 2 Nov 2026 06:17:42 -0800 Subject: [PATCH] fix(model): honor ToTaToNet linear hidden size (#2077) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Hervé BREDIN --- CHANGELOG.md | 1 + .../audio/models/separation/ToTaToNet.py | 4 +- tests/test_totatonet.py | 76 +++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 tests/test_totatonet.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e02c5ae..924728b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Python 3.14's default on Linux, by warning and using `num_workers=0` - fix(pipeline): omit unset `token` and `cache_dir` when expanding `$model/` references so loaders can inherit runtime options +- fix(model): honor the configured linear hidden size in `ToTaToNet` [@antonsoo](https://github.com/antonsoo) - fix(io): fix `Audio.crop` raising when an in-memory waveform is cropped up to its very end [@MohammadHijjawi97](https://github.com/MohammadHijjawi97) - feat(cli): add `--subfolder` option to `benchmark` command [@antoinelaurent](https://github.com/antoinelaurent) - fix(utils): fix `SpeakerDiarizationMixin.optimal_mapping` `reference` is a mapping [@Kayvan-Zahiri](https://github.com/Kayvan-Zahiri) diff --git a/src/pyannote/audio/models/separation/ToTaToNet.py b/src/pyannote/audio/models/separation/ToTaToNet.py index 584c008c..27eaadd5 100644 --- a/src/pyannote/audio/models/separation/ToTaToNet.py +++ b/src/pyannote/audio/models/separation/ToTaToNet.py @@ -233,7 +233,9 @@ class ToTaToNet(Model): def build(self): if self.hparams.linear["num_layers"] > 0: - self.classifier = nn.Linear(64, self.dimension) + self.classifier = nn.Linear( + self.hparams.linear["hidden_size"], self.dimension + ) else: self.classifier = nn.Linear(1, self.dimension) self.activation = self.default_activation() diff --git a/tests/test_totatonet.py b/tests/test_totatonet.py new file mode 100644 index 00000000..efa95871 --- /dev/null +++ b/tests/test_totatonet.py @@ -0,0 +1,76 @@ +# The MIT License (MIT) +# +# Copyright (c) 2024-2025 CNRS +# Copyright (c) 2025- pyannoteAI +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +import pytest +import torch + +from pyannote.audio.core.task import Problem, Resolution, Specifications +from pyannote.audio.models.separation.ToTaToNet import ToTaToNet + + +@pytest.mark.parametrize( + "linear", + [ + None, + {"hidden_size": 8, "num_layers": 1}, + {"hidden_size": 96, "num_layers": 2}, + {"num_layers": 0}, + ], + ids=["default", "narrow", "wide", "no_hidden_layers"], +) +def test_totatonet_linear_configuration(linear): + pytest.importorskip("asteroid") + pytest.importorskip("transformers") + model = ToTaToNet( + use_wavlm=False, + n_sources=2, + linear=linear, + encoder_decoder={"n_filters": 8}, + dprnn={"n_repeats": 1, "bn_chan": 8, "hid_size": 8, "chunk_size": 50}, + ) + model.specifications = ( + Specifications( + problem=Problem.MULTI_LABEL_CLASSIFICATION, + resolution=Resolution.FRAME, + duration=2.0, + classes=["speaker#1", "speaker#2"], + ), + Specifications( + problem=Problem.MONO_LABEL_CLASSIFICATION, + resolution=Resolution.FRAME, + duration=2.0, + classes=["speaker#1", "speaker#2"], + ), + ) + model.build() + waveforms = torch.randn(2, 1, 32000) + diarization, sources = model(waveforms) + assert diarization.shape == (2, model.num_frames(32000), 2) + assert sources.shape == (2, 32000, 2) + assert torch.isfinite(diarization).all() + assert torch.isfinite(sources).all() + (diarization.square().mean() + sources.square().mean()).backward() + assert model.classifier.weight.grad is not None + assert torch.isfinite(model.classifier.weight.grad).all() + assert torch.count_nonzero(model.classifier.weight.grad) > 0