# openbmb/voxcpm architecture

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

- Interactive diagram: https://gitdiagram.com/openbmb/voxcpm
- Repository: https://github.com/openbmb/voxcpm

## Overview

1. **What this repo is**
   - This is a Python package for VoxCPM TTS, centered on **inference, fine-tuning, and demos** for multiple model generations: **VoxCPM**, **VoxCPM1.5**, and **VoxCPM2**.
   - The repository is organized as an installable library under `src/voxcpm`, plus runnable entry points for CLI, training, and web demos.

2. **Top-level entry points**
   - `src/voxcpm/cli.py` exposes the command-line interface used by the README flows such as **design**, **clone**, and **batch** generation.
   - `app.py` is the main browser-based demo server.
   - `lora_ft_webui.py` is a separate web UI focused on **LoRA fine-tuning and inference**.
   - `scripts/*.py` contains standalone utilities for training, inference checks, and runtime tests.

3. **Core inference boundary**
   - `src/voxcpm/core.py` is the main orchestration layer that ties together model loading, generation APIs, streaming, and the different voice modes.
   - The public package surface in `src/voxcpm/__init__.py` likely re-exports the main user-facing model wrapper so applications can call `VoxCPM.from_pretrained(...)` and generate audio without touching internals.

4. **Model versioning**
   - Version-specific logic lives in `src/voxcpm/model/voxcpm.py` and `src/voxcpm/model/voxcpm2.py`.
   - `src/voxcpm/model/utils.py` contains shared model helpers.
   - The `conf/voxcpm_v1`, `conf/voxcpm_v1.5`, and `conf/voxcpm_v2` folders hold versioned YAML configs for full finetuning and LoRA finetuning, which is a strong sign the repo keeps **architecture-compatible model variants** side by side.

5. **Main model pipeline**
   - The README describes the VoxCPM2 architecture as a four-stage latent-speech pipeline: **LocEnc → TSLM → RALM → LocDiT**.
   - Those stages are reflected in the code layout:
     - `modules/locenc/` for the local encoder,
     - `modules/minicpm4/` for the language-model backbone,
     - `modules/locdit/` for the diffusion/flow-matching speech generator,
     - `modules/audiovae/` for audio latent encoding/decoding.
   - This is the central architectural boundary: the system does **not** generate waveform samples directly from text; it generates speech latents and then decodes them.

6. **Audio subsystem**
   - `src/voxcpm/modules/audiovae/audio_vae.py` and `audio_vae_v2.py` implement the audio representation layer.
   - VoxCPM2’s README emphasizes **48 kHz output** from **16 kHz reference input**, so the AudioVAE layer is not just a compressor; it also serves as the model’s speech-domain interface and reconstruction path.
   - This subsystem is the final step that turns latent speech representations into playable audio.

7. **Text/model backbone subsystem**
   - `src/voxcpm/modules/minicpm4/` contains the MiniCPM-4-based backbone integration.
   - Files like `config.py`, `model.py`, and `cache.py` indicate standard LLM-style concerns: configuration, forward pass, and KV-cache/state handling for generation.
   - This backbone is the part that converts normalized text and context into the intermediate conditioning sequence consumed by the speech generator.

8. **Generation/control layers**
   - `src/voxcpm/modules/locdit/local_dit.py`, `local_dit_v2.py`, and `unified_cfm.py` implement the diffusion/flow-matching generation stage.
   - `src/voxcpm/modules/layers/lora.py` shows LoRA is integrated at the model layer rather than as a separate training-only fork.
   - `scalar_quantization_layer.py` suggests the repo also includes speech/token representation plumbing for compact latent handling.
   - Together these modules define the controllable generation path used for **voice design**, **cloning**, and **continuation-style synthesis**.

