Skip to content

Commit

Permalink
[Doc]: revise docs (open-mmlab#547)
Browse files Browse the repository at this point in the history
* revise docs

* Update README.md

Co-authored-by: Qian Zhao <[email protected]>

Co-authored-by: Qian Zhao <[email protected]>
  • Loading branch information
2 people authored and HAOCHENYE committed Oct 8, 2022
1 parent ccb32c7 commit 8f91cf0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,25 @@ English | [简体中文](README_zh-CN.md)

## 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 on various research areas. Importantly, 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 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.

Major features:

1. **Universal and powerful runner**.
1. **A universal and powerful runner**:

- Fewer code, e.g., train ImageNet with 1/5 lines of code compared with PyTorch example.
- Compatible with popular libraries like OpenMMLab, TorchVision, timm and Detectron2.
- 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

2. **Open architecture with unified interfaces**.
2. **Open architecture with unified interfaces**:

- Handle different algorithm tasks with unified API, e.g., implement a method and apply it to all compatible models.
- Support different devices and hardwares with unified API, including CPU, GPU, IPU, Apple silicon, etc.
- 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.

3. **Customizable training process**.
3. **Customizable training process**:

- Define the training process like playing with Legos. Rich components and strategies are available.
- Complete control of training with different level of APIs.
- 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.

## Installation

Expand All @@ -74,12 +75,15 @@ python -c 'from mmengine.utils.dl_utils import collect_env;print(collect_env())'

## Get Started

As an example of training a ResNet-50 model on the CIFAR-10 dataset, we will build a complete, configurable training and validation process using MMEngine in less than 80 lines of code.
Taking the training of a ResNet-50 model on the CIFAR-10 dataset as an example, we will use MMEngine to build a complete, configurable training and validation process in less than 80 lines of code.

<details>
<summary>Build Models</summary>

First, we need to define a **Model** that 1) inherits from `BaseModel`, and 2) accepts an additional argument `mode` in the `forward` method, in addition to those arguments related to the dataset. During training, the value of `mode` is "loss" and the `forward` method should return a dict containing the key "loss". During validation, the value of `mode` is "predict" and the forward method should return results containing both predictions and labels.
First, we need to define a **model** which 1) inherits from `BaseModel` and 2) accepts an additional argument `mode` in the `forward` method, in addition to those arguments related to the dataset.

- During training, the value of `mode` is "loss," and the `forward` method should return a `dict` containing the key "loss".
- During validation, the value of `mode` is "predict", and the forward method should return results containing both predictions and labels.

```python
import torch.nn.functional as F
Expand All @@ -104,7 +108,7 @@ class MMResNet50(BaseModel):
<details>
<summary>Build Datasets</summary>

Next, we need to create a **Dataset** and **DataLoader** for training and validation.
Next, we need to create **Dataset**s and **DataLoader**s for training and validation.
In this case, we simply use built-in datasets supported in TorchVision.

```python
Expand Down Expand Up @@ -141,7 +145,7 @@ val_dataloader = DataLoader(batch_size=32,
<details>
<summary>Build Metrics</summary>

To validate and test the model, we need to define a **Metric** like accuracy to evaluate the model. This metric needs inherit from `BaseMetric` and implements the `process` and `compute_metrics` methods.
To validate and test the model, we need to define a **Metric** called accuracy to evaluate the model. This metric needs inherit from `BaseMetric` and implements the `process` and `compute_metrics` methods.

```python
from mmengine.evaluator import BaseMetric
Expand All @@ -167,7 +171,7 @@ class Accuracy(BaseMetric):
<details>
<summary>Build a Runner</summary>

Finally, we can construct a **Runner** with previously defined Model, DataLoader, Metrics and some other configs, as shown below.
Finally, we can construct a **Runner** with previously defined `Model`, `DataLoader`, and `Metrics`, with some other configs, as shown below.

```python
from torch.optim import SGD
Expand Down
20 changes: 10 additions & 10 deletions README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@

## 简介

MMEngine 是一个用于深度学习模型训练的基础库,基于 PyTorch,支持在 Linux、Windows、macOS 上运行。它具有如下三个亮点:
MMEngine 是一个基于 PyTorch 用于深度学习模型训练的基础库,支持在 Linux、Windows、macOS 上运行。它具有如下三个亮点:

1. 通用:MMEngine 实现了一个高级的通用训练器,它能够:

- 支持用少量代码训练不同的任务,例如仅使用 80 行代码就可以训练 imagenet(pytorch example 400 行)
- 轻松兼容流行的算法库如 TIMM、TorchVision 和 Detectron2 中的模型
- 支持用少量代码训练不同的任务,例如仅使用 80 行代码就可以训练 imagenet(原始pytorch example 400 行)
- 轻松兼容流行的算法库 (如 TIMM、TorchVision 和 Detectron2 ) 中的模型

2. 统一:MMEngine 设计了一个接口统一的开放架构,使得
2. 统一:MMEngine 设计了一个接口统一的开放架构,使得:

- 用户可以仅依赖一份代码实现所有任务的轻量化,例如 MMRazor 1.x 相比 MMRazor 0.x 优化了 40% 的代码量
- 上下游的对接更加统一便捷,在为上层算法库提供统一抽象的同时,支持多种后端设备。目前 MMEngine 支持 Nvidia CUDA、Mac MPS、AMD、MLU 等设备进行模型训练。

3. 灵活:MMEngine 实现了“乐高”式的训练流程,支持了
3. 灵活:MMEngine 实现了“乐高”式的训练流程,支持了:

- 根据迭代数、 loss 和评测结果等动态调整的训练流程、优化策略和数据增强策略,例如早停(early stopping)机制等
- 任意形式的模型权重平均,如 Exponential Momentum Average (EMA) 和 Stochastic Weight Averaging (SWA)
Expand Down Expand Up @@ -79,15 +79,15 @@ python -c 'from mmengine.utils.dl_utils import collect_env;print(collect_env())'

## 快速上手

以在 CIFAR-10 数据集上训练一个 ResNet-50 模型为例,我们将使用 80 行以内的代码,利用 MMEngine 构建一个完整的、
可配置的训练和验证流程。
以在 CIFAR-10 数据集上训练一个 ResNet-50 模型为例,我们将使用 80 行以内的代码,利用 MMEngine 构建一个完整的、可配置的训练和验证流程。

<details>
<summary>构建模型</summary>

首先,我们需要构建一个**模型**,在 MMEngine 中,我们约定这个模型应当继承 `BaseModel`,并且其 `forward` 方法除了接受来自数据集的若干参数外,
还需要接受额外的参数 `mode`:对于训练,我们需要 `mode` 接受字符串 "loss",并返回一个包含 "loss" 字段的字典;
对于验证,我们需要 `mode` 接受字符串 "predict",并返回同时包含预测信息和真实信息的结果。
首先,我们需要构建一个**模型**,在 MMEngine 中,我们约定这个模型应当继承 `BaseModel`,并且其 `forward` 方法除了接受来自数据集的若干参数外,还需要接受额外的参数 `mode`

- 对于训练,我们需要 `mode` 接受字符串 "loss",并返回一个包含 "loss" 字段的字典;
- 对于验证,我们需要 `mode` 接受字符串 "predict",并返回同时包含预测信息和真实信息的结果。

```python
import torch.nn.functional as F
Expand Down

0 comments on commit 8f91cf0

Please sign in to comment.