Accelerate documentation

Megatron-LM 实用工具

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

and get access to the augmented documentation experience

to get started

Megatron-LM 实用工具

MegatronLMPlugin

类 accelerate.utils.MegatronLMPlugin

< >

( tp_degree: int = Nonepp_degree: int = Noneuse_custom_fsdp: bool = Noneoverlap_cpu_optimizer_d2h_h2d: bool = Noneno_load_optim: bool = Noneeod_mask_loss: bool = Noneno_save_optim: bool = Noneoptimizer_cpu_offload: bool = Noneuse_precision_aware_optimizer: bool = Nonedecoder_last_pipeline_num_layers: int = Nonerecompute_granularity: str = Nonerecompute_method: str = Nonerecompute_num_layers: int = Noneattention_backend: bool = Noneexpert_model_parallel_size: int = Nonecontext_parallel_size: int = Noneattention_dropout: float = Nonehidden_dropout: float = Noneattention_softmax_in_fp32: bool = Noneexpert_tensor_parallel_size: int = Nonecalculate_per_token_loss: bool = Noneuse_rotary_position_embeddings: bool = Nonenum_micro_batches: int = Nonegradient_clipping: float = Nonesequence_parallelism: bool = Nonerecompute_activations: bool = Noneuse_distributed_optimizer: bool = Nonepipeline_model_parallel_split_rank: int = Nonenum_layers_per_virtual_pipeline_stage: int = Noneis_train_batch_min: str = Truetrain_iters: int = Nonetrain_samples: int = Noneweight_decay_incr_style: str = 'constant'start_weight_decay: float = Noneend_weight_decay: float = Nonelr_decay_style: str = 'linear'lr_decay_iters: int = Nonelr_decay_samples: int = Nonelr_warmup_iters: int = Nonelr_warmup_samples: int = Nonelr_warmup_fraction: float = Nonemin_lr: float = 0consumed_samples: list[int] = Noneno_wd_decay_cond: typing.Callable | None = Nonescale_lr_cond: typing.Callable | None = Nonelr_mult: float = 1.0megatron_dataset_flag: bool = Falseseq_length: int = Noneencoder_seq_length: int = Nonedecoder_seq_length: int = Nonetensorboard_dir: str = Noneset_all_logging_options: bool = Falseeval_iters: int = 100eval_interval: int = 1000return_logits: bool = Falsecustom_train_step_class: typing.Any | None = Nonecustom_train_step_kwargs: dict[str, typing.Any] | None = Nonecustom_model_provider_function: typing.Callable | None = Nonecustom_prepare_model_function: typing.Callable | None = Nonecustom_megatron_datasets_provider_function: typing.Callable | None = Nonecustom_get_batch_function: typing.Callable | None = Nonecustom_loss_function: typing.Callable | None = Noneother_megatron_args: dict[str, typing.Any] | None = None )

