重要提示
您正在查看 NeMo 2.0 文档。此版本引入了对 API 的重大更改和一个新的库,NeMo Run。我们目前正在将 NeMo 1.0 的所有功能移植到 2.0。有关先前版本或 2.0 中尚不可用的功能的文档,请参阅 NeMo 24.07 文档。
常用配置文件#
本节详细概述了 NeMo 多模态语言模型集合中特定于模型的 NeMo 配置文件设置。有关设置和执行所有 NeMo 模型通用的实验(例如实验管理器和 PyTorch Lightning 训练器参数)的基础知识,请参阅 core 文档。
在 NeMo 多模态语言模型的配置文件中,关于数据集、增强、优化参数和模型架构规范的详细信息是核心。本页探讨了这些方面的每一个。
在 examples 的 config 目录中查找所有 NeMo 多模态语言模型脚本的示例配置文件。
数据集配置#
NeMo 多模态语言模型目前支持对话数据格式,其灵感和设计来自 haotian-liu/LLaVA。要探索示例数据集,请访问 haotian-liu/LLaVA。
配置文件允许设置实验中使用的 Dataset 类接受的任何初始化参数。有关数据集及其参数的完整列表,请访问 API 的 数据集 部分。
典型的训练配置如下所示
data:
num_workers: 8
dataloader_type: cyclic
data_path: path/to/conversations.json
lazy_preprocess: True
is_multimodal: True
conv_template: llama_2
image_token_len: 256
image_folder: path/to/images
image_aspect_ratio: 'square'
关键参数包括
data_path
:JSON 格式数据集的路径。is_multimodal
:指示数据集是否具有多种模态(例如,文本和图像)。conv_template
:用于对话格式的模板。支持的值如 ‘nvgpt’ 和 ‘llama_2’。image_token_len
:指定语言模型词嵌入中每个图像将占用的 token 数量。image_folder
:包含与数据集相关的图像的文件夹的路径。image_aspect_ratio
:指定是否填充或裁剪图像以保持纵横比,例如 ‘square’。
训练器配置#
本节概述了 Pytorch Lightning Trainer 对象的参数。
trainer:
devices: 1 # number of GPUs (0 for CPU), or list of the GPUs to use e.g. [0, 1]
num_nodes: 1
max_epochs: -1
max_steps: 2500000 # precedence over max_epochs
logger: False # Provided by exp_manager
precision: bf16 # Should be set to 16 for O1 and O2 to enable the AMP.
accelerator: gpu
log_every_n_steps: 5 # Interval of logging.
resume_from_checkpoint: null # The path to a checkpoint file to continue the training, restores the whole state including the epoch, step, LR schedulers, apex, etc.
num_sanity_val_steps: 10 # number of steps to perform validation steps for sanity check the validation process before starting the training, setting to 0 disables it
enable_checkpointing: False # Provided by exp_manager
accumulate_grad_batches: 1 # do not modify, grad acc is automatic for training megatron models
gradient_clip_val: 1.0
benchmark: False
enable_model_summary: True
有关参数的详细列表,请参阅 Pytorch Lightning Trainer API 部分。
实验管理器配置#
NeMo 实验管理器提供了一种简化的方法来管理各种任务,例如日志记录、保存和恢复。
exp_manager:
exp_dir: null # exp_dir for your experiment, if None, defaults to "./nemo_experiments"
name: ${name}
create_wandb_logger: True
wandb_logger_kwargs: # Whether you want exp_manger to create a Wandb logger
name: training-session
project: text2img
group: nemo
resume: True
create_tensorboard_logger: True # Whether you want exp_manger to create a tb logger
create_checkpoint_callback: True # Whether you want exp_manager to create a modelcheckpoint callback
checkpoint_callback_params:
monitor: reduced_train_loss
save_top_k: 5
every_n_epochs: 0 # Save checkpoint frequency.
every_n_train_steps: 1000 # Mutually exclusive with every_n_epochs. It is recommended to set this if training on large-scale dataset.
filename: '${name}--{reduced_train_loss:.2f}-{step}-{consumed_samples}'
resume_if_exists: True
resume_ignore_no_checkpoint: True
resume_from_checkpoint: ${model.resume_from_checkpoint}
ema:
enable: True
decay: 0.9999
validate_original_weights: False
every_n_steps: 1
cpu_offload: False
优化器配置#
optim:
name: fused_adam
lr: 0.0001
eps: 1e-8
betas: [ 0.9, 0.999 ]
weight_decay: 0.01
sched:
name: WarmupPolicy
warmup_steps: 10000
warmup_ratio: null
默认使用的优化器是 fused_adam
。有关所有受支持的优化器的详细信息,请参阅 NeMo 用户指南。可以在 optim.sched
部分中指定学习率调度器。
模型配置#
每个配置文件应详细说明用于实验的模型架构。
大多数多模态语言模型通用的参数包括
参数 |
数据类型 |
描述 |
|
---|---|---|---|
|
int |
适合每个 GPU 的 micro batch size |
|
|
int |
global batch size,考虑了梯度累积、数据并行 |
|
|
int |
层内模型并行 |
|
|
int |
层间模型并行 |
|
|
int |
训练中使用的随机种子 |
NeVA#
有关特定于模型的配置,请参阅 Neva。