Transformers documentation

DeepSpeed

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

DeepSpeed

DeepSpeed 基于 Zero Redundancy Optimizer (ZeRO) 技术,是一个用于在 GPU 上训练和拟合超大模型的优化库。它提供多个 ZeRO 阶段,每个阶段通过分区优化器状态、梯度和参数,并支持将数据卸载到 CPU 或 NVMe,从而逐步节省更多 GPU 内存。DeepSpeed 已与 Trainer 类集成,大部分配置工作会自动为您处理。

不过,如果您想在不使用 Trainer 的情况下使用 DeepSpeed,Transformers 提供了一个 HfDeepSpeedConfig 类。

有关使用 DeepSpeed 与 Trainer 的更多信息,请参阅 DeepSpeed 指南。

HfDeepSpeedConfig

class transformers.integrations.HfDeepSpeedConfig

< >

( config_file_or_dict )

参数

  • config_file_or_dict (Union[str, Dict]) — DeepSpeed 配置文件的路径或字典。

该对象包含一个 DeepSpeed 配置字典,可以快速查询诸如 zero stage 之类的信息。

该对象的 weakref 会存储在模块的全局变量中,以便在无法访问 Trainer 对象等组件的区域(例如 from_pretrained 和 _get_resized_embeddings)中访问 config。因此,在程序运行期间,必须确保该对象保持存活。

Trainer 使用的是 HfTrainerDeepSpeedConfig 子类。该子类包含用于将配置与 TrainingArguments 的值进行同步的逻辑,方法是替换特殊占位符值:"auto"。如果没有这种特殊逻辑,DeepSpeed 配置将不会以任何方式被修改。

Update on GitHub