{"id":13936641,"url":"https://github.com/dmlc/minpy","last_synced_at":"2025-07-19T22:31:41.210Z","repository":{"id":57441880,"uuid":"45584086","full_name":"dmlc/minpy","owner":"dmlc","description":"NumPy interface with mixed backend execution","archived":true,"fork":false,"pushed_at":"2018-02-19T22:22:39.000Z","size":59612,"stargazers_count":1109,"open_issues_count":28,"forks_count":111,"subscribers_count":62,"default_branch":"master","last_synced_at":"2024-11-18T15:29:33.615Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://minpy.readthedocs.io/en/latest/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dmlc.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}},"created_at":"2015-11-05T03:10:48.000Z","updated_at":"2024-09-21T05:15:19.000Z","dependencies_parsed_at":"2022-09-13T03:03:00.270Z","dependency_job_id":null,"html_url":"https://github.com/dmlc/minpy","commit_stats":null,"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmlc%2Fminpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmlc%2Fminpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmlc%2Fminpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmlc%2Fminpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmlc","download_url":"https://codeload.github.com/dmlc/minpy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226686729,"owners_count":17666928,"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":[],"created_at":"2024-08-07T23:02:52.822Z","updated_at":"2024-11-27T04:31:22.829Z","avatar_url":"https://github.com/dmlc.png","language":"Python","funding_links":[],"categories":["Other ML","Python"],"sub_categories":[],"readme":"# MinPy\n\n[![Build Status](https://travis-ci.org/dmlc/minpy.svg?branch=master)](https://travis-ci.org/dmlc/minpy)\n[![PyPI version](https://badge.fury.io/py/minpy.svg)](https://badge.fury.io/py/minpy)\n[![Docs](https://readthedocs.org/projects/minpy/badge/?version=latest)](https://minpy.readthedocs.io/en/latest/)\n\n**Please try [MXNet Gluon](https://github.com/apache/incubator-mxnet)**.\nOur project has merged with MXNet Gluon which follows our vision.\nThis repo is being deprecated.\n\nThis repository aims at providing a high performing and flexible deep learning platform, by prototyping a pure [NumPy](http://www.numpy.org/) interface above [MXNet](https://github.com/dmlc/mxnet) backend. In one word, you get the following automatically with your NumPy code:\n```python\nimport minpy.numpy as np\n```\n* Operators with GPU support will be ran on GPU.\n* Graceful fallback for missing operations to NumPy on CPU.\n* Automatic gradient generation with [Autograd](https://github.com/HIPS/autograd) support.\n* Seamless MXNet symbol integration.\n\n## Pure NumPy, purely imperative\n\nWhy obsessed with NumPy interface? First of all, NumPy is an extension to the Python programming language, with support for large, multi-dimensional arrays, matrices, and a large library of high-level mathematical functions to operate on these abstractions. If you just begin to learn deep learning, you should absolutely start from NumPy to gain a firm grasp of its concepts (see, for example, the Stanford's [CS231n course](http://cs231n.stanford.edu/syllabus.html)). For quick prototyping of advanced deep learning algorithms, you may often start composing with NumPy as well.\n\nSecond, as an extension of Python, your implementation follows the intuitive imperative style. This is the *only* style, and there is *no* new syntax constructs to learn. To have a taste of this, let's look at some examples below.\n\n### Printing and Debugging\n![p1](https://raw.githubusercontent.com/dmlc/web-data/master/minpy/p1.png)\nIn symbolic programming, the control dependency before the print statement is required, otherwise the print operator will not appear on the critical dependency path and thus not being executed. In contrast, MinPy is simply NumPy, as straightforward as Python's hello world.\n\n### Data-dependent branches\n![p2](https://raw.githubusercontent.com/dmlc/web-data/master/minpy/p2.png)\nIn symbolic programming, the `lambda` is required in each branch to lazily expand the dataflow graph during runtime, which can be quite confusing. Again, MinPy is NumPy, and you freely use the if statement anyway you like.\n\nTensorflow is just one typical example, many other packages (e.g. Theano, or even MXNet) have similar problems. The underlying reason is the trade-off between *symbolic programming* and *imperative programming*. Codes in symbolic programs (Tensorflow and Theano) generates dataflow graph instead of performing concrete computation. This enables extensive optimizations, but requires reinventing almost all language constructs (like if and loop). Imperative programs (NumPy) generates dataflow graph *along with* the computation, enabling you freely query or use the value just computed. \n\nIn MinPy, we use NumPy syntax to ease your programming, while simultaneously achieving good performance.\n\n## Dynamic automatic gradient computation\nAutomatic gradient computation has become essential in modern deep learning systems. In MinPy, we adopt [Autograd](https://github.com/HIPS/autograd)'s approach to compute gradients. Since the dataflow graph is generated along with the computation, all kinds of native control flow are supported during gradient computation. For example:\n```python\nimport minpy\nfrom minpy.core import grad\n\ndef foo(x):\n  if x \u003e= 0:\n    return x\n  else:\n    return 2 * x\n\nfoo_grad = grad(foo)\nprint foo_grad(3)  # should print 1.0\nprint foo_grad(-1) # should print 2.0\n```\nHere, feel free to use native `if` statement. A complete tutorial about auto-gradient computation could be found [here](https://minpy.readthedocs.io/en/latest/tutorial/autograd_tutorial.html).\n\n## Elegant fallback for missing operators\nYou never like `NotImplementedError`, so do we. NumPy is a very large library. In MinPy, we automatically fallback to NumPy if some operators have not been implemented in MXNet yet. For example, the following code runs smoothly and you don't need to worry about copying arrays back and forth from GPU to CPU; MinPy handles the fallback and its side effect transparently.\n```python\nimport minpy.numpy as np\nx = np.zeros((2, 3))     # Use MXNet GPU implementation\ny = np.ones((2, 3))      # Use MXNet GPU implementation\nz = np.logaddexp(x, y)   # Use NumPy CPU implementation\n```\n\n## Seamless MXNet symbol support\nAlthough we pick the imperative side, we understand that symbolic programming is necessary for operators like convolution. Therefore, MinPy allows you to \"wrap\" a symbol into a function that could be called together with other imperative calls. From a programmer's eye, these functions is just as other NumPy calls, thus we preserve the imperative style throughout:\n```python\nimport mxnet as mx\nimport minpy.numpy as np\nfrom minpy.core import Function\n# Create Function from symbol.\nnet = mx.sym.Variable('x')\nnet = mx.sym.Convolution(net, name='conv', kernel=(3, 3), num_filter=32, no_bias=True)\nconv = Function(net, input_shapes={'x', (8, 3, 10, 10)}\n# Call Function as normal function.\nx = np.zeros((8, 3, 10, 10))\nw = np.ones((32, 3, 3, 3,))\ny = np.exp(conv(x=x, conv_weight=w))\n```\n\n## Is MinPy fast?\nThe imperative interface does raise many challenges, especially it foregoes some of the deep optimization that only (currently) embodied in symbolic programming. However, MinPy manages to retain performance, especially when the actual computation is intense. Our next target is to get back the performance with advanced system techniques.\n![benchmark](https://raw.githubusercontent.com/dmlc/web-data/master/minpy/benchmark.png)\n\n\n## Get Started\n\n### Installation Guide\n\nMinPy depends on MXNet. In order to get up and running with MinPy you'll need to\n\n1) Install MXNet for Python;\n\n2) Install Minpy.\n\nPlease read [installation guide](https://minpy.readthedocs.io/en/latest/get-started/install.html) for more details.\n\n### MXNet version\n\nCurrently both MXNet and MinPy are going through rapid development. MinPy is not guaranteed to work with all MXNet versions. **The minimum version required for MXNet is 0.9.2.** To achieve the best performance, we recommend you download the MXNet from `engine` branch and build it from source. The following command would be useful:\n```\ngit clone --recursive -b engine https://github.com/dmlc/mxnet.git\n```\nThen use the [instructions](http://mxnet.io/get_started/ubuntu_setup.html#install-mxnet-for-python) to build MXNet with python interface.\n\n### NumPy version\n\nMinpy prototypes a pure Numpy interface. To make the interface consistent, please make sure Numpy version \u003e= 1.10.0 before install Minpy.\n\nMXNet and Numpy could meet version conflicts if you are working with them on other projects. Our [installation guide](https://minpy.readthedocs.io/en/latest/get-started/install.html) provides how to use [virtualenv](https://virtualenv.pypa.io/en/stable/) and [virtualenvwrapper](https://virtualenvwrapper.readthedocs.io/en/latest/) to resolve the issue.\n\n### Easy installation\n\n```\npip install minpy\n```\n\nWe are still actively polishing the package. You can look at this [tutorial](https://github.com/dmlc/minpy/blob/master/examples/demo/minpy_tutorial.ipynb) to understand its concept. Documents are hosted [here](https://minpy.readthedocs.io/en/latest/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmlc%2Fminpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmlc%2Fminpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmlc%2Fminpy/lists"}