# NeMo Automodel

[NeMo Automodel](https://github.com/NVIDIA-NeMo/Automodel) là thư viện huấn luyện mã nguồn mở, hỗ trợ PyTorch DTensor-native từ NVIDIA. Nó hỗ trợ tiền huấn luyện và tinh chỉnh ở quy mô lớn và nhỏ cho [LLMs](https://docs.nvidia.com/nemo/automodel/latest/model-coverage/large-language-models/overview) và [VLMs](https://docs.nvidia.com/nemo/automodel/latest/model-coverage/vision-language-models/overview) để thử nghiệm nhanh trong môi trường nghiên cứu và sản xuất, với các chiến lược song song bao gồm FSDP2, tensor, pipeline, expert và context parallelism. Để đạt thông lượng cao, nó tích hợp các kernel từ DeepEP và TransformerEngine.

Định nghĩa phiên huấn luyện của bạn trong một tệp cấu hình YAML (xem [tệp cấu hình](https://github.com/NVIDIA-NeMo/Automodel/blob/106e5162ef5b5d7269a3ba1ef62bfa8941b26cc6/examples/llm_finetune/nemotron/nemotron_nano_v3_hellaswag_peft.yaml) đầy đủ).

```yaml
# Instantiate a Nemotron V3 Nano model
model:
  _target_: nemo_automodel.NeMoAutoModelForCausalLM.from_pretrained
  pretrained_model_name_or_path: nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16

# Run SFT on HellaSwag
dataset:
  _target_: nemo_automodel.components.datasets.llm.hellaswag.HellaSwag
  path_or_dataset: rowan/hellaswag
  split: train

# Train PEFT adapters
peft:
  _target_: nemo_automodel.components._peft.lora.PeftConfig
  exclude_modules: ["*.out_proj"]  # mamba layers use custom kernels that take in the out_proj.weight directly, thus lora doesn't work here.
  dim: 8
  alpha: 32
  use_triton: True

# Use EP + FSDP2 for training
distributed:
  strategy: fsdp2
  dp_size: none
  tp_size: 1
  cp_size: 1
  ep_size: 4

# ... other parameters
```

Khởi động huấn luyện bằng `torchrun` bằng lệnh bên dưới.

```bash
torchrun --nproc-per-node=4 examples/llm_finetune/finetune.py -c /path/to/yaml
```

## Tích hợp Transformers

- Bất kỳ LLM hoặc VLM nào được hỗ trợ trong Transformers cũng có thể được khởi tạo thông qua NeMo Automodel. Xem [phạm vi hỗ trợ mô hình đầy đủ](https://docs.nvidia.com/nemo/automodel/latest/model-coverage/overview).
- Được xây dựng dựa trên các mô hình Hugging Face với [AutoModel.from_pretrained()](/docs/transformers/main/vi/model_doc/auto#transformers.AutoModel.from_pretrained), cùng với khả năng thay thế lớp hiệu năng cao động và hỗ trợ các dạng song song hóa tinh vi hơn như Expert Parallelism (EP).
- Phát hiện trường architecture trong [AutoConfig.from_pretrained()](/docs/transformers/main/vi/model_doc/auto#transformers.AutoConfig.from_pretrained) để tự động nạp các cài đặt tùy chỉnh như Nemotron Nano V3.
- Tuân thủ chặt chẽ API của Transformers để đảm bảo khả năng tương thích thay thế trực tiếp.

## Tài nguyên

- [NeMo Automodel](https://github.com/NVIDIA-NeMo/Automodel)
- [NeMo Transformers API](https://docs.nvidia.com/nemo/automodel/latest/get-started/hf-compatibility)
- Các mô hình dense và Mixture-of-Expert (MoE) của NeMo Automodel cùng với các [benchmark](https://docs.nvidia.com/nemo/automodel/latest/performance/performance-summary)
- Xem hướng dẫn [tiền huấn luyện](./nemo_automodel_pretraining) của NeMo để tìm hiểu cách sử dụng NeMo cho tiền huấn luyện