9. **Training subsystem**
   - `src/voxcpm/training/` is a complete training stack with accelerator setup, configs, dataset loading, packing, state management, tracking, and validation.
   - The main training script is `scripts/train_voxcpm_finetune.py`, which consumes the YAML configs in `conf/`.
   - This stack supports the two finetuning modes called out in the README: **full SFT** and **LoRA finetuning**.
   - The presence of `validate.py` and `tracker.py` suggests training is instrumented with periodic evaluation and experiment logging, rather than being a minimal one-off script.

10. **Data flow for finetuning**
   - Example training data is stored in `examples/train_data_example.jsonl`, implying a line-delimited metadata format for audio/text supervision.
   - `src/voxcpm/training/data.py` and `packers.py` are the likely boundary between raw manifest records and model-ready training batches.
   - The flow is: dataset manifest → packing/normalization → training state/accelerator → model update → validation.

11. **User-facing input/output helpers**
   - `src/voxcpm/utils/text_normalize.py` handles text preprocessing, which matters because the system supports many languages and likely needs normalization before synthesis.
   - `src/voxcpm/zipenhancer.py` is a small utility module outside the main model stack; it looks like a packaging or archive helper, not a core inference component.
   - `examples/example.wav` and `examples/reference_speaker.wav` serve as canonical reference assets for cloning and demo paths.

12. **Testing and verification**
   - `tests/` and `scripts/test_*.py` show the repo validates both the package API and the model behaviors.
   - The test suite covers CLI behavior, model utilities, validation logic, LoRA checkpoint loading, and runtime dtype selection.
   - That tells you the architecture has a clear separation between **model correctness**, **CLI surface**, and **training/validation logic**.

13. **Packaging and release**
   - `pyproject.toml`, `uv.lock`, and `.github/workflows/publish-to-pypi.yml` show this is packaged for standard Python distribution and automated PyPI release.
   - The repo is meant to be consumed as an installable library, but also ships runnable scripts and demo entry points.
   - In architectural terms, that means the source tree is not just research code; it is structured for both **library reuse** and **end-user execution**.

14. **Overall architecture shape**
   - The cleanest diagram is: **UI/CLI/script entry points** → **core orchestration** → **versioned model wrappers** → **shared modules** (MiniCPM backbone, local encoder, diffusion generator, AudioVAE, LoRA/quantization layers) → **audio output**.
   - The training path shares the same model modules but swaps the source of inputs: instead of prompt-time text/reference audio, it consumes dataset manifests and validation loops.
   - Version-specific YAML configs and examples keep the same codebase adaptable across VoxCPM generations without changing the public API.

Main entry points: [`src/voxcpm/model/voxcpm2.py`](https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/model/voxcpm2.py) (VoxCPM2), [`src/voxcpm/core.py`](https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/core.py) (Orchestrator), [`src/voxcpm/training/config.py`](https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/training/config.py) (Training stack), [`src/voxcpm/model/utils.py`](https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/model/utils.py) (Model utils)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_entry["Entry points"]
  node_n_cli["CLI<br/>command line<br/>[cli.py]"]
  node_n_app["Web demo<br/>browser app<br/>[app.py]"]
  node_n_lora_ui["LoRA UI<br/>web ui<br/>[lora_ft_webui.py]"]
  node_n_scripts_train["Train script<br/>training entry"]
  node_n_scripts_test["Inference checks<br/>script suite"]
end

subgraph group_grp_core["Library core"]
  node_n_pkg["Package API<br/>public surface<br/>[__init__.py]"]
  node_n_core["Orchestrator<br/>runtime core<br/>[core.py]"]
end

subgraph group_grp_model["Model stack"]
  node_n_voxcpm1["VoxCPM<br/>version wrapper<br/>[voxcpm.py]"]
  node_n_voxcpm2["VoxCPM2<br/>version wrapper<br/>[voxcpm2.py]"]
  node_n_model_utils["Model utils<br/>shared helpers<br/>[utils.py]"]
  node_n_locenc["LocEnc<br/>local encoder<br/>[local_encoder.py]"]
  node_n_minicpm4["MiniCPM-4<br/>llm backbone<br/>[model.py]"]
  node_n_locdit["LocDiT<br/>speech generator<br/>[local_dit_v2.py]"]
  node_n_cfm["CFM<br/>generation core<br/>[unified_cfm.py]"]
  node_n_audiovae["AudioVAE<br/>audio codec<br/>[audio_vae_v2.py]"]
  node_n_lora["LoRA<br/>adapter layer<br/>[lora.py]"]
  node_n_quant["Quantization<br/>token layer"]
