/NeMo

NeMo: a toolkit for conversational AI

Primary LanguagePythonApache License 2.0Apache-2.0

Project Status: Active – The project has reached a stable, usable state and is being actively developed. Documentation CodeQL NeMo core license and license for collections in this repo Release version Python version PyPi total downloads Code style: black

NVIDIA NeMo

Introduction

NVIDIA NeMo is a conversational AI toolkit built for researchers working on automatic speech recognition (ASR), text-to-speech synthesis (TTS), large language models (LLMs), and natural language processing (NLP). The primary objective of NeMo is to help researchers from industry and academia to reuse prior work (code and pretrained models) and make it easier to create new conversational AI models.

All NeMo models are trained with Lightning and training is automatically scalable to 1000s of GPUs. Additionally, NeMo Megatron LLM models can be trained up to 1 trillion parameters using tensor and pipeline model parallelism. NeMo models can be optimized for inference and deployed for production use-cases with NVIDIA Riva.

Getting started with NeMo is simple. State of the Art pretrained NeMo models are freely available on HuggingFace Hub and NVIDIA NGC. These models can be used to transcribe audio, synthesize speech, or translate text in just a few lines of code.

We have extensive tutorials that can be run on Google Colab.

For advanced users that want to train NeMo models from scratch or finetune existing NeMo models we have a full suite of example scripts that support multi-GPU/multi-node training.

For scaling NeMo LLM training on Slurm clusters or public clouds, please see the NVIDIA NeMo Megatron Launcher. The NM launcher has extensive recipes, scripts, utilities, and documentation for training NeMo LLMs and also has an Autoconfigurator which can be used to find the optimal model parallel configuration for training on a specific cluster.

Key Features

Built for speed, NeMo can utilize NVIDIA's Tensor Cores and scale out training to multiple GPUs and multiple nodes.

Requirements

  1. Python 3.10 or above
  2. Pytorch 1.13.1 or above
  3. NVIDIA GPU, if you intend to do model training

Documentation

Version Status Description
Latest Documentation Status Documentation of the latest (i.e. main) branch.
Stable Documentation Status Documentation of the stable (i.e. most recent release) branch.

Tutorials

A great way to start with NeMo is by checking one of our tutorials.

You can also get a high-level overview of NeMo by watching the talk NVIDIA NeMo: Toolkit for Conversational AI, presented at PyData Yerevan 2022:

NeMo presentation at PyData@Yerevan 2022

Getting help with NeMo

FAQ can be found on NeMo's Discussions board. You are welcome to ask questions or start discussions there.

Installation

Conda

We recommend installing NeMo in a fresh Conda environment.

conda create --name nemo python==3.10.12
conda activate nemo

Install PyTorch using their configurator.

conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia

The command used to install PyTorch may depend on your system. Please use the configurator linked above to find the right command for your system.

Pip

Use this installation mode if you want the latest released version.

apt-get update && apt-get install -y libsndfile1 ffmpeg
pip install Cython
pip install nemo_toolkit['all']

Depending on the shell used, you may need to use "nemo_toolkit[all]" instead in the above command.

Pip from source

Use this installation mode if you want the version from a particular GitHub branch (e.g main).

apt-get update && apt-get install -y libsndfile1 ffmpeg
pip install Cython
python -m pip install git+https://github.com/NVIDIA/NeMo.git@{BRANCH}#egg=nemo_toolkit[all]

From source

Use this installation mode if you are contributing to NeMo.

apt-get update && apt-get install -y libsndfile1 ffmpeg
git clone https://github.com/NVIDIA/NeMo
cd NeMo
./reinstall.sh

If you only want the toolkit without additional conda-based dependencies, you may replace reinstall.sh with pip install -e . when your PWD is the root of the NeMo repository.

Mac computers with Apple silicon

To install NeMo on Mac with Apple M-Series GPU:

  • create a new Conda environment
  • install PyTorch 2.0 or higher
  • run the following code:
# [optional] install mecab using Homebrew, to use sacrebleu for NLP collection
# you can install Homebrew here: https://brew.sh
brew install mecab

# [optional] install pynini using Conda, to use text normalization
conda install -c conda-forge pynini

# install Cython manually
pip install cython

# clone the repo and install in development mode
git clone https://github.com/NVIDIA/NeMo
cd NeMo
./reinstall.sh

RNNT

Note that RNNT requires numba to be installed from conda.

conda remove numba
pip uninstall numba
conda install -c conda-forge numba

NeMo Megatron

NeMo Megatron training requires NVIDIA Apex to be installed. Install it manually if not using the NVIDIA PyTorch container.

To install Apex, run

git clone https://github.com/NVIDIA/apex.git
cd apex
git checkout 52e18c894223800cb611682dce27d88050edf1de
pip install install -v --no-build-isolation --disable-pip-version-check --no-cache-dir --config-settings "--build-option=--cpp_ext --cuda_ext --fast_layer_norm --distributed_adam --deprecated_fused_adam" ./

It is highly recommended to use the NVIDIA PyTorch or NeMo container if having issues installing Apex or any other dependencies.

While installing Apex, it may raise an error if the CUDA version on your system does not match the CUDA version torch was compiled with. This raise can be avoided by commenting it here: https://github.com/NVIDIA/apex/blob/master/setup.py#L32

cuda-nvprof is needed to install Apex. The version should match the CUDA version that you are using:

conda install -c nvidia cuda-nvprof=11.8

packaging is also needed:

pip install packaging

With the latest versions of Apex, the pyproject.toml file in Apex may need to be deleted in order to install locally.

Transformer Engine

NeMo Megatron GPT has been integrated with NVIDIA Transformer Engine Transformer Engine enables FP8 training on NVIDIA Hopper GPUs. Install it manually if not using the NVIDIA PyTorch container.

pip install --upgrade git+https://github.com/NVIDIA/TransformerEngine.git@stable

It is highly recommended to use the NVIDIA PyTorch or NeMo container if having issues installing Transformer Engine or any other dependencies.

Transformer Engine requires PyTorch to be built with CUDA 11.8.

Flash Attention

Transformer Engine already supports Flash Attention for GPT models. If you want to use Flash Attention for non-causal models, please install flash-attn. If you want to use Flash Attention with attention bias (introduced from position encoding, e.g. Alibi), please also install triton pinned version following the implementation.

pip install flash-attn
pip install triton==2.0.0.dev20221202

NLP inference UI

To launch the inference web UI server, please install the gradio gradio.

pip install gradio==3.34.0

NeMo Text Processing

NeMo Text Processing, specifically (Inverse) Text Normalization, is now a separate repository https://github.com/NVIDIA/NeMo-text-processing.

Docker containers:

We release NeMo containers alongside NeMo releases. For example, NeMo r1.21.0 comes with container nemo:23.08, you may find more details about released containers in releases page.

To use built container, please run

docker pull nvcr.io/nvidia/nemo:23.08

To build a nemo container with Dockerfile from a branch, please run

DOCKER_BUILDKIT=1 docker build -f Dockerfile -t nemo:latest .

If you choose to work with the main branch, we recommend using NVIDIA's PyTorch container version 23.08-py3 and then installing from GitHub.

docker run --gpus all -it --rm -v <nemo_github_folder>:/NeMo --shm-size=8g \
-p 8888:8888 -p 6006:6006 --ulimit memlock=-1 --ulimit \
stack=67108864 --device=/dev/snd nvcr.io/nvidia/pytorch:23.08-py3

Examples

Many examples can be found under the "Examples" folder.

Contributing

We welcome community contributions! Please refer to CONTRIBUTING.md for the process.

Publications

We provide an ever-growing list of publications that utilize the NeMo framework.

If you would like to add your own article to the list, you are welcome to do so via a pull request to this repository's gh-pages-src branch. Please refer to the instructions in the README of that branch.

License

NeMo is released under an Apache 2.0 license.