参数

  • tp_degree (int, 默认为 None) — 张量并行度。
  • pp_degree (int,默认为 None) — 流水线并行度。
  • num_micro_batches (int, 默认为 None) — 微批次的数量。
  • gradient_clipping (float,默认为 None) — 基于全局 L2 范数的梯度裁剪值(设为 0 以禁用)。
  • sequence_parallelism (bool, 默认为 None) — 启用序列并行。
  • recompute_activations (bool,默认为 None) — 启用选择性激活重计算。
  • use_distributed_optimizer (bool,默认为 None) — 启用分布式优化器。
  • pipeline_model_parallel_split_rank (int,默认为 None) — 编码器与解码器应拆分所在的 Rank。
  • num_layers_per_virtual_pipeline_stage (int,默认为 None) — 每个虚拟流水线阶段的层数。
  • is_train_batch_min (str,默认为 True) — 如果同时指定了训练和评估数据加载器,此参数将决定 micro_batch_size。
  • train_iters (int, 默认为 None) — 所有训练运行中要训练的样本总数。请注意,使用 MegatronLMDummyScheduler 时,应提供 train-iters 或 train-samples 其中之一。
  • train_samples (int, 默认为 None) — 所有训练运行中用于训练的样本总数。请注意,使用 MegatronLMDummyScheduler 时,应提供 train-iters 或 train-samples 其中之一。
  • weight_decay_incr_style (str,默认为 'constant') — 权重衰减增量函数。choices=[“constant”, “linear”, “cosine”]。
  • start_weight_decay (float,默认为 None) — L2 正则化的初始权重衰减系数。
  • end_weight_decay (float,默认为 None) — L2 正则化中运行结束时的权重衰减系数。
  • lr_decay_style (str,默认为 'linear') — 学习率衰减函数。choices=[‘constant’, ‘linear’, ‘cosine’]。
  • lr_decay_iters (int,默认为 None) — 学习率衰减的迭代次数。如果为 None,则默认为 train_iters。
  • lr_decay_samples (int,默认为 None) — 用于学习率衰减的样本数量。如果为 None,则默认为 train_samples。
  • lr_warmup_iters (int,默认为 None) — 用于线性预热学习率的迭代次数。
  • lr_warmup_samples (int,默认为 None) — 用于线性预热学习率的样本数量。
  • lr_warmup_fraction (float, 默认为 None) — 用于线性预热学习率的 lr-warmup-(iters/samples) 比例。
  • min_lr (float,默认为 0) — 学习率的最小值。调度器会将低于此阈值的值裁剪掉。
  • consumed_samples (List,默认为 None) — 与传入 accelerator.prepare 的 dataloader 顺序一致,已消耗的样本数量。
  • no_wd_decay_cond (Optional,默认为 None) — 用于禁用权重衰减的条件。
  • scale_lr_cond (Optional,默认为 None) — 用于缩放学习率的条件。
  • lr_mult (float,默认为 1.0) — 学习率乘数。
  • megatron_dataset_flag (bool,默认为 False) — 数据集格式是否遵循 Megatron-LM Indexed/Cached/MemoryMapped 格式。
  • seq_length (int,默认为 None) — 要处理的最大序列长度。
  • encoder_seq_length (int,默认为 None) — 编码器处理的最大序列长度。
  • decoder_seq_length (int,默认为 None) — 解码器要处理的最大序列长度。
  • tensorboard_dir (str, 默认为 None) — 保存 tensorboard 日志的路径。
  • set_all_logging_options (bool,默认为 False) — 是否设置所有日志选项。
  • eval_iters (int,默认为 100) — 用于运行验证/测试评估的迭代次数。
  • eval_interval (int,默认为 1000) — 在验证集上运行评估的间隔。
  • return_logits (bool,默认为 False) — 是否返回模型的 logits。
  • custom_train_step_class (Optional,默认为 None) — 自定义训练步骤类。
  • custom_train_step_kwargs (Optional,默认为 None) — 自定义训练步骤的关键字参数。
  • custom_model_provider_function (Optional,默认为 None) — 自定义模型提供函数。
  • custom_prepare_model_function (Optional,默认为 None) — 自定义的模型准备函数。
  • custom_megatron_datasets_provider_function (Optional,默认为 None) — 自定义的 megatron train_valid_test 数据集提供函数。
  • custom_get_batch_function (Optional,默认为 None) — 自定义的获取批次函数。
  • custom_loss_function (Optional,默认为 None) — 自定义损失函数。
  • other_megatron_args (Optional,默认为 None) — 其他 Megatron-LM 参数。请参阅 Megatron-LM。

用于 Megatron-LM 的插件,支持张量、流水线、序列和数据并行。同时支持选择性激活重计算和优化的融合内核。

MegatronLMDummyScheduler

类 accelerate.utils.MegatronLMDummyScheduler

< >

( optimizertotal_num_steps = Nonewarmup_num_steps = 0**kwargs )

参数

  • optimizer (torch.optim.optimizer.Optimizer) — 要包装的优化器。
  • total_num_steps (int) — 总步数。
  • warmup_num_steps (int) — 预热步数。
  • **kwargs(其他关键字参数,可选) — 其他参数。

Dummy scheduler 会呈现模型参数或参数组,这主要用于在 deepspeed 配置文件中指定了调度器配置时,遵循常规的训练循环。

MegatronLMDummyDataLoader

类 accelerate.utils.MegatronLMDummyDataLoader

< >

( **dataset_kwargs )

参数

  • **dataset_kwargs — Megatron 数据参数。

Dummy dataloader 会呈现模型参数或参数组,这主要用于遵循常规的训练

AbstractTrainStep

类 accelerate.utils.AbstractTrainStep

< >

( name )

用于批处理、前向传播和损失处理器的抽象类。

GPTTrainStep

类 accelerate.utils.GPTTrainStep

< >

( acceleratorargs )

参数

  • args (argparse.Namespace) — Megatron-LM 参数。

GPT 训练步骤类。

BertTrainStep

类 accelerate.utils.BertTrainStep

< >

( acceleratorargs )

参数

  • args (argparse.Namespace) — Megatron-LM 参数。

Bert 训练步骤类。

T5TrainStep

类 accelerate.utils.T5TrainStep

< >

( acceleratorargs )

参数

  • args (argparse.Namespace) — Megatron-LM 参数。

T5 训练步骤类。

avg_losses_across_data_parallel_group

accelerate.utils.avg_losses_across_data_parallel_group

< >

( losses )

参数

  • losses (List[Tensor]) — 需要在数据并行组中取平均的损失列表。

在数据并行组中计算平均损失。

Update on GitHub