ms_custom_ops:基于 MindSpore 的自定义算子扩展项目

用户可借助该项目为大模型等AI领域模型提供高性能算子支撑,助力突破计算效率瓶颈。它依托MindSpore原生能力构建,支持第三方算子库、AscendC算子等多种类型,具备高灵活度的算子接入能力。【此简介由AI生成】

Branch4Tags0
FilesLast commitLast update
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago

MindSpore Custom Operators Extension (ms_custom_ops)

Chinese Version | English

Introduction

MindSpore Custom Operators Extension (ms_custom_ops) is an independent operator extension plugin package built upon MindSpore's native custom operator and custom pass capabilities. Its core positioning is to provide key high-performance operator support for cutting-edge AI domain models such as large models, helping models break through computational efficiency bottlenecks; in terms of operator integration, this plugin package has extremely high flexibility, comprehensively covering various types of operator technologies including third-party operator libraries, AscendC operators, Triton DSL, and other technical approaches, fully meeting operator integration requirements in different development scenarios, and providing underlying support for efficient iteration of AI models.

Description

Directory Structure

ms_custom_ops/
├── CMakeLists.txt        # CMake build configuration
├── README.md             # Project documentation
├── README_EN.md          # English project documentation
├── OWNERS                # Project maintainers
├── LICENSE               # Open source license
├── requirements.txt      # Python dependencies
├── setup.py              # Python package configuration
├── version.txt           # Version information
├── 3rdparty/             # Third-party dependencies
├── cmake/                # CMake build scripts
├── docs/                 # Documentation resources
├── ops/                  # Custom operator kernel source code and integration code
│   ├── ascendc/          # AscendC operator implementation and integration code
│   ├── c_api/            # Operators integrated via pre-packaged API calls
│   ├── framework/        # Operator integration common code
│   └── dsl/              # DSL (Domain Specific Language) operator source code
├── pass/                 # Custom fusion passes
├── prebuild/             # Pre-compiled binary libraries
├── python/               # Python bindings and extensions
├── scripts/              # Build and utility scripts
└── tests/                # Test cases

Quick Start

Prerequisites

  • Python: >= 3.9
  • MindSpore: >= 2.7.1
  • Huawei Ascend Software: CANN toolkit >= 8.3.RC1
  • Compiler: GCC 7.3 or later
  • CMake: 3.16 or later
  • Ninja: 1.11 or later

Environment Setup

  1. Install Huawei Ascend CANN toolkit: Download and install the CANN toolkit from the Huawei Ascend official website

  2. Set Ascend environment:

    export ASCEND_HOME_PATH=${YOUR_INSTALL_PATH}$/ascend-toolkit/latest
    source ${ASCEND_HOME_PATH}/../set_env.sh
    
  3. Install MindSpore: Download and install from MindSpore official website

Build and Installation

  1. Clone the repository:

    git clone https://gitee.com/mindspore/ms-custom-ops.git
    cd ms_custom_ops
    
  2. Install Python dependencies:

    pip install -r requirements.txt
    
  3. Use the build.sh script (recommended):

    # View build options
    bash scripts/build.sh -h
    
    # Default build (Release mode)
    bash scripts/build.sh
    
    # Debug build
    bash scripts/build.sh -d
    
    # force clean build
    bash scripts/build.sh -c
    

    After compilation, install the generated wheel package:

    pip install dist/*.whl
    
  4. Install using setup.py

    # Install (automatically compiles custom operators)
    python setup.py install
    
    # Or build wheel package
    python setup.py bdist_wheel
    

Basic Usage

Using Custom Operators

After installation, you can use the custom operations in your MindSpore code:

import mindspore as ms
import ms_custom_ops

# Example usage of a custom operation (actual API may vary)
# result = ms_custom_ops.some_custom_operation(input_tensor)

Using Custom Passes

You can register and use custom fusion passes to optimize graph execution:

import mindspore as ms
import ms_custom_ops

# Register custom passes
ms_custom_ops.register_custom_pass("AddRmsNormFusionPass", backend="ascend")
ms_custom_ops.register_custom_pass("ReplaceAddNFusionPass", backend="cpu")

# Configure MindSpore context
ms.context.set_context(mode=ms.GRAPH_MODE, device_target="Ascend")

# Your network will automatically apply the registered pass optimizations

For detailed Pass mechanism, architecture design, and development guide, please refer to: Pass Auto-Registration Documentation

Reference Documentation

Internal Documentation

External Documentation

Contributing

We welcome contributions to this project. Please see the CONTRIBUTING.md file for guidelines on how to contribute. We welcome and value any form of contribution and collaboration. Please inform us via Issue of any bugs you encounter, or submit your feature requests, improvement suggestions, and technical proposals.

Introduction

用户可借助该项目为大模型等AI领域模型提供高性能算子支撑,助力突破计算效率瓶颈。它依托MindSpore原生能力构建,支持第三方算子库、AscendC算子等多种类型,具备高灵活度的算子接入能力。【此简介由AI生成】

Customize your domain