From 1a22b0236c52fd3e20d41315e7b340cf5c623a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20BREDIN?= Date: Sun, 18 Oct 2026 16:27:17 +0200 Subject: [PATCH] fix(pipeline): omit unset runtime options from model references (#2080) --- CHANGELOG.md | 1 + src/pyannote/audio/core/pipeline.py | 15 +++++++++++---- tests/test_pipeline_subfolder.py | 14 +++++++++++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b0699cb..a700a1a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## next +- fix(pipeline): omit unset `token` and `cache_dir` when expanding `$model/` references so loaders can inherit runtime options - 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/core/pipeline.py b/src/pyannote/audio/core/pipeline.py index fcada57a..aae75a6d 100644 --- a/src/pyannote/audio/core/pipeline.py +++ b/src/pyannote/audio/core/pipeline.py @@ -62,6 +62,9 @@ def expand_subfolders( "subfolder": {subfolder}, "token": token} + Token and cache directory options are included only when not None, so + loaders can inherit these options from the calling pipeline. + Parameters ---------- config : dict @@ -99,9 +102,11 @@ def expand_subfolders( "checkpoint": model_id, "revision": revision, "subfolder": subfolder, - "token": token, - "cache_dir": cache_dir, } + if token is not None: + config[key]["token"] = token + if cache_dir is not None: + config[key]["cache_dir"] = cache_dir else: expand_subfolders( value, @@ -133,9 +138,11 @@ def expand_subfolders( "checkpoint": model_id, "revision": revision, "subfolder": subfolder, - "token": token, - "cache_dir": cache_dir, } + if token is not None: + config[idx]["token"] = token + if cache_dir is not None: + config[idx]["cache_dir"] = cache_dir else: expand_subfolders( diff --git a/tests/test_pipeline_subfolder.py b/tests/test_pipeline_subfolder.py index c4a09ffe..1d9eafac 100644 --- a/tests/test_pipeline_subfolder.py +++ b/tests/test_pipeline_subfolder.py @@ -99,9 +99,21 @@ class TestExpandSubfolders: "revision": None, "subfolder": "embeddings", "token": "tok", - "cache_dir": None, } + @pytest.mark.parametrize("as_list", [False, True]) + @pytest.mark.parametrize("token", [None, False, "tok"]) + @pytest.mark.parametrize("cache_dir", [None, Path("cache")]) + def test_optional_runtime_options(self, as_list, token, cache_dir): + config = ["$model/weights"] if as_list else {"model": "$model/weights"} + expand_subfolders(config, model_id="org/repo", token=token, cache_dir=cache_dir) + model = config[0] if as_list else config["model"] + for key, value in {"token": token, "cache_dir": cache_dir}.items(): + if value is None: + assert key not in model + else: + assert model[key] == value + def test_dict_model_reference_with_parent_subfolder(self): """Child $model refs are resolved under parent_subfolder.""" config = {"segmentation": "$model/seg"}