end

subgraph group_grp_train["Training"]
  node_n_train["Training stack<br/>finetuning core<br/>[config.py]"]
  node_n_validate["Validation<br/>eval loop<br/>[validate.py]"]
end

subgraph group_grp_assets["Configs & examples"]
  node_n_cfg_v1["V1 configs<br/>yaml config"]
  node_n_cfg_v15["V1.5 configs<br/>yaml config"]
  node_n_cfg_v2["V2 configs<br/>yaml config"]
  node_n_example_data["Train data<br/>jsonl manifest"]
end

node_n_cli -->|"inference"| node_n_core
node_n_app -->|"demo inference"| node_n_core
node_n_lora_ui -->|"lora inference"| node_n_core
node_n_pkg -->|"exports"| node_n_core
node_n_core -->|"loads"| node_n_voxcpm1
node_n_core -->|"loads"| node_n_voxcpm2
node_n_voxcpm1 -->|"shares"| node_n_model_utils
node_n_voxcpm2 -->|"shares"| node_n_model_utils
node_n_voxcpm2 -->|"uses"| node_n_locenc
node_n_voxcpm2 -->|"uses"| node_n_minicpm4
node_n_voxcpm2 -->|"uses"| node_n_locdit
node_n_voxcpm2 -->|"uses"| node_n_audiovae
node_n_locdit -->|"built on"| node_n_cfm
node_n_voxcpm2 -->|"adapts"| node_n_lora
node_n_voxcpm2 -->|"plumbs"| node_n_quant
node_n_scripts_train -->|"invokes"| node_n_train
node_n_train -->|"reads"| node_n_example_data
node_n_train -->|"configures"| node_n_cfg_v1
node_n_train -->|"configures"| node_n_cfg_v15
node_n_train -->|"configures"| node_n_cfg_v2
node_n_train -->|"includes"| node_n_validate
node_n_scripts_test -->|"checks"| node_n_core
node_n_scripts_test -->|"checks"| node_n_lora
node_n_cli -.->|"normalizes"| node_n_model_utils

