重要提示

您正在查看 NeMo 2.0 文档。此版本引入了 API 的重大更改和一个新库 NeMo Run。我们目前正在将 NeMo 1.0 中的所有功能移植到 2.0。有关先前版本或 2.0 中尚不可用的功能的文档,请参阅 NeMo 24.07 文档

常用配置文件#

本节详细概述了 NeMo 多模态语言模型集合中特定于模型的 NeMo 配置文件设置。有关设置和执行所有 NeMo 模型通用的实验(例如实验管理器和 PyTorch Lightning 训练器参数)的基础知识,请参阅 core 文档。

在 NeMo 多模态语言模型的配置文件中,关于数据集、增强、优化参数和模型架构规范的详细信息是核心。本页探讨了这些方面的每一个。

示例的 config 目录中,发现所有 NeMo 多模态语言模型脚本的示例配置文件。

数据集配置#

配置文件在 trainvalidationtest 部分下分别描述了训练、验证和测试数据集的参数。根据特定任务,配置可能包括与数据集增强、图像分辨率过滤等相关的参数。

实验中使用的 Dataset 类支持的所有初始化参数都可以在配置文件中定义。有关数据集及其相关参数的完整列表,请查阅 API 的 Datasets 部分。

一个有代表性的训练配置如下所示

data:
    num_workers: 16 # Number of workers for the dataloader
    train:
      dataset_path: # Paths to wdinfo files specifying training datasets
        - dataset1.pkl
        - dataset2.pkl
    validation: # Paths to validation dataset files (pkl or tar)
      dataset_path:
        - dataset3.pkl
    webdataset:
      use_webdataset: True     # Enable the use of webdataset
      infinite_sampler: False  # Set to False for correct training resumption and accurate epoch counting
      local_root_path: ???     # Specify the directory where the dataset is located
      verbose: False           # Enable verbose debugging information if set to True

Datasets中所述,webdataset 格式的利用对于视觉语言对比训练管道至关重要。由于大量的数据需求,建议遵循Webdataset Multinode Training Guideline以获得推荐实践。

data:
  train:
    augmentations:
      resize_smallest_side: 256 # Adjust the image's smallest side to the specified dimension
      center_crop_h_w: 256, 256 # Perform center cropping
      horizontal_flip: False # Apply horizontal flip
    filterings:
      resolution:
        method: larger
        value: 256

此配置使用与 text2image 设置相同的数据类。启用 train.filteringstrain.augmentations 部分提供了灵活性,可以根据特定需求过滤特定图像(及其文本对),而无需重新创建整个 webdataset。提供的示例演示了过滤以仅保留分辨率超过 256x256 的图像以进行训练。要连接多个 webdataset,只需在 train.dataset_path 下列出所有相应的 wdinfo 文件即可。

训练器配置#

本节概述了 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 部分可以指定学习率调度器。

模型配置#

每个配置文件都应详细说明实验中使用的模型架构。

大多数多模态语言模型中常用的参数包括

参数

数据类型

描述

micro_batch_size

int

每个 GPU 上可容纳的微批大小

global_batch_size

int

考虑梯度累积和数据并行的全局批大小

tensor_model_parallel_size

int

层内模型并行

pipeline_model_parallel_size

int

层间模型并行

seed

int

训练中使用的种子

CLIP#

有关特定于模型的配置,请参阅 clip