Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
M

mmengine

> 编程语言
Open source

OpenMMLab Foundational Library for Training Deep Learning Models

1.5K stars0 likes0 views
WebsiteGitHub

About

OpenMMLab Foundational Library for Training Deep Learning Models

Introduction | Installation | Get Started | Documentation | Reporting Issues

What's New

v0.10.6 was released on 2025-01-13.

Highlights:

  • Support custom artifact_location in MLflowVisBackend #1505
  • Enable exclude_frozen_parameters for DeepSpeedEngine._zero3_consolidated_16bit_state_dict #1517

Read Changelog for more details.

Introduction

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:

Integrate mainstream large-scale model training frameworks

  • ColossalAI
  • DeepSpeed
  • FSDP

Supports a variety of training strategies

  • Mixed Precision Training
  • Gradient Accumulation
  • Gradient Checkpointing

Provides a user-friendly configuration system

  • Pure Python-style configuration files, easy to navigate
  • Plain-text-style configuration files, supporting JSON and YAML

Covers mainstream training monitoring platforms

  • TensorBoard | WandB | MLflow
  • ClearML | Neptune | DVCLive | Aim

Installation

Supported PyTorch Versions
MMEngine PyTorch Python
main >=1.6 <=2.1 >=3.8, <=3.11
>=0.9.0, <=0.10.4 >=1.6 <=2.1 >=3.8, <=3.11

Before installing MMEngine, please ensure that PyTorch has been successfully installed following the official guide.

Install MMEngine

bash
pip install -U openmim
mim install mmengine

Verify the installation

bash
python -c 'from mmengine.utils.dl_utils import collect_env;print(collect_env())'

Get Started

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.

Build Models

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
import torchvision
from mmengine.model import BaseModel

class MMResNet50(BaseModel):
    def __init__(self):
        super().__init__()
        self.resnet = torchvision.models.resnet50()

    def forward(self, imgs, labels, mode):
        x = self.resnet(imgs)
        if mode == 'loss':
            return {'loss': F.cross_entropy(x, labels)}
        elif mode == 'predict':
            return x, labels
Build Datasets

Next, we need to create Datasets and DataLoaders for training and validation. In this case, we simply use built-in datasets supported in TorchVision.

…
Build Metrics

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

…
Build a Runner

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
from mmengine.runner import Runner

runner = Runner(
    model=MMResNet50(),
    work_dir='./work_dir',
    train_dataloader=train_dataloader,
    # a wrapper to execute back propagation and gradient update, etc.
    optim_wrapper=dict(optimizer=dict(type=SGD, lr=0.001, momentum=0.9)),
    # set some training configs like epochs
    train_cfg=dict(by_epoch=True, max_epochs=5, val_interval=1),
    val_dataloader=val_dataloader,
    val_cfg=dict(),
    val_evaluator=dict(type=Accuracy),
)
Launch Training
python
runner.train()

Learn More

Tutorials
  • Runner
  • Dataset and DataLoader
  • Model
  • Evaluation
  • OptimWrapper
  • Parameter Scheduler
  • Hook
Advanced tutorials
  • Registry
  • Config
  • BaseDataset
  • Data Transform
  • Weight Initialization
  • Visualization
  • Abstract Data Element
  • Distribution Communication
  • Logging
  • File IO
  • Global manager (ManagerMixin)
  • Use modules from other libraries
  • Test Time Agumentation
Examples
  • Train a GAN
Common Usage
  • Resume Training
  • Speed up Training
  • Save Memory on GPU
Design
  • Hook
  • Runner
  • Evaluation
  • Visualization
  • Logging
  • Infer
Migration guide
  • Migrate Runner from MMCV to MMEngine
  • Migrate Hook from MMCV to MMEngine
  • Migrate Model from MMCV to MMEngine
  • Migrate Parameter Scheduler from MMCV to MMEngine
  • Migrate Data Transform to OpenMMLab 2.0

Contributing

We appreciate all contributions to improve MMEngine. Please refer to CONTRIBUTING.md for the contributing guideline.

Citation

If you find this project useful in your research, please consider cite:

@article{mmengine2022,
  title   = {{MMEngine}: OpenMMLab Foundational Library for Training Deep Learning Models},
  author  = {MMEngine Contributors},
  howpublished = {\\url{https://github.com/open-mmlab/mmengine}},
  year={2022}
}

License

This project is released under the Apache 2.0 license.

Ecosystem

  • APES: Attention-based Point Cloud Edge Sampling
  • DiffEngine: diffusers training toolbox with mmengine

Projects in OpenMMLab

  • MIM: MIM installs OpenMMLab packages.
  • MMCV: OpenMMLab foundational library for computer vision.
  • MMEval: A unified evaluation library for multiple machine learning libraries.
  • MMPreTrain: OpenMMLab pre-training toolbox and benchmark.
  • MMagic: OpenMMLab Advanced, Generative and Intelligent Creation toolbox.
  • MMDetection: OpenMMLab detection toolbox and benchmark.
  • MMYOLO: OpenMMLab YOLO series toolbox and benchmark.
  • MMDetection3D: OpenMMLab's next-generation platform for general 3D object detection.
  • MMRotate: OpenMMLab rotated object detection toolbox and benchmark.
  • MMTracking: OpenMMLab video perception toolbox and benchmark.
  • MMPose: OpenMMLab pose estimation toolbox and benchmark.
  • MMSegmentation: OpenMMLab semantic segmentation toolbox and benchmark.
  • MMOCR: OpenMMLab text detection, recognition, and understanding toolbox.
  • MMHuman3D: OpenMMLab 3D human parame

Issues· 268 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Pythonaicomputer-visiondeep-learningmachine-learning

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言