Skip to content

Commit

Permalink
Merge branch 'open-mmlab:main' into lzh/fix_ds_optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
LZHgrla committed Feb 1, 2024
2 parents 590824c + f79111e commit 6e3bb64
Show file tree
Hide file tree
Showing 39 changed files with 522 additions and 205 deletions.
57 changes: 22 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
[![open issues](https://isitmaintained.com/badge/open/open-mmlab/mmengine.svg)](https://github.com/open-mmlab/mmengine/issues)
[![issue resolution](https://isitmaintained.com/badge/resolution/open-mmlab/mmengine.svg)](https://github.com/open-mmlab/mmengine/issues)

[Introduction](#introduction) |
[Installation](#installation) |
[Get Started](#get-started) |
[📘Documentation](https://mmengine.readthedocs.io/en/latest/) |
[🛠️Installation](https://mmengine.readthedocs.io/en/latest/get_started/installation.html) |
[🤔Reporting Issues](https://github.com/open-mmlab/mmengine/issues/new/choose)

</div>
Expand Down Expand Up @@ -58,55 +60,40 @@ English | [简体中文](README_zh-CN.md)

## What's New

v0.10.1 was released on 2023-11-22.
v0.10.3 was released on 2024-1-24.

Highlights:

- Support installing mmengine-lite with no dependency on opencv. Refer to the [Installation](https://mmengine.readthedocs.io/en/latest/get_started/installation.html#install-mmengine) for more details.
- Add the support for musa device [#1453](#1453)
- Add the usage of ProfilerHook [#1466](#1466)

- Support training with [ColossalAI](https://colossalai.org/). Refer to the [Training Large Models](https://mmengine.readthedocs.io/en/latest/common_usage/large_model_training.html#colossalai) for more detailed usages.

- Support gradient checkpointing. Refer to the [Save Memory on GPU](https://mmengine.readthedocs.io/en/latest/common_usage/save_gpu_memory.html#gradient-checkpointing) for more details.

- Supports multiple visualization backends, including `NeptuneVisBackend`, `DVCLiveVisBackend` and `AimVisBackend`. Refer to [Visualization Backends](https://mmengine.readthedocs.io/en/latest/common_usage/visualize_training_log.html) for more details.

Read [Changelog](./docs/en/notes/changelog.md#v0101-22112023) for more details.

## Table of Contents

- [Introduction](#introduction)
- [Installation](#installation)
- [Get Started](#get-started)
- [Learn More](#learn-more)
- [Contributing](#contributing)
- [Citation](#citation)
- [License](#license)
- [Ecosystem](#ecosystem)
- [Projects in OpenMMLab](#projects-in-openmmlab)
Read [Changelog](./docs/en/notes/changelog.md#v0103-2412024) for more details.

## Introduction

MMEngine is a foundational library for training deep learning models based on PyTorch. It provides a solid engineering foundation and frees developers from writing redundant codes on workflows. It serves as the training engine of all OpenMMLab codebases, which support hundreds of algorithms in various research areas. Moreover, MMEngine is also generic to be applied to non-OpenMMLab projects.
MMEngine is a foundational library for training deep learning models based on PyTorch. It serves as the training engine of all OpenMMLab codebases, which support hundreds of algorithms in various research areas. Moreover, MMEngine is also generic to be applied to non-OpenMMLab projects. Its highlights are as follows:

Major features:
**Integrate mainstream large-scale model training frameworks**

1. **A universal and powerful runner**:
- [ColossalAI](https://mmengine.readthedocs.io/en/latest/common_usage/large_model_training.html#colossalai)
- [DeepSpeed](https://mmengine.readthedocs.io/en/latest/common_usage/large_model_training.html#deepspeed)
- [FSDP](https://mmengine.readthedocs.io/en/latest/common_usage/large_model_training.html#fullyshardeddataparallel-fsdp)

- Supports training different tasks with a small amount of code, e.g., ImageNet can be trained with only 80 lines of code (400 lines of the original PyTorch example).
- Easily compatible with models from popular algorithm libraries such as TIMM, TorchVision, and Detectron2.
**Supports a variety of training strategies**

2. **Open architecture with unified interfaces**:
- [Mixed Precision Training](https://mmengine.readthedocs.io/en/latest/common_usage/speed_up_training.html#mixed-precision-training)
- [Gradient Accumulation](https://mmengine.readthedocs.io/en/latest/common_usage/save_gpu_memory.html#gradient-accumulation)
- [Gradient Checkpointing](https://mmengine.readthedocs.io/en/latest/common_usage/save_gpu_memory.html#gradient-checkpointing)

- Handles different algorithm tasks with unified APIs, e.g., implement a method and apply it to all compatible models.
- Provides a unified abstraction for upper-level algorithm libraries, which supports various back-end devices such as Nvidia CUDA, Mac MPS, AMD, MLU, and more for model training.
**Provides a user-friendly configuration system**

3. **Customizable training process**:
- [Pure Python-style configuration files, easy to navigate](https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#a-pure-python-style-configuration-file-beta)
- [Plain-text-style configuration files, supporting JSON and YAML](https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html)

- Defines the training process just like playing with Legos.
- Provides rich components and strategies.
- Complete controls on the training process with different levels of APIs.
**Covers mainstream training monitoring platforms**

![mmengine_dataflow](https://github.com/open-mmlab/mmengine/assets/58739961/267db9cb-72e4-4af2-a58b-877b30091acc)
- [TensorBoard](https://mmengine.readthedocs.io/en/latest/common_usage/visualize_training_log.html#tensorboard) | [WandB](https://mmengine.readthedocs.io/en/latest/common_usage/visualize_training_log.html#wandb) | [MLflow](https://mmengine.readthedocs.io/en/latest/common_usage/visualize_training_log.html#mlflow-wip)
- [ClearML](https://mmengine.readthedocs.io/en/latest/common_usage/visualize_training_log.html#clearml) | [Neptune](https://mmengine.readthedocs.io/en/latest/common_usage/visualize_training_log.html#neptune) | [DVCLive](https://mmengine.readthedocs.io/en/latest/common_usage/visualize_training_log.html#dvclive) | [Aim](https://mmengine.readthedocs.io/en/latest/common_usage/visualize_training_log.html#aim)

## Installation

Expand Down
65 changes: 28 additions & 37 deletions README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
[![open issues](https://isitmaintained.com/badge/open/open-mmlab/mmengine.svg)](https://github.com/open-mmlab/mmengine/issues)
[![issue resolution](https://isitmaintained.com/badge/resolution/open-mmlab/mmengine.svg)](https://github.com/open-mmlab/mmengine/issues)

[📘使用文档](https://mmengine.readthedocs.io/zh_CN/latest/) |
[🛠️安装教程](https://mmengine.readthedocs.io/zh_CN/latest/get_started/installation.html) |
[简介](#简介) |
[安装](#安装) |
[快速上手](#快速上手) |
[📘用户文档](https://mmengine.readthedocs.io/zh_CN/latest/) |
[🤔报告问题](https://github.com/open-mmlab/mmengine/issues/new/choose)

</div>
Expand Down Expand Up @@ -58,56 +60,45 @@

## 最近进展

最新版本 v0.10.12023.11.22 发布。
最新版本 v0.10.32024.1.24 发布。

亮点
版本亮点

- 支持安装不依赖于 opencv 的 mmengine-lite 版本。可阅读[安装文档](https://mmengine.readthedocs.io/zh-cn/latest/get_started/installation.html#mmengine)了解用法。
- 适配摩尔线程 [#1453](#1453)
- 添加 ProfilerHook 使用文档 [#1466](#1466)

- 支持使用 [ColossalAI](https://colossalai.org/) 进行训练。可阅读[大模型训练](https://mmengine.readthedocs.io/zh_CN/latest/common_usage/large_model_training.html#colossalai)了解用法
如果想了解更多版本更新细节和历史信息,请阅读[更新日志](./docs/en/notes/changelog.md#v0103-2412024)

- 支持梯度检查点。详见[用法](https://mmengine.readthedocs.io/zh_CN/latest/common_usage/save_gpu_memory.html#id3)

- 支持多种可视化后端,包括`NeptuneVisBackend``DVCLiveVisBackend``AimVisBackend`。可阅读[可视化后端](https://mmengine.readthedocs.io/zh_CN/latest/common_usage/visualize_training_log.html)了解用法。

如果想了解更多版本更新细节和历史信息,请阅读[更新日志](./docs/en/notes/changelog.md#v0101-22112023)

## 目录
## 简介

- [简介](#简介)
- [安装](#安装)
- [快速上手](#快速上手)
- [了解更多](#了解更多)
- [贡献指南](#贡献指南)
- [引用](#引用)
- [开源许可证](#开源许可证)
- [生态项目](#生态项目)
- [OpenMMLab 的其他项目](#openmmlab-的其他项目)
- [欢迎加入 OpenMMLab 社区](#欢迎加入-openmmlab-社区)
MMEngine 是一个基于 PyTorch 实现的,用于训练深度学习模型的基础库。它作为 OpenMMLab 所有代码库的训练引擎,其在不同研究领域支持了上百个算法。此外,MMEngine 也可以用于非 OpenMMLab 项目中。它的亮点如下:

## 简介
**集成主流的大模型训练框架**

MMEngine 是一个基于 PyTorch 实现的,用于训练深度学习模型的基础库。它为开发人员提供了坚实的工程基础,以此避免在工作流上编写冗余代码。作为 OpenMMLab 所有代码库的训练引擎,其在不同研究领域支持了上百个算法。此外,MMEngine 也可以用于非 OpenMMLab 项目中。
- [ColossalAI](https://mmengine.readthedocs.io/zh-cn/latest/common_usage/large_model_training.html#colossalai)
- [DeepSpeed](https://mmengine.readthedocs.io/zh-cn/latest/common_usage/large_model_training.html#deepspeed)
- [FSDP](https://mmengine.readthedocs.io/zh-cn/latest/common_usage/large_model_training.html#fullyshardeddataparallel-fsdp)

主要特性:
**支持丰富的训练策略**

1. **通用且强大的执行器**
- [混合精度训练(Mixed Precision Training)](https://mmengine.readthedocs.io/zh-cn/latest/common_usage/speed_up_training.html#id3)
- [梯度累积(Gradient Accumulation)](https://mmengine.readthedocs.io/zh-cn/latest/common_usage/save_gpu_memory.html#id2)
- [梯度检查点(Gradient Checkpointing)](https://mmengine.readthedocs.io/zh-cn/latest/common_usage/save_gpu_memory.html#id3)

- 支持用少量代码训练不同的任务,例如仅使用 80 行代码就可以训练 ImageNet(原始 PyTorch 示例需要 400 行)。
- 轻松兼容流行的算法库(如 TIMM、TorchVision 和 Detectron2)中的模型。
**提供易用的配置系统**

2. **接口统一的开放架构**
- [纯 Python 风格的配置文件,易于跳转](https://mmengine.readthedocs.io/zh-cn/latest/advanced_tutorials/config.html#python-beta)
- [纯文本风格的配置文件,支持 JSON 和 YAML](https://mmengine.readthedocs.io/zh-cn/latest/advanced_tutorials/config.html#id1)

- 使用统一的接口处理不同的算法任务,例如,实现一个方法并应用于所有的兼容性模型。
- 上下游的对接更加统一便捷,在为上层算法库提供统一抽象的同时,支持多种后端设备。目前 MMEngine 支持 Nvidia CUDA、Mac MPS、AMD、MLU 等设备进行模型训练。
**覆盖主流的训练监测平台**

3. **可定制的训练流程**
- [TensorBoard](https://mmengine.readthedocs.io/zh-cn/latest/common_usage/visualize_training_log.html#tensorboard) | [WandB](https://mmengine.readthedocs.io/zh-cn/latest/common_usage/visualize_training_log.html#wandb) | [MLflow](https://mmengine.readthedocs.io/zh-cn/latest/common_usage/visualize_training_log.html#mlflow-wip)
- [ClearML](https://mmengine.readthedocs.io/zh-cn/latest/common_usage/visualize_training_log.html#clearml) | [Neptune](https://mmengine.readthedocs.io/zh-cn/latest/common_usage/visualize_training_log.html#neptune) | [DVCLive](https://mmengine.readthedocs.io/zh-cn/latest/common_usage/visualize_training_log.html#dvclive) | [Aim](https://mmengine.readthedocs.io/zh-cn/latest/common_usage/visualize_training_log.html#aim)

- 定义了“乐高”式的训练流程。
- 提供了丰富的组件和策略。
- 使用不同等级的 API 控制训练过程。
**兼容主流的训练芯片**

![mmengine_dataflow](https://github.com/open-mmlab/mmengine/assets/58739961/267db9cb-72e4-4af2-a58b-877b30091acc)
- 英伟达 CUDA | 苹果 MPS
- 华为 Ascend | 寒武纪 MLU | 摩尔线程 MUSA

## 安装

Expand Down
6 changes: 3 additions & 3 deletions docs/en/common_usage/distributed_training.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ On the first machine:

```bash
python -m torch.distributed.launch \
--nnodes 8 \
--nnodes 2 \
--node_rank 0 \
--master_addr 127.0.0.1 \
--master_port 29500 \
Expand All @@ -38,9 +38,9 @@ On the second machine:

```bash
python -m torch.distributed.launch \
--nnodes 8 \
--nnodes 2 \
--node_rank 1 \
--master_addr 127.0.0.1 \
--master_addr "ip_of_the_first_machine" \
--master_port 29500 \
--nproc_per_node=8 \
examples/distributed_training.py --launcher pytorch
Expand Down
35 changes: 17 additions & 18 deletions docs/en/get_started/introduction.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
# Introduction

MMEngine is a foundational library for training deep learning models based on
PyTorch. It supports running on Linux, Windows, and macOS. It has the
following three features:
PyTorch. It supports running on Linux, Windows, and macOS. Its highlights are as follows:

1. **Universal and powerful executor**:
**Integrate mainstream large-scale model training frameworks**

- Supports training different tasks with minimal code, such as training
ImageNet with just 80 lines of code (original PyTorch examples require
400 lines).
- Easily compatible with models from popular algorithm libraries like TIMM,
TorchVision, and Detectron2.
- [ColossalAI](../common_usage/large_model_training.md#colossalai)
- [DeepSpeed](../common_usage/large_model_training.md#deepspeed)
- [FSDP](../common_usage/large_model_training.md#fullyshardeddataparallel-fsdp)

2. **Open architecture with unified interfaces**:
**Supports a variety of training strategies**

- Handles different tasks with a unified API: you can implement a method
once and apply it to all compatible models.
- Supports various backend devices through a simple, high-level
abstraction. Currently, MMEngine supports model training on Nvidia CUDA,
Mac MPS, AMD, MLU, and other devices.
- [Mixed Precision Training](../common_usage/speed_up_training.md#mixed-precision-training)
- [Gradient Accumulation](../common_usage/save_gpu_memory.md#gradient-accumulation)
- [Gradient Checkpointing](../common_usage/save_gpu_memory.md#gradient-checkpointing)

3. **Customizable training process**:
**Provides a user-friendly configuration system**

- Defines a highly modular training engine with "Lego"-like composability.
- Offers a rich set of components and strategies.
- Total control over the training process with different levels of APIs.
- [Pure Python-style configuration files, easy to navigate](../advanced_tutorials/config.md#a-pure-python-style-configuration-file-beta)
- [Plain-text-style configuration files, supporting JSON and YAML](../advanced_tutorials/config.html)

**Covers mainstream training monitoring platforms**

- [TensorBoard](../common_usage/visualize_training_log.md#tensorboard) | [WandB](../common_usage/visualize_training_log.md#wandb) | [MLflow](../common_usage/visualize_training_log.md#mlflow-wip)
- [ClearML](../common_usage/visualize_training_log.md#clearml) | [Neptune](../common_usage/visualize_training_log.md#neptune) | [DVCLive](../common_usage/visualize_training_log.md#dvclive) | [Aim](../common_usage/visualize_training_log.md#aim)

## Architecture

Expand Down
35 changes: 35 additions & 0 deletions docs/en/notes/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
# Changelog of v0.x

## v0.10.3 (24/1/2024)

### New Features & Enhancements

- Add the support for musa device support by [@hanhaowen-mt](https://github.com/hanhaowen-mt) in https://github.com/open-mmlab/mmengine/pull/1453
- Support `save_optimizer=False` for DeepSpeed by [@LZHgrla](https://github.com/LZHgrla) in https://github.com/open-mmlab/mmengine/pull/1474
- Update visualizer.py by [@Anm-pinellia](https://github.com/Anm-pinellia) in https://github.com/open-mmlab/mmengine/pull/1476

### Bug Fixes

- Fix `Config.to_dict` by [@HAOCHENYE](https://github.com/HAOCHENYE) in https://github.com/open-mmlab/mmengine/pull/1465
- Fix the resume of iteration by [@LZHgrla](https://github.com/LZHgrla) in https://github.com/open-mmlab/mmengine/pull/1471
- Fix `dist.collect_results` to keep all ranks' elements by [@LZHgrla](https://github.com/LZHgrla) in https://github.com/open-mmlab/mmengine/pull/1469

### Docs

- Add the usage of ProfilerHook by [@zhouzaida](https://github.com/zhouzaida) in https://github.com/open-mmlab/mmengine/pull/1466
- Fix the nnodes in the doc of ddp training by [@XiwuChen](https://github.com/XiwuChen) in https://github.com/open-mmlab/mmengine/pull/1462

## v0.10.2 (26/12/2023)

### New Features & Enhancements

- Support multi-node distributed training with NPU backend by [@shun001](https://github.com/shun001) in https://github.com/open-mmlab/mmengine/pull/1459
- Use `ImportError` to cover `ModuleNotFoundError` by [@del-zhenwu](https://github.com/del-zhenwu) in https://github.com/open-mmlab/mmengine/pull/1438

### Bug Fixes

- Fix bug in `load_model_state_dict` of `BaseStrategy` by [@SCZwangxiao](https://github.com/SCZwangxiao) in https://github.com/open-mmlab/mmengine/pull/1447
- Fix placement policy in ColossalAIStrategy by [@fanqiNO1](https://github.com/fanqiNO1) in https://github.com/open-mmlab/mmengine/pull/1440

### Contributors

A total of 4 developers contributed to this release. Thanks [@shun001](https://github.com/shun001), [@del-zhenwu](https://github.com/del-zhenwu), [@SCZwangxiao](https://github.com/SCZwangxiao), [@fanqiNO1](https://github.com/fanqiNO1)

## v0.10.1 (22/11/2023)

### Bug Fixes
Expand Down
25 changes: 20 additions & 5 deletions docs/en/tutorials/hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ Each hook has a corresponding priority. At each mount point, hooks with higher p

**custom hooks**

| Name | Function | Priority |
| :---------------------------------: | :----------------------------------------------------------------------: | :---------: |
| [EMAHook](#emahook) | apply Exponential Moving Average (EMA) on the model during training | NORMAL (50) |
| [EmptyCacheHook](#emptycachehook) | Releases all unoccupied cached GPU memory during the process of training | NORMAL (50) |
| [SyncBuffersHook](#syncbuffershook) | Synchronize model buffers at the end of each epoch | NORMAL (50) |
| Name | Function | Priority |
| :---------------------------------: | :----------------------------------------------------------------------: | :-----------: |
| [EMAHook](#emahook) | Apply Exponential Moving Average (EMA) on the model during training | NORMAL (50) |
| [EmptyCacheHook](#emptycachehook) | Releases all unoccupied cached GPU memory during the process of training | NORMAL (50) |
| [SyncBuffersHook](#syncbuffershook) | Synchronize model buffers at the end of each epoch | NORMAL (50) |
| [ProfilerHook](#profilerhook) | Analyze the execution time and GPU memory usage of model operators | VERY_LOW (90) |

```{note}
It is not recommended to modify the priority of the default hooks, as hooks with lower priority may depend on hooks with higher priority. For example, `CheckpointHook` needs to have a lower priority than ParamSchedulerHook so that the saved optimizer state is correct. Also, the priority of custom hooks defaults to `NORMAL (50)`.
Expand Down Expand Up @@ -211,6 +212,20 @@ runner = Runner(custom_hooks=custom_hooks, ...)
runner.train()
```

### ProfilerHook

The [ProfilerHook](mmengine.hooks.ProfilerHook) is used to analyze the execution time and GPU memory occupancy of model operators.

```python
custom_hooks = [dict(type='ProfilerHook', on_trace_ready=dict(type='tb_trace'))]
runner = Runner(custom_hooks=custom_hooks, ...)
runner.train()
```

The profiling results will be saved in the tf_tracing_logs directory under `work_dirs/{timestamp}`, and can be visualized using TensorBoard with the command `tensorboard --logdir work_dirs/{timestamp}/tf_tracing_logs`.

For more information on the usage of the ProfilerHook, please refer to the [ProfilerHook](mmengine.hooks.ProfilerHook) documentation.

## Customize Your Hooks

If the built-in hooks provided by MMEngine do not cover your demands, you are encouraged to customize your own hooks by simply inheriting the base [hook](mmengine.hooks.Hook) class and overriding the corresponding mount point methods.
Expand Down
Loading

0 comments on commit 6e3bb64

Please sign in to comment.