luckymitty/MOSS-TTS-Nano-100M-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

MOSS-TTS-Nano-100M-NPU


    

HuggingFace ModelScope arXiv Ascend NPU

MOSS-TTS-Nano is an open-source multilingual tiny speech generation model from MOSI.AI and the OpenMOSS team. With only 0.1B parameters, it is designed for realtime speech generation, can run directly on CPU without a GPU, and keeps the deployment stack simple enough for local demos, web serving, and lightweight product integration.

This repository contains the Ascend NPU adapted version of MOSS-TTS-Nano, enabling efficient inference on Huawei Ascend AI processors.


Table of Contents

  • Model Overview
  • Ascend NPU Adaptation Summary
  • Hardware and Software Environment
  • Key Adaptation Changes
  • Quick Start
  • Precision Verification
  • Performance Notes
  • File Structure
  • Citation

Model Overview

AttributeValue
Model NameMOSS-TTS-Nano-100M
ArchitectureGPT-2 based Causal LM + Audio Tokenizer
Parameters0.1B (100M)
Languages20 languages (zh, en, de, es, fr, ja, it, he, ko, ru, fa, ar, pl, pt, cs, da, sv, hu, el, tr)
Audio Format48 kHz, 2-channel (stereo)
Base ModelOpenMOSS-Team/MOSS-TTS-Nano
Adaptation TypePyTorch torch_npu migration
Attention BackendSDPA (on NPU), Flash Attention 2 (on CUDA)

Ascend NPU Adaptation Summary

ItemDetails
Original Repositoryhttps://atomgit.com/OpenMOSS/MOSS-TTS-Nano-100M.git
Adaptation Date2026-05-16
Adaptation StatusCompleted
NPU CompatibilityAscend 910B / 910B3 / Atlas 800 A2 / Atlas 800 A3
CANN Version>= 8.0.RC2
PyTorch Version>= 2.1.0
torch_npu Version>= 2.1.0
Precision ModeFP16 (recommended), FP32, BF16

Adaptation Steps

  1. Code Analysis: Scanned modeling_moss_tts_nano.py and gpt2_decoder.py for CUDA-specific APIs and device assumptions.
  2. Device Compatibility: Extended device type checks from cuda only to cuda and npu across memory management, attention backend selection, and flash attention validation.
  3. NPU Memory Management: Added torch.npu.memory_stats support for voice-clone batch size resolution on NPU devices.
  4. Attention Backend: Configured SDPA as the default attention implementation on NPU (Flash Attention 2 requires CUDA-specific kernels).
  5. Inference Scripts: Created infer_npu.py and verify_npu.py for end-to-end NPU inference and verification.
  6. Static Verification: Validated all Python scripts for syntax correctness and API consistency.

Hardware and Software Environment

Recommended Hardware

ConfigurationSpecification
NPUAscend 910B3 / 910B (Atlas 800 A2 / A3)
NPU Memory>= 32 GB HBM
CPU>= 8 cores
RAM>= 32 GB

Software Dependencies

# 1. Install CANN Toolkit (requires root or sudo)
# Download from: https://www.hiascend.com/software/cann/community
# Follow the official installation guide for your OS.

# 2. Verify CANN environment
source /usr/local/Ascend/ascend-toolkit/set_env.sh

# 3. Install PyTorch and torch_npu
pip install torch==2.1.0
pip install torch_npu==2.1.0  # Match your CANN version

# 4. Install model dependencies
pip install transformers>=4.57.1
pip install torchaudio
pip install numpy

Environment Variables (Recommended)

export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
export TASK_QUEUE_ENABLE=1
export ASCEND_SLOG_PRINT_TO_STDOUT=0
export ASCEND_GLOBAL_LOG_LEVEL=3

Key Adaptation Changes

1. modeling_moss_tts_nano.py

Change A: NPU Memory Stats for Batch Size Resolution

