Skip to content
acids-ircamPublic

About

Official implementation of the RAVE model: a Realtime Audio Variational autoEncoder

Topics

Resources

Stars

1.8k stars

Watchers

56 watching

Forks

Repository files navigation

[!WARNING] > This is a beta version of RAVE (v2.4). Features and APIs may change before the stable release. See what's new for details on the changes in this version.

rave_logo

RAVE: Realtime Audio Variational autoEncoder

Official implementation of RAVE: A variational autoencoder for fast and high-quality neural audio synthesis (article link) by Antoine Caillon and Philippe Esling.

If you use RAVE as a part of a music performance or installation, be sure to cite either this repository or the article !

If you want to share / discuss / ask things about RAVE you can do so in our discord server!

Please check the FAQ before posting an issue!

Documentation : the full documentation (tutorials, command-line reference, configurations, Python API) is available at acids-rave.readthedocs.io. Coming from RAVE 2.3? Read what's new in 2.4 and its migration table.

RAVE VST RAVE VST for Windows, Mac and Linux is available as beta on the corresponding Forum IRCAM webpage. For problems, please write an issue here or on the Forum IRCAM discussion page.

Tutorials : tutorials are available in the documentation and on the Forum IRCAM webpage:

Previous versions

The original implementation of the RAVE model can be restored using

git checkout v1

Installation

RAVE requires Python ≥ 3.11. It is strongly advised to install torch and torchaudio before acids-rave, so you can choose the build matching your hardware (CUDA, ROCm, CPU, Apple Silicon) on the PyTorch website.

pip install "torch>=2.6" "torchaudio>=2.6" torchcodec  # pick the right build for your platform on pytorch.org
# on macOS < 26, use torch < 2.15: newer versions did not work there
# pip install "torch>=2.6,<2.15" "torchaudio>=2.6" torchcodec
pip install acids-rave

You may also need ffmpeg and sox on your computer. You can install them inside a conda environment with

conda install -c conda-forge ffmpeg sox

To use rave train_after (AFTER diffusion models), install the optional extra:

pip install "acids-rave[after]"

Colab

Two notebooks let you train and fine-tune RAVE on Google Colab, including with a free account. Everything (runs, checkpoints, preprocessed datasets) is kept on your Google Drive. If Colab disconnects, run the notebook again and the training resumes from the latest checkpoint.

  • Train a model: Open in Colab
  • Fine-tune a model: Open in Colab

A community colab to train RAVEv2, written for an earlier version of RAVE, is also available thanks to hexorcismos: colab_badge

Usage

Training a RAVE model usually involves 3 separate steps, namely dataset preparation, training and export. All commands go through the rave entry point; run rave <command> --helpfull to list every flag, or see the command-line reference.

Command Purpose
preprocess Turn a folder of audio files into a training dataset
train Train a RAVE model
finetune Continue training an existing model, possibly on new data / with frozen parts
export Script a trained model into a .ts file for nn~, the VST or Python
generate Process audio files offline with one or several models
dimred Add / remove / list custom latent projections
train_prior Train an autoregressive prior on a model's latent space
train_after Train an AFTER diffusion model on a RAVE latent space (optional dependency)
uncompile Turn an exported .ts back into a trainable checkpoint
adapt Fit a linear adapter between the latent spaces of two exported models

Dataset preparation

Since v2.4, RAVE uses the acids-dataset library for data pre-processing; check its github to access all the library's features. A shortcut is given for a direct use within rave:

rave preprocess --input_path /audio/folder --output_path /processed/path --channels 1

Audio files are resampled (--sampling_rate, default 44100) and cut into overlapping chunks of 2 × num_signal samples (--num_signal, default 131072), so don't be surprised if the pre-processed folder is larger than your original data. You can select files with --filter / --exclude (wildcards), parse metadata from file paths with --meta_regexp, and compute extra features with --feature.

Training on raw audio. You can also skip preprocessing and give a plain folder of audio files to --db_path at training time: files are decoded and resampled on the fly. This is the quickest way to start; for long trainings, preprocessing is still faster.

Training

After the dataset pre-processing, you can start training your RAVE model.

rave train --name give_a_name --db_path /processed/path --out_path /model/out --device cuda:0

The run is written to <out_path>/<name>_<hash>. Useful flags:

  • --device: auto (default), cpu, cuda, cuda:0, mps... Repeat it (--device cuda:0 --device cuda:1) for multi-GPU training.
  • --channels N (0 = number of channels of the dataset), --stereo, --midside (trains in mid/side, the exported model still takes and returns L/R) or --ambisonics (for A-format recordings, trained in B-format).
  • --normalize none|each|dataset|dataset_compress: input normalization strategy.
  • --one_batch_per_file: balances datasets with very uneven file lengths.
  • --beta: target regularization weight (KL for variational models, MMD for Wasserstein models).
  • --resume path: resume from a run folder, version folder or .ckpt. The configuration is read from the run.
  • --init_from path/to/run (or path/to/run->encoder,decoder, or regular expressions on weight names): initialize some or all weights from another run.

Several configurations are available, that you can give using the --config keyword (default is v2). Passing any --config replaces the default, so always start the list with an architecture. For example, you can train a discrete configuration, similar to SoundStream or EnCodec, by providing

rave train --config discrete ...

By default, RAVE is built with non-causal convolutions. If you want to make the model causal (hence lowering the overall latency of the model), you can use the causal mode

rave train --config v2 --config causal ...

Any value of the configuration can be changed with --override, e.g. --override "CAPACITY=64".

Data augmentations are also available to improve the model's generalization, and are strongly recommended in low data regimes (less than about an hour of audio). They are provided by acids-dataset (with a link to audiomentations) and added with the --augment keyword:

rave train --config v2 --augment mute --augment compress --augment gain ...

Always use mute: without it the model never learns to output silence. Many more transforms are available (pitch shift, room simulation, EQ, distortion, noise...), see data augmentations.

Many other configuration files are available in rave/configs and can be combined. Here is a list of the available configurations (see configurations for details):

Type Name Description
Architecture v1 Original continuous model (minimum GPU memory : 8Go)
v2 (default) Improved continuous model (faster, higher quality) (minimum GPU memory : 16Go)
v2_small v2 with a smaller receptive field, adapted adversarial training, and noise generator, adapted for timbre transfer for stationary signals (minimum GPU memory : 8Go)
v2_nopqmf (experimental) v2 without pqmf in generator (more efficient for bending purposes) (minimum GPU memory : 16Go)
v2_nopqmf_small (experimental) smaller variant of v2_nopqmf, with random compression augmentation
v2_with_augs (experimental) v2 with mel-spectrogram encoder input and random compression augmentation
v3 v2 with Snake activation, descript discriminator and Adaptive Instance Normalization for real style transfer (minimum GPU memory : 32Go)
v4 (experimental, new in 2.4) spectrogram-domain model: 2D encoder / decoder on a complex STFT, no PQMF, streamable
discrete Discrete model (similar to SoundStream or EnCodec) (minimum GPU memory : 18Go)
discrete_v3 discrete with Snake activations and descript discriminator
hybrid v2 with mel-spectrogram encoder input and a GRU in the decoder
onnx Noiseless v1 configuration for onnx usage (minimum GPU memory : 6Go)
raspberry Lightweight configuration compatible with realtime RaspberryPi 4 inference (minimum GPU memory : 5Go)
Regularization (v2 family) (none) Variational Auto Encoder objective (ELBO)
wasserstein Wasserstein Auto Encoder objective (MMD)
spherical Spherical Auto Encoder objective
Discriminator spectral_discriminator Use the MultiScale discriminator from EnCodec.
descript_discriminator Use the Descript Audio Codec discriminator.
Others causal Use causal convolutions
noise Enables noise synthesizer V2
snake Snake activations everywhere (better periodic signals)
adain Adaptive Instance Normalization in encoder and decoder (style transfer; included in v3)
adv_at_start Enables adversarial learning at start (Experimental). Can be added when resuming.
no_encoder_freeze Does not freeze the encoder at phase 2 (latent space is still trained). Can be added when resuming.
normalize_ambient Adds a compressor augmentation tuned for ambient material

