Instructions to use moonbox-dev/MossFormer2_SE_48K-TensorRT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- TensorRT
How to use moonbox-dev/MossFormer2_SE_48K-TensorRT with TensorRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
MossFormer2 TensorRT
TensorRT engines of MossFormer2, made by Moonbox for NVIDIA RTX GPUs. Each precision is one folder holding the
engine, trt_runner.py (a small numpy runner: TensorRT plus Polygraphy, no PyTorch) and a script that does the rest
of the pipeline. What the engine takes and returns is under How to run.
Compatibility. The engines are built hardware compatible (Ampere and newer: RTX 30, 40 and 50 series) and
version compatible (any TensorRT 10.x from 10.13 on, through its lean runtime). That costs a little speed against an
engine built for one GPU, but no rebuild is needed. Install the runtime with
pip install "tensorrt-cu12>=10.13,<11" "tensorrt-lean-cu12>=10.13,<11" polygraphy numpy.
Files
The last column is the benchmark (details under How to run).
| Precision | File | Size | sha256 | Benchmark |
|---|---|---|---|---|
| fp16 | fp16/model.engine |
482.9 MB | 926ef2c5f706 |
fp32 math (as the ONNX fp16-storage build): PESQ 3.102, STOI 0.9538, SI-SDR 19.42 dB; vs the ONNX build 81.7 dB mean, worst file -0.005 dB; RTF 0.044 (ONNX 0.105) |
| fp16 | fp16/trt_runner.py |
2.2 kB | efa8ba97631b |
fp32 math (as the ONNX fp16-storage build): PESQ 3.102, STOI 0.9538, SI-SDR 19.42 dB; vs the ONNX build 81.7 dB mean, worst file -0.005 dB; RTF 0.044 (ONNX 0.105) |
How to run
MossFormer2 SE 48K (ClearerVoice-Studio's speech enhancement: removes noise from speech at 48 kHz) as a TensorRT engine of its network: Kaldi filterbank features in, a spectral mask out.
- Input:
fbanks[1, T, 180]: 60 log-mel bands plus their first and second deltas, frames of 40 ms every 8 ms. - Output:
mask[1, T, 961]. - Length: T from 10 to 3000 frames (24 s; the profile is tuned for 500).
- Outside the engine: the features, the STFT, applying the mask and the ISTFT, as in ClearerVoice's own code. The simplest correct pipeline is ClearerVoice's decode function with its network swapped for the engine.
import sys, numpy as np, soundfile as sf, torch
import clearvoice.utils.decode as dec # pip install clearvoice==0.1.2
from clearvoice.network_wrapper import network_wrapper
sys.path.insert(0, "fp16")
from trt_runner import Engine
w = network_wrapper(); w.model_name = "MossFormer2_SE_48K"; w.load_args_se()
args = w.args; args.network = "MossFormer2_SE_48K"
eng = Engine("fp16/model.engine")
class Net: # what decode() calls: net(fbanks)[-1] is the mask
def __call__(self, fbanks):
return [torch.from_numpy(eng({"fbanks": fbanks.numpy().astype(np.float32)})["mask"])]
noisy, sr = sf.read("noisy_48k.wav", dtype="float32") # 48 kHz mono
clean = dec.decode_one_audio(Net(), torch.device("cpu"), noisy[None].astype(np.float64), args)
sf.write("enhanced.wav", np.asarray(clean, np.float32).reshape(-1)[: len(noisy)] / 32768, 48000)
ClearerVoice computes its filterbank with dither=1.0, so its output differs slightly from run to run. Set
dec.compute_fbank to call torchaudio.compliance.kaldi.fbank(..., dither=0.0) for repeatable output, as the
benchmark does. decode_one_audio itself processes files longer than 20 s in 4 s windows.
Precisions. fp16/: built from the fp16 ONNX build, whose weights are stored in fp16 and read as fp32. The
network's gated FSMN layers reach values around 1e10, far past fp16's range. So the casts are folded into fp32
weights (TensorRT wants constant convolution weights), and the engine's math is fp32 like the ONNX build's. Its
Squeeze nodes got explicit axes, the dimensions that are always 1, because TensorRT can't infer them from a dynamic
shape. No int8: TensorRT's int8 needs calibrated activations, and this network's ranges exceed what int8 activations
can hold.
Benchmark.
- Data: the VoiceBank-DEMAND test set (Valentini et al.: 824 utterances by two unseen speakers, 48 kHz), through ClearerVoice's own decode with filterbank dither 0, on an RTX 3080 Laptop GPU.
- Scores: PESQ wide-band (ITU-T P.862.2, at 16 kHz), STOI at 48 kHz, SI-SDR against the clean speech.
- Agreement: the SI-SDR of each output against the ONNX fp16 build's output.
- Pass mark: no file's SI-SDR more than 0.5 dB below the ONNX build's.
| PESQ | STOI | SI-SDR (dB) | vs the ONNX build: mean / worst file (dB) | worst-file SI-SDR change | real-time factor | |
|---|---|---|---|---|---|---|
ONNX fp16/ (CUDA) |
3.102 | 0.9538 | 19.42 | - | - | 0.105 |
TensorRT fp16/ |
3.102 | 0.9538 | 19.42 | 81.7 / 68.7 | -0.005 | 0.044 |
The ONNX build's own scores equal the PyTorch original's (clearvoice 0.1.2, fp32, CPU: PESQ 3.102, STOI 0.9538,
SI-SDR 19.42 dB). The real-time factor is for the whole pipeline (features and ISTFT on the CPU).
How these were made
From MossFormer2 at revision eff8c97925: each engine was built with TensorRT's builder from Moonbox's published
ONNX graph of the same model and precision. The network is strongly typed: every tensor keeps the precision the
ONNX graph gives it, so an fp16 engine computes what the fp16 ONNX build computes. Built on an RTX 3080 Laptop GPU,
it was benchmarked against the original before upload, and the sha256 column above is what the files must hash to.
License
Apache-2.0. These files are a derivative of the original model and carry its license: it is copied in this repository, and it governs your use of these files. The original model card follows unchanged.
Original model card
Introduction
The MossFormer2_SE_48K model weights for 48 kHz speech enhancement in ClearerVoice-Studio repo.
This model is trained on large scale datasets inclduing open-sourced and private data.
It enhances speech audios by removing background noise.
Install
Clone the Repository
git clone https://github.com/modelscope/ClearerVoice-Studio.git
Create Conda Environment
cd ClearerVoice-Studio
conda create -n clearvoice python=3.8
conda activate clearvoice
pip install -r requirements.txt
Run Script
Go to clearvoice/ and use the following examples. The MossFormer2_SE_48K model will be downloaded from huggingface automatically.
Sample example 1: use speech enhancement model MossFormer2_SE_48K to process one wave file of samples/input.wav and save the output wave file to samples/output_MossFormer2_SE_48K.wav
from clearvoice import ClearVoice
myClearVoice = ClearVoice(task='speech_enhancement', model_names=['MossFormer2_SE_48K'])
output_wav = myClearVoice(input_path='samples/input.wav', online_write=False)
myClearVoice.write(output_wav, output_path='samples/output_MossFormer2_SE_48K.wav')
Sample example 2: use speech enhancement model MossFormer2_SE_48K to process all input wave files in samples/path_to_input_wavs/ and save all output files to samples/path_to_output_wavs
from clearvoice import ClearVoice
myClearVoice = ClearVoice(task='speech_enhancement', model_names=['MossFormer2_SE_48K'])
myClearVoice(input_path='samples/path_to_input_wavs', online_write=True, output_path='samples/path_to_output_wavs')
Sample example 3: use speech enhancement model MossFormer2_SE_48K to process wave files listed in `samples/audio_samples.scp' file, and save all output files to 'samples/path_to_output_wavs_scp/'
from clearvoice import ClearVoice
myClearVoice = ClearVoice(task='speech_enhancement', model_names=['MossFormer2_SE_48K'])
myClearVoice(input_path='samples/scp/audio_samples.scp', online_write=True, output_path='samples/path_to_output_wavs_scp')
- Downloads last month
- -
Model tree for moonbox-dev/MossFormer2_SE_48K-TensorRT
Base model
alibabasglab/MossFormer2_SE_48K