README.md 2.49 KB
Newer Older
1
## nGraph Neural Network compiler
2

3
[nGraph][ngraph_github] is Intel's open-source graph compiler and runtime for Neural Network models. Frameworks using nGraph to execute workloads have shown up to [45X](https://ai.intel.com/ngraph-compiler-stack-beta-release/) performance boost compared to native implementations.
4

5
nGraph can be used directly thought it's [Python API][api_python] or [C++ API][api_cpp]. Alternatively it can be used through one of its frontends, e.g. [TensorFlow][frontend_tf], [MXNet][frontend_mxnet] and [ONNX][frontend_onnx].
6

7
## Installation
8

9
nGraph is available as binary wheels you can install from PyPI. nGraph binary wheels are currently tested on Ubuntu 16.04 and require a CPU with AVX-512 instructions, if you're using a different system, you may want to [build][ngraph_building] nGraph from sources.
10

11
Installing nGraph Python API from PyPI is easy:
12

13
    pip install ngraph-core
14

15
## Usage example
16

17
Using nGraph's Python API to construct a computation graph and execute a computation is simple. The following example shows how to create a simple `(A + B) * C` computation graph and calculate a result using 3 numpy arrays as input.
18

19 20 21
```python
import numpy as np
import ngraph as ng
22

23 24 25 26 27
A = ng.parameter(shape=[2, 2], name='A', dtype=np.float32)
B = ng.parameter(shape=[2, 2], name='B', dtype=np.float32)
C = ng.parameter(shape=[2, 2], name='C', dtype=np.float32)
# >>> print(A)
# <Parameter: 'A' ([2, 2], float)>
28

29 30 31
model = (A + B) * C
# >>> print(model)
# <Multiply: 'Multiply_14' ([2, 2])>
32

33 34 35
runtime = ng.runtime(backend_name='CPU')
# >>> print(runtime)
# <Runtime: Backend='CPU'>
36

37 38 39
computation = runtime.computation(model, A, B, C)
# >>> print(computation)
# <Computation: Multiply_14(A, B, C)>
40

41 42 43
value_a = np.array([[1, 2], [3, 4]], dtype=np.float32)
value_b = np.array([[5, 6], [7, 8]], dtype=np.float32)
value_c = np.array([[9, 10], [11, 12]], dtype=np.float32)
44

45 46 47 48
result = computation(value_a, value_b, value_c)
# >>> print(result)
# [[ 54.  80.]
#  [110. 144.]]
49

50 51
print('Result = ', result)
```
52

53 54 55 56 57 58 59
[frontend_onnx]: https://pypi.org/project/ngraph-onnx/
[frontend_mxnet]: https://pypi.org/project/ngraph-mxnet/ 
[frontend_tf]: https://pypi.org/project/ngraph-tensorflow-bridge/
[ngraph_github]: https://github.com/NervanaSystems/ngraph "nGraph on GitHub"
[ngraph_building]: https://github.com/NervanaSystems/ngraph/blob/master/python/BUILDING.md "Building nGraph"
[api_python]: https://ngraph.nervanasys.com/docs/latest/python_api/ "nGraph's Python API documentation"
[api_cpp]: https://ngraph.nervanasys.com/docs/latest/howto/