重要提示
您正在查看 NeMo 2.0 文档。此版本对 API 和新的库 NeMo Run 进行了重大更改。我们目前正在将 NeMo 1.0 的所有功能移植到 2.0。有关先前版本或 2.0 中尚不可用的功能的文档,请参阅 NeMo 24.07 文档。
简介#
NVIDIA NeMo 框架是一个端到端、云原生的框架,用于在任何地方构建、定制和部署生成式 AI 模型。它允许在包括语音、语言和视觉在内的广泛领域中创建最先进的模型。有关在您的生成式 AI 工作流程中利用 NeMo 的详细信息,请参阅 NeMo 框架用户指南。
训练生成式 AI 架构通常需要大量数据和计算资源。NeMo 利用 PyTorch Lightning 进行高效且高性能的多 GPU/多节点混合精度训练。NeMo 构建于 NVIDIA 强大的 Megatron-LM 和 Transformer Engine 之上,用于其大型语言模型 (LLM) 和多模态模型 (MM),利用模型训练和优化方面的尖端进展。对于语音 AI 应用、自动语音识别 (ASR) 和文本到语音 (TTS),NeMo 是使用原生 PyTorch 和 PyTorch Lightning 开发的,确保了无缝集成和易用性。未来的更新计划将语音 AI 模型与 Megatron 框架对齐,从而提高训练效率和模型性能。
NVIDIA NeMo 框架 具有用于大型语言模型 (LLM)、多模态模型 (MM)、计算机视觉 (CV)、自动语音识别 (ASR) 和文本到语音 (TTS) 模型的独立集合。每个集合都包含预构建的模块,其中包括在您的数据上进行训练所需的一切。这些模块可以轻松定制、扩展和组合,以创建新的生成式 AI 模型架构。
预训练的 NeMo 模型可在 NGC 和 HuggingFace Hub 上下载。
前提条件#
在使用 NeMo 之前,请确保您满足以下前提条件
Python 版本 3.10 或更高版本。
Pytorch 版本 1.13.1 或 2.0+。
访问 NVIDIA GPU 以进行模型训练。
安装#
有关最新的安装说明,请参阅 NeMo 框架 用户指南。
快速入门指南#
要探索 NeMo 在 LLM、ASR 和 TTS 方面的功能,请按照以下基于 音频翻译 教程的示例进行操作。在继续之前,请确保已安装 NeMo。
# Import NeMo's ASR, NLP and TTS collections
import nemo.collections.asr as nemo_asr
import nemo.collections.nlp as nemo_nlp
import nemo.collections.tts as nemo_tts
# Download an audio file that we will transcribe, translate, and convert the written translation to speech
import wget
wget.download("https://nemo-public.s3.us-east-2.amazonaws.com/zh-samples/common_voice_zh-CN_21347786.mp3")
# Instantiate a Mandarin speech recognition model and transcribe an audio file.
asr_model = nemo_asr.models.ASRModel.from_pretrained(model_name="stt_zh_citrinet_1024_gamma_0_25")
mandarin_text = asr_model.transcribe(['common_voice_zh-CN_21347786.mp3'])
print(mandarin_text)
# Instantiate Neural Machine Translation model and translate the text
nmt_model = nemo_nlp.models.MTEncDecModel.from_pretrained(model_name="nmt_zh_en_transformer24x6")
english_text = nmt_model.translate(mandarin_text)
print(english_text)
# Instantiate a spectrogram generator (which converts text -> spectrogram)
# and vocoder model (which converts spectrogram -> audio waveform)
spectrogram_generator = nemo_tts.models.FastPitchModel.from_pretrained(model_name="tts_en_fastpitch")
vocoder = nemo_tts.models.HifiGanModel.from_pretrained(model_name="tts_en_hifigan")
# Parse the text input, generate the spectrogram, and convert it to audio
parsed_text = spectrogram_generator.parse(english_text[0])
spectrogram = spectrogram_generator.generate_spectrogram(tokens=parsed_text)
audio = vocoder.convert_spectrogram_to_audio(spec=spectrogram)
# Save the audio to a file
import soundfile as sf
sf.write("output_audio.wav", audio.to('cpu').detach().numpy()[0], 22050)
有关特定任务的详细教程和文档,或要了解有关 NeMo 的更多信息,请查看 NeMo 教程 或深入研究文档,例如在此处了解有关 ASR 的信息。
讨论区#
如需更多信息和问题,请访问 NVIDIA NeMo 讨论区。
贡献 NeMo#
欢迎社区贡献!请参阅 CONTRIBUTING.md 文件,了解如何贡献。
许可证#
NeMo 在 Apache 2.0 许可证下发布。