MMDeploy Documentation

repository·main·Indexed 25 days ago

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

An open-source deep learning model deployment toolset within the OpenMMLab ecosystem. MMDeploy enables efficient deployment of models across various hardware platforms and inference backends, including TensorRT and ONNXRuntime. It provides SDKs and APIs for C/C++, C# (via NuGet), and Java, along with guides for model conversion, configuration, profiling, quantization, and extending backend support.

Tokens
155.5K
Snippets
348
Records
671
Agent score
83%

What's inside MMDeploy

  1. MMDeploy Documentation Overview

    main

    MMDeploy provides a comprehensive set of guides for model deployment. The documentation is organized into several key areas:

    • Getting Started: Quickstart guides to begin using MMDeploy.
    • Compilation: Instructions for building from source, including one-click scripts, Docker, and platform-specific builds (Linux, macOS, Windows, Android, Jetson, SNPE, and cross-building for aarch64).
    • Usage: Workflows for converting models to inference backends, configuring conversion parameters, quantization, and testing converted models.
    • Developer Guide: Deep dives into software architecture, supporting new models, adding new inference backends, model partitioning, and testing/regression testing.
    • Custom Operators: Lists of custom operators for specific backends like ncnn, onnxruntime, and tensorrt.
    • Tutorials: Beginner-friendly guides covering terminology, deployment challenges, PyTorch to ONNX conversion, and debugging ONNX models.
  2. Understand the MMDeploy Repository Structure

    main

    MMDeploy is divided into two primary functional parts: Model Conversion and the SDK.

    • Model Conversion logic is primarily located in tools/, mmdeploy/, and parts of csrc/.
    • SDK core components are located in csrc/, third_party/, and demo/.

    Key directories:

    • configs/: Algorithm library configurations for model conversion.
    • csrc/: Source code for the SDK and custom operators.
    • demo/: FFI interface application examples (C#, Java, Python, etc.).
    • mmdeploy/: Python package used for model conversion.
    • service/: Server implementations for Client/Server mode (used when target frameworks like SNPE do not support Python).
    • tools/: Entry points for all functionalities, including deploy.py, onnx2xx.py, profiler.py, and test.py.
  3. Supported TVM features in MMDeploy

    main

    MMDeploy integrates TVM into both its model conversion tools and its SDK. The following TVM features are supported:

    • AutoTVM tuner: For automated performance tuning.
    • Ansor tuner: For automated performance tuning.
    • Graph Executor runtime: For executing the model graph.
    • Virtual Machine runtime: For executing the model via the TVM VM.
  4. Understand common challenges in model deployment

    main

    When deploying deep learning models, developers typically encounter three main categories of difficulties:

    1. Model Dynamization: Most inference frameworks default to static input/output shapes and structures for performance reasons. Making a model dynamic (allowing variable input sizes or structures) without breaking original logic is a key challenge.
    2. New Operator Implementation: New deep learning operators are often released faster than inference engines (like ONNX or TensorRT) can support them. This requires engineers to implement custom operator support.
    3. IR and Inference Engine Compatibility: Different inference engines have varying levels of support for Intermediate Representations (IR) like ONNX. Ensuring consistent behavior across different engines often requires engine-specific model customization.
  5. Understand the Model Deployment Pipeline

    main

    Model deployment is the process of running a trained model in a specific environment, addressing issues like framework incompatibility and slow execution speeds. The standard deployment pipeline follows this flow:

    1. Deep Learning Framework: Where the model is trained (e.g., PyTorch).
    2. Intermediate Representation (IR): A common format used to bridge frameworks and engines, most notably ONNX.
    3. Inference Engine: The runtime that executes the model (e.g., ONNX Runtime, TensorRT, ncnn, OpenVINO).

    Key concepts:

    • Static Computation Graphs: Deployment often involves converting models into static graphs that lack control flow (like branches or loops).
    • MMDeploy Role: MMDeploy facilitates the deployment of OpenMMLab models (detection, segmentation, super-resolution, etc.) across multiple inference engines like ONNX Runtime, TensorRT, ncnn, OpenPPPL, and OpenVINO.
  6. Understand the MMDeploy deployment workflow

    main

    MMDeploy facilitates the deployment of OpenMMLab algorithms through a three-stage pipeline:

    1. Model Converter: Converts input models (e.g., PyTorch) into device-agnostic IR models (ONNX, TorchScript) or directly into backend-specific formats (e.g., TensorRT, ONNX Runtime).
    2. MMDeploy Model (SDK Model): A collection of the converted backend model and its associated metadata required for inference.
    3. Inference SDK: A multi-language interface that encapsulates pre-processing, network inference, and post-processing.
  7. Understand ONNX underlying implementation and structure

    main

    ONNX models are stored using Protobuf (Protocol Buffers), a serialization mechanism by Google. The .onnx file is a binary instance of the data definitions (Protobuf files) that specify the types for models, nodes, and tensors.

    An ONNX model is structured as a computational graph where:

    • ModelProto: The top-level container representing the model. It includes metadata (version, creator) and the graph.
    • GraphProto: Contained within ModelProto, it defines the computational structure, including inputs, outputs, and nodes.
    • ValueInfoProto: Describes tensor information, including the tensor name, data type, and shape.
    • NodeProto: Describes an operator node, including the operator type (op_type), and the names of its input and output tensors.
  8. Understand the MMDeploy Architecture

    main

    MMDeploy is divided into two independent parts: Model Conversion and the SDK.

    • Model Conversion: Primarily uses tools, mmdeploy (Python package), and parts of csrc. It is used to rewrite model code (e.g., forward methods) and convert models to specific inference backends (like ncnn or TensorRT).
    • SDK: Consists of csrc, third_party, and demo. It is a C++ based framework designed to execute converted models on various platforms, providing abstractions for preprocessing, inference, and postprocessing, along with FFI (Foreign Function Interface) for multiple languages.