# pich09/tuna-tts architecture

> Architecture diagram of the GitHub repository pich09/tuna-tts, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pich09/tuna-tts
- Repository: https://github.com/pich09/tuna-tts

## Overview

Tuna-TTS adapts Fish Audio’s S1-mini for Khmer speech synthesis by extending its text vocabulary and training LoRA adapters plus new Khmer embeddings. The main workflow prepares split manifests and cached audio-codec targets, then normalizes and tokenizes text, packs dataset batches, builds the adapted model, and trains with checkpointing. Evaluation and checkpoint inference are separate result paths. The README documents these capabilities; source-index references and excerpts support the shown internal calls. Some implementation details—especially evaluation and precompute internals—were not excerpted, so those links rely on README statements.

Main entry points: [`training/trainer.py`](https://github.com/pich09/tuna-tts/blob/main/training/trainer.py) (Training loop), [`data/dataset.py`](https://github.com/pich09/tuna-tts/blob/main/data/dataset.py) (Training dataset), [`model/model_builder.py`](https://github.com/pich09/tuna-tts/blob/main/model/model_builder.py) (Model assembly), [`scripts/precompute_semantic_cache.py`](https://github.com/pich09/tuna-tts/blob/main/scripts/precompute_semantic_cache.py) (Semantic precompute)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_splits["Manifest splits<br/>[make_splits.py]"]
  node_normalize["Text normalization<br/>[text_normalize.py]"]
  node_sharding["Precompute sharding<br/>[sharding.py]"]
  node_precompute["Semantic precompute"]
  node_cache[("Semantic cache<br/>[semantic_cache.py]")]
  node_dataset["Training dataset<br/>[dataset.py]"]
  node_proto_dataset["Prototype dataset<br/>[proto_dataset.py]"]
  node_validation["Data validation<br/>[validation.py]"]
end

subgraph group_adapt["Khmer adaptation"]
  node_tokenizer["Tuna tokenizer<br/>[tuna_tokenizer.py]"]
  node_vocab["Vocabulary mapping<br/>[vocabulary.py]"]
  node_embedding["Embedding extension"]
  node_lora["LoRA adaptation<br/>[lora.py]"]
  node_builder["Model assembly<br/>[model_builder.py]"]
end

subgraph group_train["Training runtime"]
  node_collator["Batch collator<br/>[collator.py]"]
  node_scheduler["WSD scheduler<br/>[scheduler.py]"]
  node_distributed["Distributed runtime<br/>[distributed.py]"]
  node_trainer["Training loop<br/>[trainer.py]"]
  node_checkpoint[("Checkpoint manager<br/>[checkpoint.py]")]
  node_hub["Hub upload<br/>[hub_upload.py]"]
end

subgraph group_results["Evaluation and inference"]
  node_evaluate["Evaluation scoring<br/>[evaluate.py]"]
  node_generate["Sample generation"]
  node_inference["Checkpoint inference"]
end

node_engineer(("Training operator"))
node_source_data[("Processed corpus")]
node_base_model[("S1-mini checkpoint")]

node_engineer -->|"prepares splits"| node_splits
node_source_data -->|"provides corpus"| node_splits
node_splits -->|"creates manifest"| node_dataset
node_engineer -->|"starts precompute"| node_precompute
node_precompute -->|"uses shards"| node_sharding
node_precompute -->|"writes targets"| node_cache
node_dataset -->|"normalizes text"| node_normalize
node_dataset -->|"tokenizes text"| node_tokenizer
node_tokenizer -->|"maps IDs"| node_vocab
node_dataset -->|"reads targets"| node_cache
node_dataset -.->|"alternative data path"| node_proto_dataset
node_dataset -.->|"validates inputs"| node_validation
node_engineer -->|"runs training"| node_trainer
node_trainer -->|"loads samples"| node_dataset
node_trainer -->|"batches samples"| node_collator
node_trainer -->|"builds model"| node_builder
node_builder -->|"loads checkpoint"| node_base_model
node_builder -->|"extends embeddings"| node_embedding
node_builder -->|"attaches adapters"| node_lora
node_trainer -->|"schedules learning rate"| node_scheduler
node_trainer -->|"configures ranks"| node_distributed
node_trainer -->|"saves state"| node_checkpoint
node_trainer -.->|"uploads model"| node_hub
node_engineer -->|"scores model"| node_evaluate
node_engineer -->|"generates samples"| node_generate
node_engineer -->|"runs checkpoint"| node_inference
node_inference -->|"loads model"| node_builder
node_inference -->|"encodes text"| node_tokenizer

click node_splits "https://github.com/pich09/tuna-tts/blob/main/scripts/make_splits.py"
click node_normalize "https://github.com/pich09/tuna-tts/blob/main/data/text_normalize.py"
click node_tokenizer "https://github.com/pich09/tuna-tts/blob/main/tokenizer/tuna_tokenizer.py"
click node_vocab "https://github.com/pich09/tuna-tts/blob/main/tokenizer/vocabulary.py"
click node_sharding "https://github.com/pich09/tuna-tts/blob/main/data/sharding.py"
click node_precompute "https://github.com/pich09/tuna-tts/blob/main/scripts/precompute_semantic_cache.py"
click node_cache "https://github.com/pich09/tuna-tts/blob/main/data/semantic_cache.py"
click node_dataset "https://github.com/pich09/tuna-tts/blob/main/data/dataset.py"
click node_proto_dataset "https://github.com/pich09/tuna-tts/blob/main/data/proto_dataset.py"
click node_validation "https://github.com/pich09/tuna-tts/blob/main/data/validation.py"
click node_collator "https://github.com/pich09/tuna-tts/blob/main/data/collator.py"
click node_embedding "https://github.com/pich09/tuna-tts/blob/main/model/embedding_extension.py"
click node_lora "https://github.com/pich09/tuna-tts/blob/main/model/lora.py"
click node_builder "https://github.com/pich09/tuna-tts/blob/main/model/model_builder.py"
click node_scheduler "https://github.com/pich09/tuna-tts/blob/main/training/scheduler.py"
click node_distributed "https://github.com/pich09/tuna-tts/blob/main/training/distributed.py"
click node_trainer "https://github.com/pich09/tuna-tts/blob/main/training/trainer.py"
click node_checkpoint "https://github.com/pich09/tuna-tts/blob/main/training/checkpoint.py"
click node_hub "https://github.com/pich09/tuna-tts/blob/main/training/hub_upload.py"
click node_evaluate "https://github.com/pich09/tuna-tts/blob/main/evaluation/evaluate.py"
click node_generate "https://github.com/pich09/tuna-tts/blob/main/evaluation/generate_samples.py"
click node_inference "https://github.com/pich09/tuna-tts/blob/main/scripts/run_inference_checkpoint.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_splits,node_normalize,node_sharding,node_precompute,node_cache,node_dataset,node_proto_dataset,node_validation toneBlue
class node_tokenizer,node_vocab,node_embedding,node_lora,node_builder,node_source_data,node_base_model toneAmber
class node_collator,node_scheduler,node_distributed,node_trainer,node_checkpoint,node_hub toneMint
class node_evaluate,node_generate,node_inference toneRose
class node_engineer toneIndigo
```

## Components

### Data preparation

- [Manifest splits](https://github.com/pich09/tuna-tts/blob/main/scripts/make_splits.py): `scripts/make_splits.py`
- [Text normalization](https://github.com/pich09/tuna-tts/blob/main/data/text_normalize.py): `data/text_normalize.py`
- [Precompute sharding](https://github.com/pich09/tuna-tts/blob/main/data/sharding.py): `data/sharding.py`
- [Semantic precompute](https://github.com/pich09/tuna-tts/blob/main/scripts/precompute_semantic_cache.py): `scripts/precompute_semantic_cache.py`
- [Semantic cache](https://github.com/pich09/tuna-tts/blob/main/data/semantic_cache.py): `data/semantic_cache.py`
- [Training dataset](https://github.com/pich09/tuna-tts/blob/main/data/dataset.py): `data/dataset.py`
- [Prototype dataset](https://github.com/pich09/tuna-tts/blob/main/data/proto_dataset.py): `data/proto_dataset.py`
- [Data validation](https://github.com/pich09/tuna-tts/blob/main/data/validation.py): `data/validation.py`

### Khmer adaptation

- [Tuna tokenizer](https://github.com/pich09/tuna-tts/blob/main/tokenizer/tuna_tokenizer.py): `tokenizer/tuna_tokenizer.py`
- [Vocabulary mapping](https://github.com/pich09/tuna-tts/blob/main/tokenizer/vocabulary.py): `tokenizer/vocabulary.py`
- [Embedding extension](https://github.com/pich09/tuna-tts/blob/main/model/embedding_extension.py): `model/embedding_extension.py`
- [LoRA adaptation](https://github.com/pich09/tuna-tts/blob/main/model/lora.py): `model/lora.py`
- [Model assembly](https://github.com/pich09/tuna-tts/blob/main/model/model_builder.py): `model/model_builder.py`

### Training runtime

- [Batch collator](https://github.com/pich09/tuna-tts/blob/main/data/collator.py): `data/collator.py`
- [WSD scheduler](https://github.com/pich09/tuna-tts/blob/main/training/scheduler.py): `training/scheduler.py`
- [Distributed runtime](https://github.com/pich09/tuna-tts/blob/main/training/distributed.py): `training/distributed.py`
- [Training loop](https://github.com/pich09/tuna-tts/blob/main/training/trainer.py): `training/trainer.py`
- [Checkpoint manager](https://github.com/pich09/tuna-tts/blob/main/training/checkpoint.py): `training/checkpoint.py`
- [Hub upload](https://github.com/pich09/tuna-tts/blob/main/training/hub_upload.py): `training/hub_upload.py`

### Evaluation and inference

- [Evaluation scoring](https://github.com/pich09/tuna-tts/blob/main/evaluation/evaluate.py): `evaluation/evaluate.py`
- [Sample generation](https://github.com/pich09/tuna-tts/blob/main/evaluation/generate_samples.py): `evaluation/generate_samples.py`
- [Checkpoint inference](https://github.com/pich09/tuna-tts/blob/main/scripts/run_inference_checkpoint.py): `scripts/run_inference_checkpoint.py`

### Other components

- **Training operator**
- **Processed corpus**
- **S1-mini checkpoint**

## Connections

- Training operator → Manifest splits: prepares splits (evidence: `README.md`)
- Processed corpus → Manifest splits: provides corpus (evidence: `README.md`)
- Manifest splits → Training dataset: creates manifest (evidence: `README.md`)
- Training operator → Semantic precompute: starts precompute (evidence: `README.md`)
- Semantic precompute → Precompute sharding: uses shards (evidence: `scripts/precompute_semantic_cache.py`)
- Semantic precompute → Semantic cache: writes targets (evidence: `data/semantic_cache.py`)
- Training dataset → Text normalization: normalizes text (evidence: `data/dataset.py`)
- Training dataset → Tuna tokenizer: tokenizes text (evidence: `data/dataset.py`)
- Tuna tokenizer → Vocabulary mapping: maps IDs (evidence: `tokenizer/tuna_tokenizer.py`)
- Training dataset → Semantic cache: reads targets (evidence: `data/dataset.py`)
- Training dataset → Prototype dataset: alternative data path (evidence: `training/trainer.py`)
- Training dataset → Data validation: validates inputs (evidence: `README.md`)
- Training operator → Training loop: runs training (evidence: `README.md`)
- Training loop → Training dataset: loads samples (evidence: `training/trainer.py`)
- Training loop → Batch collator: batches samples (evidence: `training/trainer.py`)
- Training loop → Model assembly: builds model (evidence: `training/trainer.py`)
- Model assembly → S1-mini checkpoint: loads checkpoint (evidence: `model/model_builder.py`)
- Model assembly → Embedding extension: extends embeddings (evidence: `model/model_builder.py`)
- Model assembly → LoRA adaptation: attaches adapters (evidence: `model/model_builder.py`)
- Training loop → WSD scheduler: schedules learning rate (evidence: `training/trainer.py`)
- Training loop → Distributed runtime: configures ranks (evidence: `training/trainer.py`)
- Training loop → Checkpoint manager: saves state (evidence: `training/trainer.py`)
- Training loop → Hub upload: uploads model (evidence: `training/trainer.py`)
- Training operator → Evaluation scoring: scores model (evidence: `README.md`)
- Training operator → Sample generation: generates samples (evidence: `README.md`)
- Training operator → Checkpoint inference: runs checkpoint (evidence: `README.md`)
- Checkpoint inference → Model assembly: loads model (evidence: `scripts/run_inference_checkpoint.py`)
- Checkpoint inference → Tuna tokenizer: encodes text (evidence: `scripts/run_inference_checkpoint.py`)
