{"id":13628433,"url":"https://github.com/wkcn/MobulaOP","last_synced_at":"2025-04-17T04:31:47.267Z","repository":{"id":82951641,"uuid":"132334822","full_name":"wkcn/MobulaOP","owner":"wkcn","description":"A Simple \u0026 Flexible Cross Framework Operators Toolkit","archived":false,"fork":false,"pushed_at":"2020-09-27T11:37:25.000Z","size":614,"stargazers_count":164,"open_issues_count":2,"forks_count":21,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-11-08T19:41:46.156Z","etag":null,"topics":["cross-framework","cupy","deep-learning","mxnet","numpy","operators","pytorch","scientific-computing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wkcn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-05-06T12:08:25.000Z","updated_at":"2024-06-13T14:36:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"103985cc-851d-4c20-a695-407da1c6643b","html_url":"https://github.com/wkcn/MobulaOP","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wkcn%2FMobulaOP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wkcn%2FMobulaOP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wkcn%2FMobulaOP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wkcn%2FMobulaOP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wkcn","download_url":"https://codeload.github.com/wkcn/MobulaOP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249315938,"owners_count":21249860,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cross-framework","cupy","deep-learning","mxnet","numpy","operators","pytorch","scientific-computing"],"created_at":"2024-08-01T22:00:51.953Z","updated_at":"2025-04-17T04:31:46.747Z","avatar_url":"https://github.com/wkcn.png","language":"Python","funding_links":[],"categories":["\u003ca name=\"Tools\"\u003e\u003c/a\u003e13. Tools","\u003ca name=\"Tools\"\u003e\u003c/a\u003e9. Tools"],"sub_categories":["13.2 Language Bindings"],"readme":"# MobulaOP\n\nLinux | Windows | Coverage | Badge\n------|---------|----------|------\n[![Linux Build Status](https://api.travis-ci.org/wkcn/MobulaOP.svg?branch=master)](https://travis-ci.org/wkcn/MobulaOP)|[![Windows Build Status](https://ci.appveyor.com/api/projects/status/bvnavb8k2xnu0wqj/branch/master?svg=true)](https://ci.appveyor.com/project/wkcn/mobulaop/branch/master)|[![Coverage Status](https://coveralls.io/repos/github/wkcn/MobulaOP/badge.svg?branch=master)](https://coveralls.io/github/wkcn/MobulaOP?branch=master)|[![996.icu](https://img.shields.io/badge/link-996.icu-red.svg)](https://996.icu)\n\n## What is it?\n*MobulaOP* is a simple and flexible cross framework operators toolkit.\n\nYou can write custom operators by Python/C++/C/CUDA/HIP/TVM without rebuilding deep learning framework from source.\n\n## How to use it?\n\n[[中文教程](docs/tutorial-cn.md)]\n\n[[Tutorial](docs/tutorial-en.md)]\n\n- Add an addition operator [[Code](examples/MyFirstOP.py)]\n\n```python\nimport mobula\n\n@mobula.op.register\nclass MyFirstOP:\n    def forward(self, x, y):\n        return x + y\n    def backward(self, dy): \n        return [dy, dy]\n    def infer_shape(self, in_shape):\n        assert in_shape[0] == in_shape[1]\n        return in_shape, [in_shape[0]]\n\n# MXNet\nimport mxnet as mx\na = mx.nd.array([1, 2, 3])\nb = mx.nd.array([4, 5, 6])\nc = MyFirstOP(a, b)\nprint (c) # [5, 7, 9]\n\n# PyTorch\nimport torch\na = torch.tensor([1, 2, 3])\nb = torch.tensor([4, 5, 6])\nc = MyFirstOP(a, b)\nprint (c) # [5, 7, 9]\n\n# NumPy\nimport numpy as np\na = np.array([1, 2, 3])\nb = np.array([4, 5, 6])\nop = MyFirstOP[np.ndarray]()\nc = op(a, b)\nprint (c) # [5, 7, 9]\n\n# CuPy\nimport cupy as cp\na = cp.array([1, 2, 3])\nb = cp.array([4, 5, 6])\nop = MyFirstOP[cp.ndarray]()\nc = op(a, b)\nprint(c) # [5, 7, 9]\n```\n\n- Use **custom operators** without rebuilding the source of deep learning framework [[Code](examples/RunROIAlign.py)]\n\n```python\n# Use ROIAlign operator\nimport mxnet as mx\nimport numpy as np\nimport mobula\n\n# Load ROIAlign Module\nmobula.op.load('ROIAlign')\n\nctx = mx.cpu(0)\ndtype = np.float32\nN, C, H, W = 2, 3, 4, 4\n\ndata = mx.nd.array(np.arange(N*C*H*W).astype(dtype).reshape((N,C,H,W)))\nrois = mx.nd.array(np.array([[0, 1, 1, 3, 3]], dtype = dtype))\n\ndata.attach_grad()\nwith mx.autograd.record():\n    # mx.nd.NDArray and mx.sym.Symbol are both available as the inputs.\n    output = mobula.op.ROIAlign(data = data, rois = rois, pooled_size = (2,2), spatial_scale = 1.0, sampling_ratio = 1)\n\nprint (output.asnumpy(), data.grad.asnumpy())\n```\n\n- Import Custom C++ Operator Dynamically [[Code](examples/dynamic_import_op/dynamic_import_op.py)]\n\n```python\nimport mobula\n# Import Custom Operator Dynamically\nmobula.op.load('./AdditionOP')\n\nimport mxnet as mx\na = mx.nd.array([1,2,3])\nb = mx.nd.array([4,5,6])\nc = mobula.op.AdditionOP(a, b)\n\nprint ('a + b = c \\n {} + {} = {}'.format(a.asnumpy(), b.asnumpy(), c.asnumpy()))\n```\n\n## How to get it? \n```bash\n# Clone the project\ngit clone https://github.com/wkcn/MobulaOP\n\n# Enter the directory\ncd MobulaOP\n\n# Install MobulaOP\npip install -v -e .\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwkcn%2FMobulaOP","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwkcn%2FMobulaOP","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwkcn%2FMobulaOP/lists"}