• Stars
    star
    164
  • Rank 230,032 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created over 6 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Simple & Flexible Cross Framework Operators Toolkit

MobulaOP

Linux Windows Coverage Badge
Linux Build Status Windows Build Status Coverage Status 996.icu

What is it?

MobulaOP is a simple and flexible cross framework operators toolkit.

You can write custom operators by Python/C++/C/CUDA/HIP/TVM without rebuilding deep learning framework from source.

How to use it?

[中文教程]

[Tutorial]

  • Add an addition operator [Code]
import mobula

@mobula.op.register
class MyFirstOP:
    def forward(self, x, y):
        return x + y
    def backward(self, dy): 
        return [dy, dy]
    def infer_shape(self, in_shape):
        assert in_shape[0] == in_shape[1]
        return in_shape, [in_shape[0]]

# MXNet
import mxnet as mx
a = mx.nd.array([1, 2, 3])
b = mx.nd.array([4, 5, 6])
c = MyFirstOP(a, b)
print (c) # [5, 7, 9]

# PyTorch
import torch
a = torch.tensor([1, 2, 3])
b = torch.tensor([4, 5, 6])
c = MyFirstOP(a, b)
print (c) # [5, 7, 9]

# NumPy
import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
op = MyFirstOP[np.ndarray]()
c = op(a, b)
print (c) # [5, 7, 9]

# CuPy
import cupy as cp
a = cp.array([1, 2, 3])
b = cp.array([4, 5, 6])
op = MyFirstOP[cp.ndarray]()
c = op(a, b)
print(c) # [5, 7, 9]
  • Use custom operators without rebuilding the source of deep learning framework [Code]
# Use ROIAlign operator
import mxnet as mx
import numpy as np
import mobula

# Load ROIAlign Module
mobula.op.load('ROIAlign')

ctx = mx.cpu(0)
dtype = np.float32
N, C, H, W = 2, 3, 4, 4

data = mx.nd.array(np.arange(N*C*H*W).astype(dtype).reshape((N,C,H,W)))
rois = mx.nd.array(np.array([[0, 1, 1, 3, 3]], dtype = dtype))

data.attach_grad()
with mx.autograd.record():
    # mx.nd.NDArray and mx.sym.Symbol are both available as the inputs.
    output = mobula.op.ROIAlign(data = data, rois = rois, pooled_size = (2,2), spatial_scale = 1.0, sampling_ratio = 1)

print (output.asnumpy(), data.grad.asnumpy())
  • Import Custom C++ Operator Dynamically [Code]
import mobula
# Import Custom Operator Dynamically
mobula.op.load('./AdditionOP')

import mxnet as mx
a = mx.nd.array([1,2,3])
b = mx.nd.array([4,5,6])
c = mobula.op.AdditionOP(a, b)

print ('a + b = c \n {} + {} = {}'.format(a.asnumpy(), b.asnumpy(), c.asnumpy()))

How to get it?

# Clone the project
git clone https://github.com/wkcn/MobulaOP

# Enter the directory
cd MobulaOP

# Install MobulaOP
pip install -v -e .

More Repositories

1

OSLabs

使用NASM汇编以及C++(内嵌MASM)编写的实模式操作系统,以及一个汇编编写的QQ堂图形化游戏
Assembly
75
star
2

TinyCLIP

[ICCV2023] TinyCLIP: CLIP Distillation via Affinity Mimicking and Weight Inheritance
Python
53
star
3

mobula

A Lightweight & Flexible Deep Learning (Neural Network) Framework in Python
Python
44
star
4

TinyViT

