PaddleSlim Documentation

repository·develop·Indexed 23 days ago

https://github.com/paddlepaddle/paddleslim

A deep learning model compression toolkit for model miniaturization. It provides tools for low-bit quantization (including PTQ and QAT), knowledge distillation, sparsification, and neural architecture search (NAS) using methods like DARTS and PC-DARTS. The toolkit includes SlimDet, a model library integrated with PaddleDetection for compression techniques such as sensitivity-based convolutional channel pruning and distillation for pruned models.

Tokens
162.6K
Snippets
354
Records
653
Agent score
78%

What's inside PaddleSlim

  1. Overview of Auto Compression Toolkit (ACT)

    develop

    The Auto Compression Toolkit (ACT) is a source-free automated model compression tool provided by PaddleSlim. It is designed to automatically compress prediction models so they can be deployed directly without requiring access to the original training code or source code.

    Key features include:

    • Decoupled Training Code: Developers can compress exported prediction models directly without modifying model source code.
    • Full-Process Automated Optimization: ACT automatically optimizes compression strategies to find the best performing model based on user configuration.
    • Rich Compression Algorithms: Supports a combination of quantization training, distillation, structured pruning, unstructured pruning, various offline quantization methods, and hyperparameter search.
  2. Overview of the paddleslim package structure

    develop

    The paddleslim package is organized into several specialized subpackages for different model compression and optimization tasks. Depending on your goal, you should use the corresponding subpackage:

    • paddleslim.analysis: For model analysis.
    • paddleslim.common: Common utilities and shared components.
    • paddleslim.core: Core compression logic and engine.
    • paddleslim.dist: Distribution-related utilities.
    • paddleslim.models: Model-specific compression implementations.
    • paddleslim.nas: Neural Architecture Search (NAS) capabilities.
    • paddleslim.pantheon: Pantheon-specific features.
    • paddleslim.prune: Pruning techniques to remove redundant parameters.
    • paddleslim.quant: Quantization techniques to reduce precision requirements.
  3. Overview of built-in pruning methods in PaddleSlim

    develop

    PaddleSlim provides several built-in filter pruning methods that support different execution modes (Static Graph vs. Dynamic Graph) and features like sensitivity analysis or custom pruning rates per layer.

    MethodStatic GraphDynamic GraphSensitivity AnalysisCustom Layer Ratios
    FPGMFilterPrunerYesYesYesYes
    L1NormFilterPrunerYesYesYesYes
    L2NormFilterPrunerNoYesYesYes
    SlimFilterPrunerYesNoYesYes
    OptSlimFilterPrunerYesNoYesYes
    • Sensitivity Analysis: Supports determining pruning rates for convolutional layers based on their sensitivity.
    • Custom Layer Ratios: Supports manually specifying pruning rates for individual convolutional layers.
  4. Overview of the paddleslim.nas package

    develop

    The paddleslim.nas package provides tools for Neural Architecture Search (NAS). It is organized into subpackages and modules designed to automate the search for optimal neural network architectures.

    Key components include:

    • paddleslim.nas.one_shot: A subpackage likely containing one-shot NAS algorithms (where a single weight-sharing supernet is trained to search for sub-networks).
    • paddleslim.nas.sa_nas: A submodule providing specific NAS capabilities (likely related to 'Searchable Architecture' or similar NAS paradigms).
  5. Overview of YOLO Series Automatic Compression

    develop

    This example demonstrates how to automatically compress YOLO series object detection models (YOLOv5, YOLOv6, and YOLOv7) using PaddleSlim's ACT (Automatic Compression Technology).

    Workflow:

    1. Convert: Use X2Paddle to convert PyTorch models to PaddlePaddle models.
    2. Compress: Use PaddleSlim's AutoCompression feature to perform quantization and distillation.
    3. Deploy: The resulting compressed models can be deployed using Paddle Inference or exported to ONNX for TensorRT deployment.
  6. Overview of SlimOCR Models

    develop

    PaddleSlim provides compressed versions of models originally released by PaddleOCR. These models are optimized for tasks like text detection and recognition using strategies such as PACT quantization and pruning.

    Key model series include:

    • MobileNetV3_DB / MobileNetV3_CRNN: Original models without compression.
    • SlimTextDet / SlimTextRec: Models compressed using PACT quantization training.
    • SlimTextDet_quat_pruning: Models using both pruning and PACT quantization.
    • SlimTextDet_pruning: Models using pruning.

    Note on Latency: Latency measurements are based on a Snapdragon 855 chip with PaddleLite. For recognition models, the reported latency is per detection box; total latency for an image is the sum of detection time and the recognition time for all detected boxes.

  7. Overview of PaddleSlim compression features

    develop

    PaddleSlim is a toolkit for deep learning model compression. It provides several core strategies to achieve model miniaturization:

    • Quantization: Includes Quantization Aware Training (QAT), PACT, Static Post-Training Quantization (PTQ), Dynamic PTQ, and Embedding Quantization.
    • Pruning: Includes SensitivityPruner, FPGMFilterPruner, L1NormFilterPruner, L2NormFilterPruner, SlimFilterPruner (static graph only), and OptSlimFilterPruner (static graph only).
    • NAS (Neural Architecture Search): Includes Simulate Anneal based NAS, Reinforcement Learning based NAS, DARTS, PC-DARTS, Once-for-All, and Hardware-aware Search.
    • Distilling: Includes FSP, DML, and DK methods.

    Note: * indicates support for static graphs only, and ** indicates support for dynamic graphs only.

  8. Overview of FIMA-Q: Post-Training Quantization for Vision Transformers

    develop
    FIMA-Q is a joint compression method that combines pruning and quantization. It is specifically designed for Vision Transformers (ViT) using Fisher Information Matrix Approximation to perform Post-Training Quantization (PTQ). This approach aims to compress models by jointly addressing sparsity and precision.