# aslp-lab/diffrhythm architecture

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

- Interactive diagram: https://gitdiagram.com/aslp-lab/diffrhythm
- Repository: https://github.com/aslp-lab/diffrhythm

## Overview

DiffRhythm generates full-length songs from timed lyrics and style or audio references, with documented text-prompt and instrumental modes, plus song editing and continuation. Inference prepares inputs, converts lyrics to phoneme tokens, and invokes the model utilities; training is a separate capability using a diffusion dataset. The sampled excerpts support the main inference, G2P, model, and training-data connections. Some README-described generation modes and internals are unsampled, so those are represented at the subsystem level rather than as guessed call chains.

Main entry points: [`infer/infer.py`](https://github.com/aslp-lab/diffrhythm/blob/main/infer/infer.py) (Inference Runner), [`infer/infer_utils.py`](https://github.com/aslp-lab/diffrhythm/blob/main/infer/infer_utils.py) (Audio and Model Utilities), [`g2p/g2p_generation.py`](https://github.com/aslp-lab/diffrhythm/blob/main/g2p/g2p_generation.py) (Lyrics G2P), [`g2p/g2p`](https://github.com/aslp-lab/diffrhythm/tree/main/g2p/g2p) (Language Tokenizers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inference["Song Inference"]
  node_inference["Inference Runner<br/>[infer.py]"]
  node_infer_utils["Audio and Model Utilities<br/>[infer_utils.py]"]
  node_song["Generated Song"]
end

subgraph group_lyrics["Lyrics Processing"]
  node_g2p_generation["Lyrics G2P<br/>[g2p_generation.py]"]
  node_phoneme_backend["Phoneme Backend<br/>[g2p.py]"]
  node_tokenizers["Language Tokenizers"]
  node_mandarin["Mandarin Processing<br/>[mandarin.py]"]
  node_polyphone["Polyphone Prediction"]
  node_language_segment["Language Segmentation<br/>[LangSegment.py]"]
end

subgraph group_generation["Diffusion Model"]
  node_cfm["Flow Matching<br/>[cfm.py]"]
  node_dit["DiT Network<br/>[dit.py]"]
  node_model_modules["Neural Components<br/>[modules.py]"]
  node_model_utils["Model Utilities<br/>[utils.py]"]
end

subgraph group_training["Model Training"]
  node_training_entry["Training Entry<br/>[train.py]"]
  node_trainer["Training Orchestrator<br/>[trainer.py]"]
  node_dataset["Diffusion Dataset<br/>[dataset.py]"]
end

node_user(("Composer"))

node_user -->|"requests generation"| node_inference
node_inference -->|"uses utilities"| node_infer_utils
node_infer_utils -->|"tokenizes lyrics"| node_g2p_generation
node_infer_utils -->|"loads model"| node_cfm
node_inference -->|"generates audio"| node_song
node_g2p_generation -->|"phonemizes text"| node_phoneme_backend
node_g2p_generation -->|"uses tokenizer"| node_tokenizers
node_tokenizers -->|"uses segmentation"| node_language_segment
node_tokenizers -->|"dispatches language"| node_mandarin
node_mandarin -->|"predicts pronunciation"| node_polyphone
node_cfm -->|"uses helpers"| node_model_utils
node_dit -->|"uses components"| node_model_modules
node_training_entry -->|"imports model"| node_cfm
node_trainer -->|"loads training data"| node_dataset

click node_inference "https://github.com/aslp-lab/diffrhythm/blob/main/infer/infer.py"
click node_infer_utils "https://github.com/aslp-lab/diffrhythm/blob/main/infer/infer_utils.py"
click node_g2p_generation "https://github.com/aslp-lab/diffrhythm/blob/main/g2p/g2p_generation.py"
click node_phoneme_backend "https://github.com/aslp-lab/diffrhythm/blob/main/g2p/utils/g2p.py"
click node_tokenizers "https://github.com/aslp-lab/diffrhythm/tree/main/g2p/g2p"
click node_mandarin "https://github.com/aslp-lab/diffrhythm/blob/main/g2p/g2p/mandarin.py"
click node_polyphone "https://github.com/aslp-lab/diffrhythm/blob/main/g2p/g2p/chinese_model_g2p.py"
click node_language_segment "https://github.com/aslp-lab/diffrhythm/blob/main/thirdparty/LangSegment/LangSegment.py"
click node_cfm "https://github.com/aslp-lab/diffrhythm/blob/main/model/cfm.py"
click node_dit "https://github.com/aslp-lab/diffrhythm/blob/main/model/dit.py"
click node_model_modules "https://github.com/aslp-lab/diffrhythm/blob/main/model/modules.py"
click node_model_utils "https://github.com/aslp-lab/diffrhythm/blob/main/model/utils.py"
click node_training_entry "https://github.com/aslp-lab/diffrhythm/blob/main/train/train.py"
click node_trainer "https://github.com/aslp-lab/diffrhythm/blob/main/model/trainer.py"
click node_dataset "https://github.com/aslp-lab/diffrhythm/blob/main/dataset/dataset.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_inference,node_infer_utils,node_song toneBlue
class node_g2p_generation,node_phoneme_backend,node_tokenizers,node_mandarin,node_polyphone,node_language_segment toneAmber
class node_cfm,node_dit,node_model_modules,node_model_utils toneMint
class node_training_entry,node_trainer,node_dataset toneRose
class node_user toneIndigo
```

## Components

### Song Inference

- [Inference Runner](https://github.com/aslp-lab/diffrhythm/blob/main/infer/infer.py): `infer/infer.py`
- [Audio and Model Utilities](https://github.com/aslp-lab/diffrhythm/blob/main/infer/infer_utils.py): `infer/infer_utils.py`
- **Generated Song**

### Lyrics Processing

- [Lyrics G2P](https://github.com/aslp-lab/diffrhythm/blob/main/g2p/g2p_generation.py): `g2p/g2p_generation.py`
- [Phoneme Backend](https://github.com/aslp-lab/diffrhythm/blob/main/g2p/utils/g2p.py): `g2p/utils/g2p.py`
- [Language Tokenizers](https://github.com/aslp-lab/diffrhythm/tree/main/g2p/g2p): `g2p/g2p`
- [Mandarin Processing](https://github.com/aslp-lab/diffrhythm/blob/main/g2p/g2p/mandarin.py): `g2p/g2p/mandarin.py`
- [Polyphone Prediction](https://github.com/aslp-lab/diffrhythm/blob/main/g2p/g2p/chinese_model_g2p.py): `g2p/g2p/chinese_model_g2p.py`
- [Language Segmentation](https://github.com/aslp-lab/diffrhythm/blob/main/thirdparty/LangSegment/LangSegment.py): `thirdparty/LangSegment/LangSegment.py`

### Diffusion Model

- [Flow Matching](https://github.com/aslp-lab/diffrhythm/blob/main/model/cfm.py): `model/cfm.py`
- [DiT Network](https://github.com/aslp-lab/diffrhythm/blob/main/model/dit.py): `model/dit.py`
- [Neural Components](https://github.com/aslp-lab/diffrhythm/blob/main/model/modules.py): `model/modules.py`
- [Model Utilities](https://github.com/aslp-lab/diffrhythm/blob/main/model/utils.py): `model/utils.py`

### Model Training

- [Training Entry](https://github.com/aslp-lab/diffrhythm/blob/main/train/train.py): `train/train.py`
- [Training Orchestrator](https://github.com/aslp-lab/diffrhythm/blob/main/model/trainer.py): `model/trainer.py`
- [Diffusion Dataset](https://github.com/aslp-lab/diffrhythm/blob/main/dataset/dataset.py): `dataset/dataset.py`

### Other components

- **Composer**

## Connections

- Composer → Inference Runner: requests generation (evidence: `Readme.md`)
- Inference Runner → Audio and Model Utilities: uses utilities (evidence: `infer/infer.py`)
- Audio and Model Utilities → Lyrics G2P: tokenizes lyrics (evidence: `infer/infer_utils.py`)
- Audio and Model Utilities → Flow Matching: loads model (evidence: `infer/infer_utils.py`)
- Inference Runner → Generated Song: generates audio (evidence: `Readme.md`)
- Lyrics G2P → Phoneme Backend: phonemizes text (evidence: `g2p/g2p_generation.py`)
- Lyrics G2P → Language Tokenizers: uses tokenizer (evidence: `g2p/g2p_generation.py`)
- Language Tokenizers → Language Segmentation: uses segmentation (evidence: `g2p/g2p/__init__.py`)
- Language Tokenizers → Mandarin Processing: dispatches language (evidence: `g2p/g2p/cleaners.py`)
- Mandarin Processing → Polyphone Prediction: predicts pronunciation (evidence: `g2p/g2p/mandarin.py`)
- Flow Matching → Model Utilities: uses helpers (evidence: `model/cfm.py`)
- DiT Network → Neural Components: uses components (evidence: `model/dit.py`)
- Training Entry → Flow Matching: imports model (evidence: `train/train.py`)
- Training Orchestrator → Diffusion Dataset: loads training data (evidence: `model/trainer.py`)
