Transformers documentation

NeMo Automodel

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v5.22.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

NeMo Automodel

NeMo Automodel は、NVIDIA によるオープンソースの PyTorch DTensor ネイティブな学習ライブラリです。LLM および VLM 的大規模・小規模な事前学習とファインチューニングをサポートし、FSDP2、テンソル並列、パイプライン並列、エキスパート並列、コンテキスト並列などの並列化戦略を備えています。これにより、研究環境および本番環境での高速な実験が可能です。高スループットを実現するため、DeepEP および TransformerEngine のカーネルを統合しています。

# Instantiating Nemotron V3 Nano with Expert Parallelism, FSDP2, and TransformerEngine + DeepEP kernels.
import os

import torch
import torch.distributed as dist

from nemo_automodel import NeMoAutoModelForCausalLM
from nemo_automodel.recipes._dist_utils import create_distributed_setup_from_config

dist.init_process_group(backend="nccl")
torch.cuda.set_device(int(os.environ.get("LOCAL_RANK", 0)))
torch.manual_seed(1111)

dist_setup = create_distributed_setup_from_config(
    {
        "strategy": "fsdp2",
        "ep_size": 8,
    },
)
model = NeMoAutoModelForCausalLM.from_pretrained(
    "nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16",
    dtype=torch.bfloat16,
    distributed_setup=dist_setup,
)
print(model)
dist.destroy_process_group()

以下のコマンドを使用して、torchrunでスクリプトを起動します。

torchrun --nproc-per-node=8 /path/to/script

Transformers の統合

  • Transformers でサポートされている LLM や VLM は、すべて NeMo Automodel 経由でもインスタンス化できます。対応モデルの全リストを参照してください。
  • Hugging Face のモデルを基盤とし、AutoModel.from_pretrained() を使用して構築されています。動的な高性能レイヤーの差し替えや、Expert Parallelism (EP) といったより洗練された並列化方式に対応しています。
  • AutoConfig.from_pretrained()内のarchitectureフィールドを検出し、Nemotron Nano V3などのカスタム実装を自動的に読み込みます。
  • TransformersのAPIに忠実に従っており、そのまま置き換え可能な互換性を備えています。

リソース

Update on GitHub