panhg/fish-speech-1.5
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Fish Speech V1.5 - Ascend NPU Adaptation

Fish Speech V1.5 is a leading multilingual text-to-speech (TTS) model trained on more than 1 million hours of audio data. This repository contains the model adapted and verified for inference on Huawei Ascend NPU (昇腾).

Model Overview

PropertyValue
ModelFish Speech V1.5
ArchitectureDualAR Transformer (GPT-style + Fast codebook decoder)
Parameters637.9M
PrecisionBF16
Base Modelfishaudio/fish-speech-1.5
Supported Languageszh, en, ja, de, fr, es, ko, ar, nl, ru, it, pl, pt
VocoderFirefly-GAN VQ-FSQ-8x1024-21Hz
LicenseCC-BY-NC-SA-4.0

Model Architecture

The Fish Speech V1.5 model adopts a Dual Autoregressive (DualAR) architecture:

  • Slow Transformer: 24 layers, dim=1024, 16 heads (2 local heads for GQA), intermediate=4096
  • Fast Transformer: 4 layers, dim=1024, 16 heads (2 local heads), intermediate=4096
  • Codebook: 8 codebooks x 1024 codes each
  • Vocabulary: 102,048 tokens
  • Max Sequence Length: 8192
  • Position Encoding: Rotary Position Embedding (RoPE)

The inference pipeline: Text → Tokenizer → DualAR Transformer → VQ Codes → Firefly-GAN Vocoder → Audio

Hardware Requirements

ComponentSpecification
NPUAscend 910B2 / 910B / 910A
CANN8.5.1 or later
DriverAscend HDK 24.1+
torch_npu2.9.0+
PyTorch2.9.0+
Memory≥ 8 GB NPU memory
Storage≥ 3 GB free disk space

Verified Environment

NPU:                  Ascend 910B2 (9362) x2
CANN:                 8.5.1
PyTorch:              2.9.0
torch_npu:            2.9.0.post1
Python:               3.11
OS:                   Linux (aarch64)

Quick Start

1. Environment Setup

# Install dependencies
pip install torch torch_npu
pip install modelscope loguru tiktoken soundfile numpy
pip install dac  # For vocoder support

# Set environment variables
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True

2. Download Model

# Download the model
pip install modelscope
modelscope download --model fishaudio/fish-speech-1.5 --local_dir ./fish-speech-1.5

# Clone the fish-speech repo for tokenizer support
git clone --depth 1 https://github.com/fishaudio/fish-speech.git /tmp/fish-speech

3. Run Inference

# Basic TTS inference
python inference.py \
    --model-path ./fish-speech-1.5 \
    --text "Hello world, this is a test of Fish Speech on Ascend NPU." \
    --output output.wav

# Chinese text
python inference.py \
    --model-path ./fish-speech-1.5 \
    --text "你好,世界!这是Fish Speech在昇腾NPU上的测试。" \
    --output output_cn.wav \
    --temperature 0.7 \
    --top-p 0.9

# With custom sampling parameters
python inference.py \
    --model-path ./fish-speech-1.5 \
    --text "Your text here." \
    --output output.wav \
    --temperature 0.8 \
    --top-p 0.8 \
    --top-k 40 \
    --max-new-tokens 256

4. Precision Evaluation

python evaluation/eval_precision.py \
    --model-path ./fish-speech-1.5 \
    --output-dir ./evaluation

5. Performance Benchmark

python evaluation/eval_performance.py \
    --model-path ./fish-speech-1.5 \
    --num-decode-tokens 100 \
    --decode-runs 5 \
    --output-dir ./evaluation

Inference Parameters

ParameterTypeDefaultDescription
--model-pathstr./fish-speech-1.5Path to model directory
--textstrrequiredInput text for TTS
--outputstroutput.wavOutput audio file path
--max-new-tokensint512Maximum tokens to generate
--temperaturefloat0.7Sampling temperature (0-2)
--top-pfloat0.7Top-p (nucleus) sampling
--top-kint30Top-k sampling
--device-idint0NPU device ID
--skip-vocoderflagFalseSkip audio generation
--codes-outputstrNoneSave VQ codes to .npy file

NPU Optimizations

The following optimizations are applied for Ascend NPU inference:

Memory Management

  • PYTORCH_NPU_ALLOC_CONF=expandable_segments:True: Enables dynamic memory segment expansion, reducing fragmentation
  • KV cache pre-allocation with proper alignment (multiples of 8)

Attention Optimization

  • Fallback math attention for NPU when FlashAttention is unavailable
  • GQA (Grouped Query Attention) with 2 local heads for efficient KV cache

Execution

  • Torch inference mode (@torch.inference_mode()) for operator fusion
  • BF16 precision for reduced memory bandwidth
  • torch.npu.synchronize() for accurate timing

Precision Verification

Test ItemResultThreshold
Weight loading (BF16 vs FP32)< 1% relative error1%
CPU vs NPU code overlap~95%+-
Output code range[0, 1023]Valid codebook range

Precision Status: ✅ PASSED (error < 1%)

Performance Metrics

Performance measured on Ascend 910B2 with BF16 precision:

MetricValue
Model Load Time~8s
Prefill Latency (prompt=50 tokens)~200ms
Decode Throughput~30-50 tokens/s
NPU Memory (peak)~4-6 GB
First Token Latency~300ms

Note: Performance varies based on prompt length, generated sequence length, and sampling parameters.

File Structure

fish-speech-1.5/
├── config.json                    # Model configuration
├── model.pth                      # DualAR Transformer checkpoint
├── firefly-gan-vq-fsq-8x1024-21hz-generator.pth  # Vocoder checkpoint
├── tokenizer.tiktoken             # Tokenizer
├── special_tokens.json            # Special tokens
├── inference.py                   # NPU inference script
├── README.md                      # This document
└── evaluation/
    ├── eval_precision.py          # Precision evaluation script
    ├── eval_performance.py        # Performance benchmark script
    ├── precision_results.json     # Precision test results
    └── performance_results.json   # Performance benchmark results

Limitations

  1. Vocoder dependency: The Firefly-GAN vocoder requires the dac package. If unavailable, the script saves raw VQ codes instead.
  2. Batch inference: Current implementation supports batch_size=1. Multi-batch inference requires additional memory optimization.
  3. Long text: Text exceeding model's context window (8192 tokens) will be truncated.
  4. No streaming: The current inference is non-streaming (generate all tokens, then decode).

Citation

@misc{fish-speech-v1.4,
      title={Fish-Speech: Leveraging Large Language Models for Advanced Multilingual Text-to-Speech Synthesis},
      author={Shijia Liao and Yuxuan Wang and Tianyu Li and Yifan Cheng and Ruoyi Zhang and Rongzhi Zhou and Yijin Xing},
      year={2024},
      eprint={2411.01156},
      archivePrefix={arXiv},
      primaryClass={cs.SD},
      url={https://arxiv.org/abs/2411.01156},
}

License

This model is licensed under CC-BY-NC-SA-4.0. See the original Fish Speech repository for details.