Skip to content

[RFC / Optimization]: Reduce depth decoder dispatch overhead & eliminate per-step heap churn in BreezeTTS 2 #347

Closed

Description

@FraserHum

Context & Motivation

In BreezeTTS 2, the depth decoder executes 15 autoregressive codebook steps for every audio frame (codebooks 1 through 15). At 12.5 frames per second, this results in 187.5 depth decoding iterations per second of audio. Because depth decoding represents ~60% of total inference time, reducing per-step overhead significantly improves generation latency and throughput.

Identified Bottlenecks in src/models/breeze_tts/generator.cpp (dev branch)

  1. Multiple Graph Computations and Syncs per Step:

    • Each codebook step executes separate graph dispatches:
      • depth_pair->decode_embeddings_batched() (Qwen transformer layer decode)
      • depth_projection->logits_cfg() (head_graphs_[codebook - 1] linear projection)
      • project_audio_embedding_row() (projector_single_ linear projection)
    • Each separate graph calls compute_backend_graph() and ggml_backend_synchronize(), multiplying synchronization and dispatch overhead.
  2. Per-Step Heap Allocator Churn:

    • In generate_frame(), each of the 15 steps performs multiple heap allocations:
      • project_audio_embedding_row() allocates embedding vector and run_graph() allocates output.
      • logits_cfg() allocates input, run_graph() allocates output, and logits_cfg() allocates out for CFG combination.
      • next_pair, cond_hidden_now, and uncond_hidden_now allocate and reassign vectors dynamically each step.

Proposed Optimization Strategy

  1. Persistent Staging & Scratch Buffers (Immediate / High Impact):

    • Add pre-allocated member scratch buffers (input_staging_, output_staging_, combined_logits_) inside BreezeDepthProjectionRuntime and BreezeGeneratorRuntime::Impl.
    • Pass existing buffers or views to run_graph and logits_cfg to perform readbacks and CFG combinations completely in-place without vector allocations.
    • Pre-allocate cond_hidden_now, uncond_hidden_now, and next_pair in Impl.
  2. Benchmark Results in Reference Port:

    • In Breeze-TTS-2.cpp, eliminating per-step context and staging heap churn dropped depth decode time from 60.60 ms/frame to 50.47 ms/frame on CPU (~17% speedup) with zero numeric deviation.

We are preparing a PR targeting dev to implement the pre-allocated staging optimization for src/models/breeze_tts/generator.cpp.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions