---
title: Chunk-Aware Causal Flow Matching
url: https://www.emergentmind.com/topics/chunk-aware-causal-flow-matching
type: topic
---

# Chunk-Aware Causal Flow Matching

Chunk-aware causal flow matching (CFM) is a generative modeling framework central to the CosyVoice 2 text-to-speech (TTS) system, enabling high-quality, low-latency streaming speech synthesis by segmenting target mel-spectrograms into chunks and modeling their temporal progression with causally-masked optimal transport-based neural ordinary differential equations. CFM combines robust flow-matching objectives, chunk-based attention masking, and a causal convolutional Transformer U-Net architecture to harmonize streaming and offline TTS within a unified framework, achieving near-human naturalness and virtually lossless streaming fidelity [2412.10117].

## 1. Flow Matching Objective and Mathematical Formulation

At its core, chunk-aware causal flow matching constructs a deterministic flow, parameterized by $t \in [0, 1]$, between a standard Gaussian prior $X_0 \sim \mathcal N(0,I)$ and a data-sampled mel-spectrogram $X_1 \in \mathbb R^{T \times D}$, using the optimal transport (OT) interpolation:

\[
\phi^{OT}_t(X_0,X_1) = (1-t)\,X_0 + t\,X_1\,.
\]

The ground-truth time-dependent vector field is

\[
\omega_t(\phi^{OT}_t(X_0,X_1)) = X_1 - X_0\,.
\]

A neural Flow Matcher $\nu_\theta$ is trained to predict $\omega_t$, conditioned on interpolated states $X_t = \phi^{OT}_t(X_0, X_1)$ and auxiliary information $\Psi = \{\mu_{1:L}, \tilde X_1, \mathbf v\}$, where $\mu_{1:L}$ are upsampled speech tokens from a pretrained language model, $\tilde X_1$ is a heavily masked version of $X_1$, and $\mathbf v$ is the speaker embedding. The $L_1$ flow-matching loss is

\[
\mathcal L(\theta) = \mathbb E_{X_0, X_1, t} \| (X_1 - X_0) - \nu_\theta(X_t, t; \Psi) \|_1\,.
\]

Inference discretizes the ODE into $N$ steps using cosine time re-parameterization

\[
t_i = 1 - \cos \Bigl( \frac{\pi}{2} \frac{i}{N} \Bigr), \quad i = 0, \ldots, N
\]

and an Euler update

\[
X_{t+\Delta t} = X_t + (X_1 - X_0 - \nu_\theta(X_t, t))\,\Delta t\,.
\]

Classifier-free guidance is implemented by randomly dropping $\Psi$ at training and assembling predictions at inference as

\[
\tilde\nu_t = (1+\beta)\,\nu_\theta(X_t, t; \Psi) - \beta\,\nu_\theta(X_t, t; \emptyset)\,, \quad \beta = 0.7\,.
\]

## 2. Chunking and Causal Masking Strategies

To facilitate streaming, the CFM processes only small contiguous segments (“chunks”) of output frames at a time, never seeing the full mel sequence. Each chunk consists of $M$ frames, typically matched to 50 Hz audio (so $M$ frames equals $M/50$ seconds). Four attention masks govern context access during training:

- Non-causal mask: full context (offline)
- Full-causal mask: only past frames (no look-ahead)
- Chunk-$M$ mask: past plus $M$ future frames
- Chunk-$2M$ mask: past plus $2M$ future frames

Masking mode is selected uniformly per mini-batch sample, enforcing model robustness to variable look-ahead and chunk boundaries. At inference, a look-ahead buffer of $P$ frames from the preceding chunk is prepended to each chunk. The same masking scheme is enforced, producing seamless synthesis across chunk boundaries.

## 3. Network Architecture: Causal Convolutional Transformer U-Net

The flow matcher $\nu_\theta$ adopts a causal–convolutional Transformer U-Net architecture. The main modules include:

- **Input preprocessing**: Semantic tokens $\mu_{1:L}$ are upsampled by $\times2$ to reach 50 Hz; a 1D look-ahead convolution with kernel size $P+1$ and right padding $P$ facilitates limited future-frame access.
- **Chunk-aware causal Transformer blocks**: Causal multi-head self-attention with current chunk’s mask, cross-attention to upsampled tokens, a local feed-forward network, residual/layer-norm—all strictly causal.
- **U-Net pathway**: Down- and up-sampling paths with skip connections, housing identical causal conv-Transformer blocks at every resolution.
- **Conditioning mechanisms**: Sinusoidal embeddings of $t$ (injected at all layers), speaker embedding $\mathbf v$, and masked mel $\tilde X_1$ (projected as bias terms).
- **Final projection**: Outputs $\nu_\theta(X_t, t; \Psi)$ as a $D$-dimensional Mel frame.

