MMRazor Documentation

repository·main·Indexed 23 days ago

https://github.com/open-mmlab/mmrazor

An OpenMMLab model compression toolkit providing a unified framework for Neural Architecture Search (NAS), Pruning, Knowledge Distillation (KD), and Quantization. It supports various distillation methods including ABLoss, BYOT (Be Your Own Teacher), Contrastive Representation Distillation (CRD), Data-Free Learning of Student Networks (DAFL), Data-Free Adversarial Distillation (DFAD), Decoupled Knowledge Distillation (DKD), and Factor Transfer.

Tokens
66.6K
Snippets
138
Records
256
Agent score
81%

What's inside MMRazor

  1. Overview of PKD (Pearson Correlation Coefficient) Distillation

    main

    PKD is a general knowledge distillation (KD) framework designed for object detectors. It addresses the challenges of distilling between heterogeneous detectors (where teacher and student have different architectures, heads, or label assignments) by focusing on relational information rather than direct feature map alignment.

    Key features include:

    • Pearson Correlation Coefficient: Uses correlation to imitate features, which relaxes constraints on feature magnitude and prevents high-magnitude teacher features from dominating the distillation gradient.
    • Heterogeneous Support: Works effectively for both homogeneous and heterogeneous student-teacher pairs.
    • FPN Feature Distillation: Focuses on distilling better FPN features from the teacher to the student.

    For more details, refer to the original paper: PKD: General Distillation Framework for Object Detectors via Pearson Correlation Coefficient.

  2. Overview of MMRazor model compression toolkit

    main

    MMRazor is a model compression toolkit designed for model slimming. It supports four mainstream technologies:

    • Neural Architecture Search (NAS)
    • Pruning
    • Knowledge Distillation (KD)
    • Quantization

    It is part of the OpenMMLab project and is designed for high compatibility with other OpenMMLab repositories (like MMClassification, MMDetection, and MMSegmentation) through a decoupled architecture of slimming algorithms and vision tasks.

  3. Overview of MMRazor

    main

    MMRazor is a model compression toolbox and benchmark designed for model slimming and AutoML. It is part of the OpenMMLab project and provides four main categories of compression technologies:

    • Neural Architecture Search (NAS): Automating the design of network structures.
    • Pruning: Removing redundant parameters to reduce model size.
    • Knowledge Distillation (KD): Transferring knowledge from a large teacher model to a smaller student model.
    • Quantization: Reducing the precision of weights and activations (e.g., PTQ, QAT).

    Key features include high compatibility with other OpenMMLab projects due to similar architectural designs, flexibility through plug-and-play algorithm combinations, and ease of extension via modular configuration files.

  4. What is MMRazor?

    main

    MMRazor is a model compression toolkit designed for model slimming and AutoML. It is part of the OpenMMLab project and provides a unified framework for four mainstream model compression technologies:

    • Neural Architecture Search (NAS): Automating the search for optimal network architectures.
    • Pruning: Removing redundant parameters to reduce model size.
    • Knowledge Distillation (KD): Transferring knowledge from a large teacher model to a smaller student model.
    • Quantization: Reducing the precision of model weights and activations.

    Key advantages include compatibility with various OpenMMLab projects due to decoupled algorithm design, flexibility through a plug-and-play system for different algorithms, and convenience for developers to implement new methods via configuration files or minimal code changes.

  5. Overview of MMRazor for Large Models

    main

    MMRazor is a general-purpose model compression toolkit that supports both conventional Computer Vision (CV) models and large-scale models. It provides implementations for pruning and quantization algorithms applied to various architectures such as LLaMA, OPT, and Stable Diffusion.

    The project structure for large model support is organized as follows:

    • mmrazor/implementations: Contains core algorithm components for pruning and quantization.
    • projects/mmrazor_large/algorithms: Contains usage introductions for specific algorithms.
    • projects/mmrazor_large/examples: Contains model-specific implementation examples, categorized by model type (e.g., language_models/LLaMA, language_models/OPT, ResNet).
  6. Overview of Group Fisher Pruning

    main

    Group Fisher Pruning is a general channel pruning approach designed for networks with complicated structures such as residual connections, group/depthwise convolutions, and feature pyramid networks (FPN).

    Key features include:

    • Layer Grouping Algorithm: Automatically identifies coupled channels that must be pruned simultaneously.
    • Fisher Information Metric: Uses a unified metric based on Fisher information to evaluate the importance of individual and coupled channels.
    • Memory-Aware Importance: Normalizes importance based on memory reduction rather than just FLOPs, as memory reduction is more highly correlated with GPU inference speedup.

    This method is applicable to various backbones including ResNet, ResNeXt, MobileNetV2, and RegNet for both image classification and object detection tasks.

  7. Explore mmrazor.engine components

    main

    The mmrazor.engine module contains the core execution logic for model compression and knowledge distillation tasks. It is organized into the following submodules:

    • hooks: Provides mechanisms to intercept and modify the training or evaluation process (e.g., logging, checkpointing).
    • optimizers: Contains optimization algorithms used to update model parameters.
    • runner: The central execution engine that manages the lifecycle of training, validation, and testing.
  8. Explore mmrazor.models components

    main

    The mmrazor.models module defines the building blocks for compression algorithms and model architectures. Key submodules include:

    • algorithms: High-level logic for specific compression or distillation methods.
    • architectures: Base neural network architectures.
    • distillers: Components specifically designed for knowledge distillation.
    • losses: Loss functions used during training.
    • mutables and mutators: Components used for structural modifications or parameter manipulation.
    • ops: Specialized operations used within models.
    • task_modules: Modules that encapsulate specific tasks within the model pipeline.
  9. Data-Free Adversarial Distillation (DFAD) Overview

    main
    Data-Free Adversarial Distillation (DFAD) is a knowledge distillation method designed for scenarios where the original training data is unavailable. Instead of relying on real-world data, it uses an adversarial mechanism where a generator produces 'hard samples' to enlarge the discrepancy between a teacher and a student model. The student and teacher jointly act as a discriminator to minimize this discrepancy. This approach can be applied to classification and semantic segmentation tasks.
  10. Knowledge Distillation (KD) for Image Classification

    main

    Knowledge Distillation (KD) is a technique used to compress the knowledge from a large, high-performance 'Teacher' model into a smaller, more efficient 'Student' model. This allows for deploying models that maintain high accuracy while being computationally cheaper for real-world use.

    In MMrazor, KD configurations for classification tasks (using mmcls backends) typically involve distilling information from the logits of a teacher model to the student model. This repository provides pre-configured experiments and pre-trained models for common teacher-student pairs on the ImageNet dataset.

  11. Contrastive Representation Distillation (CRD)

    main

    Contrastive Representation Distillation (CRD) is a knowledge distillation method that uses contrastive learning to transfer representational knowledge from a teacher network to a student network. Unlike standard knowledge distillation which minimizes KL divergence between probabilistic outputs, CRD aims to capture the structural knowledge of the teacher's representations. It is applicable to tasks such as single model compression, ensemble distillation, and cross-modal transfer.

    This implementation is based on the paper Contrastive Representation Distillation.