[ECCV 2022] TinyViT: Fast Pretraining Distillation for Small Vision Transformers (https://github.com/microsoft/Cream/tree/main/TinyViT)
Python
36
star
5

3dviewer

一个跨平台的三维模型编辑器,支持多个模型放缩、旋转、矩阵变换,顶点修改,导入obj文件,读取mtl材质文件
C++
27
star
6

CaffeSVD

使用SVD、K-Means、降低权值精度的方法压缩Cifar-10神经网络的全连接层
Python
24
star
7

AttentionSampler

Attention-based sampler in TASN (Trilinear Attention Sampling Network)
Python
23
star
8

Adaptive-Fast-Face-Color-Transfer

《自适应的快速人脸肤色转移》(Adaptive Fast Face Color Transfer)论文复现
Python
23
star
9

LookaheadOptimizer-mx

Lookahead Optimizer: k steps forward, 1step back for MXNet
Python
21
star
10

TodoList

TodoList - 我的计划表 我的待办事项管理程序 使用Qt制作
C++
18
star
11

MikuMikuFace

基于人工神经网络的动漫角色人脸检测
MATLAB
14
star
12

pyjackal

赤色要塞Python复刻版
Python
14
star
13

learning_tvm

Learning TVM
Python
12
star
14

pyfcemu

A NES Emulator Written in Python
Python
12
star
15

resnet-fcn.tensorflow

ResNet + FCN (tensorflow version) for Semantic Segmentation
Python
10
star
16

oh-my-gpu

GPU Manager on Multi-Server
Python
8
star
17

TinyViT-model-zoo

The model zoo of TinyViT: Fast Pretraining Distillation for Small Vision Transformers
7
star
18

weekly_challenge_for_algorithm

Weekly Challenge for Algorithm
C++
7
star
19

iRPE-model-zoo

The Model Zoo of the ICCV 2021 paper `Rethinking and Improving Relative Position Encoding for Vision Transformer`
7
star
20

42

The answer to life, the universe, and everything
C++
7
star
21

TVM_tutorials_for_EAIDK

TVM tutorials, which are adapted to EAIDK
Python
7
star
22

SicilyChan

A cute girl Sicily in SYSU Online Judge
C++
5
star
23

LuckyMapleJam

一个欢乐的抽奖器
C++
5
star
24

MobulaOP-mx

MXNet Operator Extend
Cuda
5
star
25

UGATIT-mxnet

[WIP] Unofficial MXNet implementation of U-GAT-IT: Unsupervised Generative Attentional Networks with Adaptive Layer-Instance Normalization for Image-to-Image Translation
Python
5
star
26

MyVimConfig

我的Vim配置文件
Vim Script
4
star
27

mlkit

implement machine learning algorithm from scratch
C++
4
star
28

resnet-v1-mx

ResNet v1 on MXNet
Python
4
star
29

vgg-mx

VGG on MXNet
Python
3
star
30

ModuleEXT-mx

The extended version of mxnet.module.Module
Python
3
star
31

leetcode

C++
2
star
32

HappyQQT-ASM

An Intel 8086 Emulator for QQTang-ASM
Assembly
2
star
33

nccl

C++
2
star
34

TinyCLIP-model-zoo

The model zoo of TinyCLIP: CLIP Distillation via Affinity Mimicking and Weight Inheritance
2
star
35

canny

C++
1
star
36

my-arduino-toys

My Arduino Toys
C++
1
star
37

stock

股市的基本数据统计
Python
1
star
38

KeilC2SDCC

Keil C to SDCC
Python
1
star
39

SLang

SLang解释器和高精度实现,向Lisp致敬
C++
1
star
40

FlyingChess

一个基于MFC的飞行棋游戏
C++
1
star
41

Poly

基于SLang的多项式运算系统
C++
1
star
42

learning_rust

Learning Rust
Rust
1
star
43

DinostyPlayer

自动玩Chrome小恐龙游戏
Python
1
star
44

iRPE

[ICCV 2021] Rethinking and Improving Relative Position Encoding for Vision Transformer (https://github.com/microsoft/Cream/tree/main/iRPE)
Python
1
star
45

WorldCup

WorldCup Simulator
Python
1
star
46

DLCustomOp

C++
1
star
47

GameX

A simple Game Frame Help you quickly know how to build a game frame for Windows and Linux >.<
C++
1
star
48

testsvr

Python
1
star
49

nanoGPT

Integrate MS-AMP into nanoGPT (https://github.com/karpathy/nanoGPT)
Python
1
star