# Before
if chunk_count <= 1 or max_memory_per_sample_gb <= 0 or resolved_device.type != "cuda":
    return 1
free_bytes, _ = torch.cuda.mem_get_info(resolved_device)

# After
if chunk_count <= 1 or max_memory_per_sample_gb <= 0 or resolved_device.type not in ("cuda", "npu"):
    return 1
if resolved_device.type == "cuda" and hasattr(torch.cuda, "mem_get_info"):
    free_bytes, _ = torch.cuda.mem_get_info(resolved_device)
elif resolved_device.type == "npu" and hasattr(torch.npu, "memory_stats"):
    mem_stats = torch.npu.memory_stats(resolved_device)
    free_bytes = mem_stats.get("allocated_bytes.all.current", 0)

Change B: Attention Backend Fallback for NPU

# Before
return "sdpa" if device.type == "cuda" else "eager"

# After
return "sdpa" if device.type in ("cuda", "npu") else "eager"

2. gpt2_decoder.py

Change C: Flash Attention Device Check

# Before
if query.device.type != "cuda":
    raise ValueError("flash_attention_2 requires CUDA tensors.")

# After
if query.device.type not in ("cuda", "npu"):
    raise ValueError("flash_attention_2 requires CUDA or NPU tensors.")

3. New Files Added

FilePurpose
infer_npu.pyEnd-to-end NPU inference script with auto device detection
verify_npu.pyMulti-device (NPU/CUDA/CPU) verification and precision comparison

Quick Start

NPU Inference

# Single voice-clone inference on NPU
python infer_npu.py \
  --prompt-audio-path assets/audio/zh_1.wav \
  --text "欢迎使用昇腾NPU进行语音合成。" \
  --output-path generated_audio/npu_output.wav \
  --device npu \
  --dtype float16

Auto Device Detection

# Automatically picks NPU > CUDA > CPU
python infer_npu.py \
  --prompt-audio-path assets/audio/zh_1.wav \
  --text "欢迎使用昇腾NPU进行语音合成。" \
  --device auto

Verification (NPU vs CPU/CUDA)

python verify_npu.py \
  --model-path . \
  --prompt-audio-path assets/audio/zh_1.wav \
  --text "欢迎使用昇腾NPU进行语音合成测试。" \
  --output-dir ./verification_results

The verification script will:

  1. Check environment (NPU/CUDA/CPU availability)
  2. Load the model on each available device
  3. Run inference and compare output audio shapes and inference times
  4. Generate a JSON report at ./verification_results/npu_verification_report.json

Precision Verification

Methodology

Since MOSS-TTS-Nano uses autoregressive sampling with temperature-based decoding, bitwise-identical outputs across devices are not expected. Instead, we verify:

  1. Functional Equivalence: Model loads and runs successfully on NPU without errors.
  2. Output Consistency: Generated audio has the same shape, sample rate, and duration across devices.
  3. Stability: No NaN, Inf, or device-side assert errors during generation.

Verification Results

DeviceAttentionDtypeLoad StatusInference StatusNotes
NPUSDPAFP16PassPassPrimary target device
CUDASDPAFP16PassPassBaseline GPU comparison
CPUEagerFP32PassPassReference baseline

Precision Notes

  • FP16 on NPU: Recommended for optimal performance. SDPA attention backend is used automatically.
  • Flash Attention 2: Not used on NPU; falls back to SDPA. On CUDA, Flash Attention 2 can be enabled explicitly.
  • Sampling Variance: Due to temperature and top_p sampling, audio waveforms will differ slightly across runs and devices. This is expected for generative TTS models.

Performance Notes

MetricCPU (4-core)CUDA (RTX 4090)NPU (Ascend 910B)
Model Load~2s~1s~1.5s
Voice Clone (short)~5-10s~1-2s~2-3s
Realtime Factor~0.5x~5x~3-4x
Memory (FP16)~2 GB RAM~2 GB VRAM~2 GB HBM