Integration with the upstream LM (e.g., Qwen2.5) relies on a convolution+linear embedding mapping each semantic token to the same feature dimension $D$ before cross-attention.

## 4. Inference Procedures for Offline and Streaming Synthesis

CosyVoice 2 supports both offline and streaming inference regimes:

- **Offline (non-streaming)**:
  1. Full text is processed by text-speech LM to produce $\mu_{1:L}$.
  2. Build full conditioning set $\{\mu, \mathbf v, X_{\text{prompt}}\}$.
  3. Initialize $X_0 \sim \mathcal N(0, I)$.
  4. For each step $i$, compute $t_i$, update $X_{t_{i+1}}$, and pass final $X_1$ to the vocoder.

- **Streaming (chunk-by-chunk)**:
  1. For chunk $k$, query LM for next $M$ tokens $\mu^{(k)}$ and upsample.
  2. Prepend $P$ frames from prior chunk as look-ahead.
  3. Form chunk input ($M+P$ frames) and apply appropriate causal/chunk mask.
  4. Run $N$ flow-matching steps restricted to chunk frames.
  5. Discard the first $P$ frames; send $M$ frames to the vocoder and concatenate outputs.

Streaming TTS latency is formalized as

\[
L_{TTS} = M\,d_{lm} + M\,d_{fm} + M\,d_{voc}\,,
\]

with $d_{fm}$ denoting per-token flow matcher time and empirical head-of-line streaming latency remaining under 40 ms.

## 5. Training Procedures and Data Regimen

Training occurs on a corpus comprising approximately 130k hours of Chinese, 30k hours of English, and small amounts of Japanese/Korean speech, all at 50 Hz frame rate and $D \approx 80$ Mel channels. For each example:

- 70–100% of final frames in $X_1$ are randomly masked to yield $\tilde X_1$.
- Attention mask (non-causal, full-causal, chunk-$M$, chunk-$2M$) is selected uniformly.
- Batch size is 256 chunks per GPU, optimized with AdamW and standard learning rate scheduling.
- Loss is $L_1$ flow matching; $N=10$ flow steps, classifier-free guidance strength $\beta=0.7$.
- Upstream semantic token quantization uses finite-scalar quantization (FSQ) with $D_{\text{code}}$ dimensions, codebook $[-K,\ldots,K]$.

## 6. Evaluation, Quantitative Results, and Ablation Studies

On the SEED benchmarks, CosyVoice 2 with chunk-aware CFM attains near-human performance in both offline and streaming scenarios:

| Dataset         | Mode      | Error Rate | Speaker Sim. (SS) |
|-----------------|-----------|------------|-------------------|
| test-zh         | Offline   | 1.45% CER  | 0.806             |
| test-zh         | Streaming | 1.45% CER  | 0.812             |
| test-en         | Offline   | 2.57% WER  | 0.736             |
| test-en         | Streaming | 2.38% WER  | 0.743             |
| test-hard       | Offline   | 6.83%      | 0.776             |
| test-hard       | Streaming | 8.08%      | 0.785             |

Ablation (Table 7 in paper):

- Streaming LM only (+offline CFM): $+0.05\%$ CER on test-zh, $+1.05\%$ on test-hard.
- Streaming CFM only (+offline LM): $+0.01\%$ CER on test-zh, $+0.29\%$ on test-hard.
- Both streaming: at most $+0.00\%$ on test-zh, $+1.25\%$ on test-hard.

This demonstrates that chunk-aware CFM preserves quality and consistency across streaming/non-streaming settings and diverse benchmarks.

## 7. Advantages, Limitations, and Prospective Extensions

**Advantages**
- A unified model supports both streaming and offline TTS synthesis.
- Streaming quality is virtually lossless, first-package latencies of tens of milliseconds.
- Chunk-aware masking ensures robustness to varied look-ahead, encourages implicit self-distillation.
- Decoupled modeling (semantic via LM, acoustic via CFM): streaming semantic token input does not degrade speaker fidelity.

**Limitations**
- Languages with overlapping character sets (e.g., Japanese and Chinese) show elevated error rates.
- No explicit control over timbre or pitch by text instruction.
- Singing and highly rhythmic speech remain problematic.

**Potential extensions**
- Application to fully non-autoregressive TTS (bypassing discrete tokens).
- Variable chunk lengths and adaptive look-ahead schemes.
- Hybrid samplers combining chunk-aware flow matching with diffusion models.
- Enabling multi-modal (e.g., visual or gestural) streaming conditioning in generative agents [2412.10117].

Source: https://www.emergentmind.com/topics/chunk-aware-causal-flow-matching