click node_n_cli "https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/cli.py"
click node_n_app "https://github.com/openbmb/voxcpm/blob/main/app.py"
click node_n_lora_ui "https://github.com/openbmb/voxcpm/blob/main/lora_ft_webui.py"
click node_n_scripts_train "https://github.com/openbmb/voxcpm/blob/main/scripts/train_voxcpm_finetune.py"
click node_n_scripts_test "https://github.com/openbmb/voxcpm/blob/main/scripts/test_voxcpm_ft_infer.py"
click node_n_pkg "https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/__init__.py"
click node_n_core "https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/core.py"
click node_n_voxcpm1 "https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/model/voxcpm.py"
click node_n_voxcpm2 "https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/model/voxcpm2.py"
click node_n_model_utils "https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/model/utils.py"
click node_n_locenc "https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/modules/locenc/local_encoder.py"
click node_n_minicpm4 "https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/modules/minicpm4/model.py"
click node_n_locdit "https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/modules/locdit/local_dit_v2.py"
click node_n_cfm "https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/modules/locdit/unified_cfm.py"
click node_n_audiovae "https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/modules/audiovae/audio_vae_v2.py"
click node_n_lora "https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/modules/layers/lora.py"
click node_n_quant "https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/modules/layers/scalar_quantization_layer.py"
click node_n_train "https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/training/config.py"
click node_n_validate "https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/training/validate.py"
click node_n_cfg_v1 "https://github.com/openbmb/voxcpm/blob/main/conf/voxcpm_v1/voxcpm_finetune_all.yaml"
click node_n_cfg_v15 "https://github.com/openbmb/voxcpm/blob/main/conf/voxcpm_v1.5/voxcpm_finetune_all.yaml"
click node_n_cfg_v2 "https://github.com/openbmb/voxcpm/blob/main/conf/voxcpm_v2/voxcpm_finetune_all.yaml"
click node_n_example_data "https://github.com/openbmb/voxcpm/blob/main/examples/train_data_example.jsonl"

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_n_cli,node_n_app,node_n_lora_ui,node_n_scripts_train,node_n_scripts_test toneBlue
class node_n_pkg,node_n_core toneAmber
class node_n_voxcpm1,node_n_voxcpm2,node_n_model_utils,node_n_locenc,node_n_minicpm4,node_n_locdit,node_n_cfm,node_n_audiovae,node_n_lora,node_n_quant toneMint
class node_n_train,node_n_validate toneRose
class node_n_cfg_v1,node_n_cfg_v15,node_n_cfg_v2,node_n_example_data toneIndigo
```

## Components

### Entry points

User-facing CLI, web, and script entry points

- [CLI](https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/cli.py): command line · Command-line interface for design, clone, and batch flows · `src/voxcpm/cli.py`
- [Web demo](https://github.com/openbmb/voxcpm/blob/main/app.py): browser app · Main browser-based demo server · `app.py`
- [LoRA UI](https://github.com/openbmb/voxcpm/blob/main/lora_ft_webui.py): web ui · Web UI for LoRA fine-tuning and inference · `lora_ft_webui.py`
- [Train script](https://github.com/openbmb/voxcpm/blob/main/scripts/train_voxcpm_finetune.py): training entry · Standalone finetuning runner · `scripts/train_voxcpm_finetune.py`
- [Inference checks](https://github.com/openbmb/voxcpm/blob/main/scripts/test_voxcpm_ft_infer.py): script suite · Standalone runtime and inference verification scripts · `scripts/test_voxcpm_ft_infer.py`

### Library core

Public package surface and orchestration

- [Package API](https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/__init__.py): public surface · Library exports for external consumers · `src/voxcpm/__init__.py`
- [Orchestrator](https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/core.py): runtime core · Main inference orchestration across loading, generation, streaming, and voice modes · `src/voxcpm/core.py`

### Model stack

Versioned model wrappers and shared generation modules

- [VoxCPM](https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/model/voxcpm.py): version wrapper · First-generation model wrapper · `src/voxcpm/model/voxcpm.py`
- [VoxCPM2](https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/model/voxcpm2.py): version wrapper · Second-generation model wrapper · `src/voxcpm/model/voxcpm2.py`
- [Model utils](https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/model/utils.py): shared helpers · Common model helpers used across generations · `src/voxcpm/model/utils.py`
- [LocEnc](https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/modules/locenc/local_encoder.py): local encoder · Speech context and local encoding stage · `src/voxcpm/modules/locenc/local_encoder.py`
- [MiniCPM-4](https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/modules/minicpm4/model.py): llm backbone · Backbone language model integration with config, forward, and cache handling · `src/voxcpm/modules/minicpm4/model.py`
- [LocDiT](https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/modules/locdit/local_dit_v2.py): speech generator · Diffusion / flow-matching latent speech generation · `src/voxcpm/modules/locdit/local_dit_v2.py`
- [CFM](https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/modules/locdit/unified_cfm.py): generation core · Unified conditional flow-matching generation logic · `src/voxcpm/modules/locdit/unified_cfm.py`
- [AudioVAE](https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/modules/audiovae/audio_vae_v2.py): audio codec · Latent audio encode/decode path and reconstruction interface · `src/voxcpm/modules/audiovae/audio_vae_v2.py`
- [LoRA](https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/modules/layers/lora.py): adapter layer · Low-rank adaptation support integrated at the model layer · `src/voxcpm/modules/layers/lora.py`
- [Quantization](https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/modules/layers/scalar_quantization_layer.py): token layer · Scalar quantization and latent token plumbing · `src/voxcpm/modules/layers/scalar_quantization_layer.py`

### Training

Fine-tuning and validation pipeline

- [Training stack](https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/training/config.py): finetuning core · Accelerator, config, data, state, tracking, and validation · `src/voxcpm/training/config.py`
- [Validation](https://github.com/openbmb/voxcpm/blob/main/src/voxcpm/training/validate.py): eval loop · Training-time validation and evaluation logic · `src/voxcpm/training/validate.py`

### Configs & examples

Versioned configs and example artifacts

- [V1 configs](https://github.com/openbmb/voxcpm/blob/main/conf/voxcpm_v1/voxcpm_finetune_all.yaml): yaml config · Versioned finetuning configs for VoxCPM v1 · `conf/voxcpm_v1/voxcpm_finetune_all.yaml`
- [V1.5 configs](https://github.com/openbmb/voxcpm/blob/main/conf/voxcpm_v1.5/voxcpm_finetune_all.yaml): yaml config · Versioned finetuning configs for VoxCPM v1.5 · `conf/voxcpm_v1.5/voxcpm_finetune_all.yaml`
- [V2 configs](https://github.com/openbmb/voxcpm/blob/main/conf/voxcpm_v2/voxcpm_finetune_all.yaml): yaml config · Versioned finetuning configs for VoxCPM v2 · `conf/voxcpm_v2/voxcpm_finetune_all.yaml`
- [Train data](https://github.com/openbmb/voxcpm/blob/main/examples/train_data_example.jsonl): jsonl manifest · Example line-delimited training dataset manifest · `examples/train_data_example.jsonl`

## Connections

- CLI → Orchestrator: inference · CLI routes generation requests into the orchestration layer
- Web demo → Orchestrator: demo inference · Web demo uses the same runtime core as the CLI
- LoRA UI → Orchestrator: lora inference · LoRA web UI drives the shared inference stack
- Package API → Orchestrator: exports · Public API re-exports the main runtime wrapper
- Orchestrator → VoxCPM: loads · Core can dispatch to first-generation model logic
- Orchestrator → VoxCPM2: loads · Core can dispatch to second-generation model logic
- VoxCPM → Model utils: shares · Version wrapper reuses common helpers
- VoxCPM2 → Model utils: shares · Version wrapper reuses common helpers
- VoxCPM2 → LocEnc: uses · VoxCPM2 passes context through the local encoder
- VoxCPM2 → MiniCPM-4: uses · VoxCPM2 relies on the MiniCPM-4 backbone
- VoxCPM2 → LocDiT: uses · VoxCPM2 generates speech latents with LocDiT
- VoxCPM2 → AudioVAE: uses · VoxCPM2 encodes and decodes audio through AudioVAE
- LocDiT → CFM: built on · LocDiT uses unified flow-matching generation logic
- VoxCPM2 → LoRA: adapts · LoRA adapters integrate into the model layer
- VoxCPM2 → Quantization: plumbs · Quantized latent handling supports generation and conditioning
- Train script → Training stack: invokes · Training entry point runs the training stack
- Training stack → Train data: reads · Training stack consumes manifest-style example data
- Training stack → V1 configs: configures · Training stack is driven by versioned YAML configs
- Training stack → V1.5 configs: configures · Training stack is driven by versioned YAML configs
- Training stack → V2 configs: configures · Training stack is driven by versioned YAML configs
- Training stack → Validation: includes · Training loop includes validation and evaluation
- Inference checks → Orchestrator: checks · Inference scripts verify runtime behavior through the core stack
- Inference checks → LoRA: checks · Runtime checks cover LoRA loading and inference
- CLI → Model utils: normalizes · User-facing flows depend on model-side helpers indirectly through the core
