Download src/nida/data/registry.py from Bilal7Dev/nida-tts: direct link, hf CLI and curl.
- Browser
- Download file 8.3 kB
-
https://huggingface.co/Bilal7Dev/nida-tts/resolve/main/src/nida/data/registry.py
- Command line
-
hf download hf://Bilal7Dev/nida-tts/src/nida/data/registry.py
-
curl -L -o registry.py https://huggingface.co/Bilal7Dev/nida-tts/resolve/main/src/nida/data/registry.py
8.3 kB
| """Phase 1 data-pipeline models and their pinned references (single source of truth). | |
| Every entry maps to a ``configs/sources.yaml`` id; :func:`require_models_approved` refuses | |
| to run anything whose source is not ``approved`` (golden rule 6, data-pipeline rule) by | |
| delegating to :func:`nida.bench.registry.require_approved`. Hugging Face revisions are commit | |
| SHAs read from the Hub API on 2026-10-08 (sortformer and mpoyraz match the notes in | |
| ``sources.yaml``). PANNs weights come from Zenodo (record 3987831, v3) and are addressed by | |
| the pseudo model id/revision understood by the PANNs worker. | |
| The optional speech-enhancement arms (:mod:`nida.data.enhance`) are registered separately in | |
| :data:`ENHANCE_MODELS`, *not* in :data:`DATA_MODELS`: the annotate config digest covers every | |
| ``DATA_MODELS`` pin and the pilot demands every ``DATA_MODELS`` source to be approved, and neither | |
| may depend on which enhancement arm (if any) is selected. Two arms are pinned by the SHA-256 of | |
| their model file (``sha256:<hex>`` revisions, verified by the worker): the UVR ONNX file is fetched | |
| from a third-party release and the DeepFilterNet checkpoint from the unpinned main branch. | |
| The evaluation models (:data:`EVAL_MODELS`, speaker similarity) are registered separately for the | |
| same reason: they must not move the config digests. | |
| """ | |
| from __future__ import annotations | |
| from collections.abc import Iterable, Mapping | |
| from dataclasses import dataclass | |
| from types import MappingProxyType | |
| from typing import Any | |
| from nida.bench.registry import ( | |
| VAE_SYSTEMS, | |
| SourceNotApprovedError, | |
| load_sources, | |
| require_approved, | |
| ) | |
| from nida.bench.workers.runner import ModelRef | |
| from nida.data.workers.sed_panns import ZENODO_MODEL_ID, ZENODO_REVISION | |
| __all__ = [ | |
| "DATA_MODELS", | |
| "ENHANCE_ARM_KEYS", | |
| "ENHANCE_MODELS", | |
| "EVAL_MODELS", | |
| "DataModel", | |
| "SourceNotApprovedError", | |
| "data_model", | |
| "enhance_model", | |
| "eval_model", | |
| "load_sources", | |
| "require_eval_models_approved", | |
| "require_models_approved", | |
| ] | |
| class DataModel: | |
| """One Phase 1 model. | |
| Attributes: | |
| key: Short id used in file names and reports (equals the ``sources.yaml`` id). | |
| source_id: Id in ``configs/sources.yaml``. | |
| worker: Worker module name in ``nida.data.workers``. | |
| ref: Model reference passed to the worker (``--model-id`` / ``--revision``). | |
| batch_size: Worker batch size (workers run clips one at a time; the batch only | |
| groups result writes and bounds the cost of an item-by-item retry). | |
| """ | |
| key: str | |
| source_id: str | |
| worker: str | |
| ref: ModelRef | |
| batch_size: int | |
| def _index(models: Iterable[DataModel]) -> Mapping[str, DataModel]: | |
| out: dict[str, DataModel] = {} | |
| for model in models: | |
| if model.key in out: | |
| raise ValueError(f"duplicate data model key {model.key}") | |
| out[model.key] = model | |
| return MappingProxyType(out) | |
| DATA_MODELS: Mapping[str, DataModel] = _index( | |
| ( | |
| DataModel( | |
| "panns_cnn14_dlm", | |
| "panns_cnn14_dlm", | |
| "sed_panns", | |
| ModelRef(ZENODO_MODEL_ID, ZENODO_REVISION), | |
| 8, | |
| ), | |
| DataModel( | |
| "sortformer_v2", | |
| "sortformer_v2", | |
| "diar_sortformer", | |
| ModelRef( | |
| "nvidia/diar_streaming_sortformer_4spk-v2", | |
| "84edd514b8ef68004c10086918cd62f2148cbd59", | |
| ), | |
| 1, | |
| ), | |
| DataModel( | |
| "mpoyraz_ctc_tr", | |
| "mpoyraz_ctc_tr", | |
| "ctc_emissions", | |
| ModelRef( | |
| "mpoyraz/wav2vec2-xls-r-300m-cv7-turkish", | |
| "708639f50559d7970f462e13ec64d3f059ca89f6", | |
| ), | |
| 8, | |
| ), | |
| DataModel( | |
| "emotion2vec_plus_large", | |
| "emotion2vec_plus_large", | |
| "emotion_e2v", | |
| ModelRef( | |
| "emotion2vec/emotion2vec_plus_large", | |
| "6c303ba987b86b93193de93e34bb2b077a6bedc4", | |
| ), | |
| 8, | |
| ), | |
| DataModel( | |
| "voxcpm2_audiovae_v2", | |
| "voxcpm2_audiovae_v2", | |
| "vae_encode", | |
| ModelRef( | |
| VAE_SYSTEMS["voxcpm2_audiovae_v2"].model_id, | |
| VAE_SYSTEMS["voxcpm2_audiovae_v2"].revision, | |
| ), | |
| 1, | |
| ), | |
| ) | |
| ) | |
| #: Speech-enhancement arms (``configs/data/enhance.yaml``), keyed like DATA_MODELS by their | |
| #: ``sources.yaml`` id. Pins: configs/sources.yaml (uvr_mdx_inst_hq3, sidon_v0_1, deepfilternet3). | |
| ENHANCE_MODELS: Mapping[str, DataModel] = _index( | |
| ( | |
| DataModel( | |
| "uvr_mdx_inst_hq3", | |
| "uvr_mdx_inst_hq3", | |
| "enhance_uvr", | |
| ModelRef( | |
| "UVR-MDX-NET-Inst_HQ_3.onnx", | |
| "sha256:317554b07fe1ea5279a77f2b1520a41ea4b93432560c4ffd08792c30fddf9adc", | |
| ), | |
| 1, | |
| ), | |
| DataModel( | |
| "sidon_v0_1", | |
| "sidon_v0_1", | |
| "enhance_sidon", | |
| ModelRef("sarulab-speech/sidon-v0.1", "b3b02d8bbd55fdbc410e6e46e76ef95ace4fbf52"), | |
| 1, | |
| ), | |
| DataModel( | |
| "deepfilternet3", | |
| "deepfilternet3", | |
| "enhance_dfn", | |
| ModelRef( | |
| "DeepFilterNet3", | |
| "sha256:23b92884f63ccf54bb026014604625ab231657b6480df65db4095c4c171e6003", | |
| ), | |
| 1, | |
| ), | |
| ) | |
| ) | |
| #: ``enhance.yaml`` arm -> key in :data:`ENHANCE_MODELS`. | |
| ENHANCE_ARM_KEYS: Mapping[str, str] = MappingProxyType( | |
| {"uvr": "uvr_mdx_inst_hq3", "sidon": "sidon_v0_1", "dfn": "deepfilternet3"} | |
| ) | |
| #: Evaluation / consistency-check models (speaker similarity, ``scripts/speaker_sim.py``), keyed | |
| #: by their ``sources.yaml`` id. Like the enhancement arms they are *not* in :data:`DATA_MODELS`: | |
| #: that mapping is hashed into the pilot's and the importer's config digests (and so into every | |
| #: dataset directory name), and measuring a dataset must not change its identity. | |
| EVAL_MODELS: Mapping[str, DataModel] = _index( | |
| ( | |
| DataModel( | |
| "speechbrain_ecapa_voxceleb", | |
| "speechbrain_ecapa_voxceleb", | |
| "spk_ecapa", | |
| ModelRef( | |
| "speechbrain/spkrec-ecapa-voxceleb", | |
| "0f99f2d0ebe89ac095bcc5903c4dd8f72b367286", | |
| ), | |
| 8, | |
| ), | |
| ) | |
| ) | |
| def data_model(key: str) -> DataModel: | |
| """Look up a model by key. | |
| Raises: | |
| KeyError: if the key is unknown (the message lists the known keys). | |
| """ | |
| try: | |
| return DATA_MODELS[key] | |
| except KeyError: | |
| raise KeyError(f"unknown data model {key!r}; known: {sorted(DATA_MODELS)}") from None | |
| def enhance_model(arm: str) -> DataModel: | |
| """The model of an enhancement ``arm`` (``uvr`` | ``sidon`` | ``dfn``). | |
| Raises: | |
| KeyError: for ``none`` or an unknown arm (the message lists the known arms). | |
| """ | |
| try: | |
| return ENHANCE_MODELS[ENHANCE_ARM_KEYS[arm]] | |
| except KeyError: | |
| raise KeyError( | |
| f"no enhancement model for arm {arm!r}; known: {sorted(ENHANCE_ARM_KEYS)}" | |
| ) from None | |
| def eval_model(key: str) -> DataModel: | |
| """Look up an evaluation model by key. | |
| Raises: | |
| KeyError: if the key is unknown (the message lists the known keys). | |
| """ | |
| try: | |
| return EVAL_MODELS[key] | |
| except KeyError: | |
| raise KeyError(f"unknown eval model {key!r}; known: {sorted(EVAL_MODELS)}") from None | |
| def require_eval_models_approved( | |
| keys: Iterable[str], sources: Mapping[str, Mapping[str, Any]] | |
| ) -> None: | |
| """Raise unless every evaluation model's source is ``approved`` in ``sources``. | |
| Raises: | |
| KeyError: on an unknown model key. | |
| SourceNotApprovedError: if a source is missing or not approved. | |
| """ | |
| require_approved([eval_model(key).source_id for key in keys], sources) | |
| def require_models_approved(keys: Iterable[str], sources: Mapping[str, Mapping[str, Any]]) -> None: | |
| """Raise unless every model's source is ``approved`` in ``sources``. | |
| Raises: | |
| KeyError: on an unknown model key. | |
| SourceNotApprovedError: if a source is missing or not approved. | |
| """ | |
| require_approved([data_model(key).source_id for key in keys], sources) | |