Neuron Apache MXNet Compilation Python API — AWS Neuron Documentation (original) (raw)

Contents

This document is relevant for: Inf1

Neuron Apache MXNet Compilation Python API#

The MXNet-Neuron compilation Python API provides a method to compile model graph for execution on Inferentia.

Description#

Within the graph or subgraph, the compile method selects and sends Neuron-supported operations to Neuron-Compiler for compilation and saves the compiled artifacts in the graph. Uncompilable operations are kept as original operations for framework execution.

The compiled graph can be saved using the MXNet save_checkpoint and served using MXNet Model Serving. Please seeTutorial: Neuron Apache MXNet Model Serving for more information about exporting to saved model and serving using MXNet Model Serving.

Options can be passed to Neuron compiler via the compile function. For example, the “--neuroncore-pipeline-cores” option directs Neuron compiler to compile each subgraph to fit in the specified number of NeuronCores. This number can be less than the total available NeuronCores on an Inf1 instance. See Neuron compiler CLI Reference Guide (neuron-cc) for more information about compiler options.

For debugging compilation, use SUBGRAPH_INFO=1 environment setting before calling the compilation script. The extract subgraphs are preserved as hidden files in the run directory. For more information, see Using Neuron GatherInfo Tool to collect debug and support information

MXNet 1.5#

Method#

from mxnet.contrib import neuron neuron.compile(sym, args, aux, inputs, **compile_args)

Arguments#

Returns#

Example Usage: Compilation#

The following is an example usage of the compilation, with default compilation arguments:

from mxnet.contrib import neuron ... neuron.compile(sym, args, aux, inputs={'data' : img})

MXNet 1.8#

Method#

import mx_neuron as neuron neuron.compile(obj, args=None, aux=None, inputs=None, **compile_args)

Arguments#

Returns#

Example Usage: Compilation#

The following is an example usage of the compilation, with default compilation arguments for symbol object:

import mx_neuron as neuron ... neuron.compile(sym, args, aux, inputs={'data' : img})

The following is an example usage of the compilation, with default compilation arguments for gluon.HybridBlock object (only supported in MXNet-Neuron 1.8):

import mx_neuron as neuron ... neuron.compile(obj, inputs={'data' : img})