Export

Once trained, export your model to a torchscript file using

rave export --run /path/to/your/run --streaming (--name export_name --out_path /out/path/for/scripted)

Setting the --streaming flag will enable cached convolutions, making the model compatible with realtime processing. If you forget to use the streaming mode and try to load the model in Max, you will hear clicking artifacts.

Other useful flags:

  • --db_path /path/to/dataset: recompute the latent PCA on a whole dataset with the final model (recommended; during training it is only estimated on validation batches). Required to get a PCA for Wasserstein models.
  • --fidelity 0.95, --latent_size N or --no_pca: choose the exported latent size, or export the raw latent space.
  • --ica, --sfa, --pls, --cca, --mapper (with --db_path): embed custom latent projections, switchable live in Max with the projection attribute.
  • --ckpt_name best.ckpt: export another checkpoint than last.ckpt.

The exported file embeds the model's configuration, so it can be turned back into a trainable checkpoint with rave uncompile --model my_model.ts.

Custom representations

rave dimred adds, removes or lists custom latent projections (pca, wpca, ica, sfa, pls, cca, lda) fitted on your own audio, on a run or directly on an exported .ts:

rave dimred add --model my_model.ts --name strings --audio /path/to/strings --type pca --type sfa

See the custom representations tutorial.

Fine-tune

Since v2.4, rave finetune allows you to fine-tune a model from an existing run. The difference between fine-tuning and training is that you generally fine-tune on another dataset than the original training, starting with fresh optimizers, and freeze / train only some parts of the model. For example, fine-tuning only the encoder of a model trained on flute with a voice dataset improves timbre transfer from voice to flute:

rave finetune --name run_name --run /path/to/original/run --db_path /path/to/db --out_path /path/to/finetuned/model --mode encoder

--mode chooses the objective:

  • encoder (default): update only the encoder with reconstruction and latent regularization losses; the decoder is fixed.
  • decoder: update the decoder with reconstruction, adversarial and feature-matching losses; update the discriminator on separate batches at the configured cadence. The encoder is fixed. This enables to learn to generate samples in a new domain, while retaining the latent organisation of the original training.
  • full: run decoder mode for the first half of --max_steps, then encoder mode for the second half. Default: 25,000 batches per phase. Set a positive total with --max_steps. This enables to create a rave model on the target domain, while benefitting from the pre-training.

--train and --freeze further restrict the trained weights, using either specific words (all, encoder, decoder, discriminator) or regular expressions on weight names. For example :

rave finetune --name run_name --run /path/to/original/run --db_path /path/to/db --mode decoder --train "decoder.net.[0-3].*"

will only fine-tune the first layers of the decoder. To access all the keys, you can use Python :

import rave

model, path = rave.load_rave_checkpoint("path/to/run")
print(model.state_dict().keys())

Learning rates are set per module (--lr_encoder, --lr_decoder, --lr_discriminator). --encoder_start_step delays updates in encoder mode; omit it for full. --beta sets the variational encoder's KL weight (default: source beta divided by 4). PCA updates are enabled by default; --noupdate_pca retains the source axes. Use --resume with the same settings to restore optimizers, batch count and phase. For full, retain --max_steps so the phase boundary stays unchanged. See the fine-tuning tutorial for details.

Prior

For discrete models, we redirect the user to the msprior library here. However, as this library is still experimental, the prior from version 1.x has been re-integrated in v2.3.

Training

To train a prior for a pretrained RAVE model :

rave train_prior --name my_prior --model /path/to/your/run --db_path /path/to/your_preprocessed_data --out_path /path/to/output

this will train a prior over the latent of the pretrained model path/to/your/run, and save the model and tensorboard logs to folder /path/to/output.

Scripting

