Download code/photontts/config.py from hello-test1/PhotonTTS: direct link, hf CLI and curl.
- Browser
- Download file 3.45 kB
-
https://huggingface.co/hello-test1/PhotonTTS/resolve/main/code/photontts/config.py
- Command line
-
hf download hf://hello-test1/PhotonTTS/code/photontts/config.py
-
curl -L -o config.py https://huggingface.co/hello-test1/PhotonTTS/resolve/main/code/photontts/config.py
3.45 kB
| """Typed configs, loadable from YAML. Nested dataclasses mirror the YAML sections.""" | |
| from __future__ import annotations | |
| import dataclasses | |
| from dataclasses import dataclass, field | |
| from pathlib import Path | |
| from typing import Any, get_type_hints | |
| import yaml | |
| class CodecConfig: | |
| sample_rate: int = 24_000 | |
| latent_dim: int = 64 | |
| enc_channels: list[int] = field(default_factory=lambda: [32, 64, 128, 256, 512]) | |
| enc_strides: list[int] = field(default_factory=lambda: [2, 4, 5, 6, 4]) # product = 960 | |
| dec_dim: int = 512 | |
| dec_layers: int = 8 | |
| dec_upsample: int = 4 # 25 Hz -> 100 Hz before iSTFT | |
| n_fft: int = 960 # iSTFT at 100 Hz: hop = 960 / dec_upsample = 240 | |
| kl_weight: float = 1e-4 | |
| semantic_dim: int = 0 # >0 enables semantic regularization projector | |
| semantic_weight: float = 1.0 | |
| class BackboneConfig: | |
| pretrained: str | None = None # e.g. "Qwen/Qwen3-0.6B"; None -> random init from fields below | |
| hidden_size: int = 1024 | |
| num_layers: int = 28 | |
| num_heads: int = 16 | |
| num_kv_heads: int = 8 | |
| intermediate_size: int = 3072 | |
| max_position: int = 8192 | |
| attn_implementation: str = "sdpa" | |
| gradient_checkpointing: bool = False | |
| class HeadConfig: | |
| dim: int = 512 | |
| layers: int = 6 | |
| heads: int = 8 | |
| n_ctx_patches: int = 2 | |
| noise_samples: int = 4 # flow-matching noise draws per backbone state | |
| p_uncond: float = 0.1 # CFG dropout of h_t | |
| ctx_noise: float = 0.1 # noise augmentation of context patches (anti exposure-bias) | |
| class SpeakerConfig: | |
| n_tokens: int = 32 | |
| dim: int = 512 | |
| layers: int = 4 | |
| heads: int = 8 | |
| p_drop: float = 0.1 # drop whole speaker conditioning (CFG / voice design) | |
| n_emotions: int = 0 # >0 enables gradient-reversal emotion adversary | |
| class ClockConfig: | |
| enabled: bool = True | |
| frame_dim: int = 128 # per-frame features fed to the head | |
| p_drop: float = 0.3 | |
| class LossConfig: | |
| stop_weight: float = 0.5 | |
| ctc_weight: float = 0.1 | |
| ctc_upsample: int = 4 # CTC runs at 12.5 * 4 = 50 Hz so byte targets fit | |
| class PhotonConfig: | |
| name: str = "photon-m" | |
| codec: CodecConfig = field(default_factory=CodecConfig) | |
| backbone: BackboneConfig = field(default_factory=BackboneConfig) | |
| head: HeadConfig = field(default_factory=HeadConfig) | |
| speaker: SpeakerConfig = field(default_factory=SpeakerConfig) | |
| clock: ClockConfig = field(default_factory=ClockConfig) | |
| loss: LossConfig = field(default_factory=LossConfig) | |
| tokenizer: str = "bytes" # "bytes" or an HF tokenizer name | |
| patch: int = 2 | |
| def _build(cls, data: dict[str, Any] | None): | |
| data = dict(data or {}) | |
| hints = get_type_hints(cls) | |
| kwargs = {} | |
| for f in dataclasses.fields(cls): | |
| if f.name not in data: | |
| continue | |
| val = data.pop(f.name) | |
| typ = hints[f.name] | |
| if dataclasses.is_dataclass(typ): | |
| val = _build(typ, val) | |
| kwargs[f.name] = val | |
| if data: | |
| raise ValueError(f"Unknown keys for {cls.__name__}: {sorted(data)}") | |
| return cls(**kwargs) | |
| def load_config(path: str | Path) -> PhotonConfig: | |
| with open(path, encoding="utf-8") as f: | |
| return _build(PhotonConfig, yaml.safe_load(f)) | |
| def config_from_dict(d: dict[str, Any]) -> PhotonConfig: | |
| return _build(PhotonConfig, d) | |
| def to_dict(cfg) -> dict[str, Any]: | |
| return dataclasses.asdict(cfg) | |