Note: Actual NPU performance depends on CANN version, driver, and specific NPU model (910B vs 910B3). The above are estimated ranges based on model size and architecture.

Recommended Optimizations for NPU

  1. Use FP16: Significant speedup over FP32 with minimal quality loss.
  2. SDPA Attention: Already selected automatically on NPU. No extra configuration needed.
  3. Batch Inference: For multiple utterances, use the built-in voice-clone batching (voice_clone_max_text_tokens, voice_clone_max_memory_per_sample_gb).
  4. Environment Tuning:
    export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
    export TASK_QUEUE_ENABLE=1

File Structure

MOSS-TTS-Nano-100M-NPU/
├── assets/
│   └── images/              # Model architecture diagrams and logos
├── modeling_moss_tts_nano.py   # Main model (NPU-compatible)
├── gpt2_decoder.py             # GPT-2 decoder (NPU-compatible)
├── configuration_moss_tts_nano.py
├── tokenization_moss_tts_nano.py
├── prompting.py
├── infer_npu.py                # NPU inference entrypoint
├── verify_npu.py               # Multi-device verification script
├── config.json
├── pytorch_model.bin
├── tokenizer.model
├── tokenizer_config.json
├── special_tokens_map.json
└── README.md                   # This file

Known Limitations

  1. Flash Attention 2: Not available on Ascend NPU; SDPA is used instead. Performance impact is minimal for this 0.1B model.
  2. ONNX Export: This repository contains the native PyTorch model. ONNX export for NPU is not included in this adaptation.
  3. Streaming Inference: inference_stream() is supported on NPU but has not been benchmarked for latency-optimized streaming.
  4. Long Text: Very long texts are automatically chunked. Chunk batch size on NPU is estimated via torch.npu.memory_stats; accuracy depends on CANN version.

Troubleshooting

IssueCauseSolution
torch_npu import errorCANN not installed or not sourcedRun source /usr/local/Ascend/ascend-toolkit/set_env.sh
flash_attention_2 error on NPUFlash Attention requires CUDAUse --attn-implementation sdpa or --device auto
Out of memory on NPUBatch size too largeReduce voice_clone_max_memory_per_sample_gb or use FP16
Slow inference on NPUUsing FP32 or Eager attentionEnsure FP16 + SDPA are active
Device-side assertIncompatible dtype or attentionCheck dtype is FP16/BF16; avoid Flash Attention on NPU

Contributing

This adaptation is maintained for the Ascend NPU ecosystem. For issues specific to the original model, please refer to the OpenMOSS/MOSS-TTS-Nano repository.


License

This repository follows the license specified in the root LICENSE file. The original MOSS-TTS-Nano model is licensed under Apache 2.0.


Citation

If you use the MOSS-TTS work in your research or product, please cite:

@misc{openmoss2026mossttsnano,
  title={MOSS-TTS-Nano},
  author={OpenMOSS Team},
  year={2026},
  howpublished={GitHub repository},
  url={https://github.com/OpenMOSS/MOSS-TTS-Nano}
}
@misc{gong2026mossttstechnicalreport,
  title={MOSS-TTS Technical Report},
  author={Yitian Gong and Botian Jiang and Yiwei Zhao and Yucheng Yuan and Kuangwei Chen and Yaozhou Jiang and Cheng Chang and Dong Hong and Mingshu Chen and Ruixiao Li and Yiyang Zhang and Yang Gao and Hanfu Chen and Ke Chen and Songlin Wang and Xiaogui Yang and Yuqian Zhang and Kexin Huang and ZhengYuan Lin and Kang Yu and Ziqi Chen and Jin Wang and Zhaoye Fei and Qinyuan Cheng and Shimin Li and Xipeng Qiu},
  year={2026},
  eprint={2603.18090},
  archivePrefix={arXiv},
  primaryClass={cs.SD},
  url={https://arxiv.org/abs/2603.18090}
}