To script a prior along with a RAVE model, export your model by providing the --prior keyword to your pretrained prior :

rave export --run /path/to/your/run --prior /path/to/your/prior --fidelity 0.99 (--streaming)

The exported latent size must match the one of the prior: use the same --fidelity (or --latent_size) as for train_prior (whose default is 0.99, while the export default is 0.95).

Pretrained models

Several pretrained streaming models are available here. We'll keep the list updated with new models.

Realtime usage

This section presents how RAVE can be loaded inside nn~ in order to be used live with Max/MSP or PureData.

Reconstruction

A pretrained RAVE model named darbouka.gin available on your computer can be loaded inside nn~ using the following syntax, where the default method is set to forward (i.e. encode then decode)

This does the same thing as the following patch, but slightly faster.

Since v2.4, forward goes through the full latent space (decode_full(encode_full(x))), giving the best reconstruction whatever the exported latent size. The encode_full / decode_full methods expose the raw latent space, and encode_dist returns the posterior mean and standard deviation.

High-level manipulation

Having an explicit access to the latent representation yielded by RAVE allows us to interact with the representation using Max/MSP or PureData signal processing tools:

Style transfer

By default, RAVE can be used as a style transfer tool, based on the large compression ratio of the model. We recently added a technique inspired from StyleGAN to include Adaptive Instance Normalization to the reconstruction process, effectively allowing to define source and target styles directly inside Max/MSP or PureData, using the attribute system of nn~.

Other attributes, such as enable or gpu can enable/disable computation, or use the gpu to speed up things (still experimental). New in 2.4:

  • projection: active latent projection (default for PCA, raw, or any custom projection), switchable live with set projection <name>;
  • projection_names: list of available projections;
  • temperature: scales the posterior sampling and the noise used for latent dimensions not driven by decode (0 = deterministic);
  • receptive_field: receptive field of the model, in samples.

See exported models for the complete reference.

Offline usage

The rave generate script allows the transformation of large amounts of files

rave generate --model model_path --input path_1 --input path_2 --out_path out_path (--mode stream --mode full --device cuda:0)

where model_path is the path to your trained model (training run or exported .ts; several --model can be given), path_X a list of audio files or directories, and out_path the out directory of the generations. --mode selects streaming (stream, default) and/or whole-file (full) processing, and --loudness applies input gains in dB (several values give several outputs).

Discussion

If you have questions, want to share your experience with RAVE or share musical pieces done with the model, you can use the Discussion tab !

Demonstration

RAVE x nn~

Demonstration of what you can do with RAVE and the nn~ external for maxmsp !

RAVE x nn~

embedded RAVE

Using nn~ for puredata, RAVE can be used in realtime on embedded platforms !

RAVE x nn~

Frequently Asked Question (FAQ)

Question : my preprocessing is stuck, showing 0it[00:00, ?it/s]
Answer : This means that the audio files in your dataset are too short to provide a sufficient temporal scope to RAVE. Try decreasing the signal window with the --num_signal XXX(samples) with preprocess, without forgetting afterwards to add the --n_signal XXX(samples) with train

Question : During training I got an exception resembling ValueError: n_components=128 must be between 0 and min(n_samples, n_features)=64 with svd_solver='full'
Answer : This means that your dataset does not have enough data batches to compute the intern latent PCA, that requires at least 128 examples (then batches).

Question : I used --gpu, --ckpt or --output and get an unknown flag error
Answer : These flags were renamed in 2.4: use --device cuda:0, --resume and --out_path. See the migration table.

Question : my dataset was preprocessed with RAVE 2.3 and does not load
Answer : 2.4 uses acids-dataset databases. Preprocess your data again with rave preprocess, or train directly on the audio folder.

Funding

This work is led at IRCAM, and has been funded by the following projects

About

Official implementation of the RAVE model: a Realtime Audio Variational autoEncoder

Topics

Resources

Stars

1.8k stars

Watchers

56 watching

Forks

Releases

Packages

Used by

Contributors

Languages