Python Reference

shape

class migraphx.shape(type, lens, strides=None)

Describes the shape of a tensor. This includes size, layout, and data type/

migraphx.type()

An integer that represents the type

Return type

int

migraphx.lens()

A list of the lengths of the shape

Return type

list[int]

migraphx.strides()

A list of the strides of the shape

Return type

list[int]

migraphx.elements()

The number of elements in the shape

Return type

int

migraphx.bytes()

The number of bytes the shape uses

Return type

int

migraphx.type_size()

The number of bytes one element uses

Return type

int

migraphx.packed()

Returns true if the shape is packed.

Return type

bool

migraphx.transposed()

Returns true if the shape is transposed.

Return type

bool

migraphx.broadcasted()

Returns true if the shape is broadcasted.

Return type

bool

migraphx.standard()

Returns true if the shape is a standard shape. That is, the shape is both packed and not transposed.

Return type

bool

migraphx.scalar()

Returns true if all strides are equal to 0 (scalar tensor).

Return type

bool

argument

class migraphx.argument(data)

Construct an argument from a python buffer. This can include numpy arrays.

migraphx.get_shape()

Returns the shape of the argument.

Return type

shape

migraphx.tolist()

Convert the elements of the argument to a python list.

Return type

list

migraphx.generate_argument(s, seed=0)

Generate an argument with random data.

Parameters
  • s (shape) – Shape of argument to generate.

  • seed (int) – The seed used for random number generation

Return type

argument

target

class migraphx.target

This represents the compiliation target.

migraphx.get_target(name)

Constructs the target.

Parameters

name (str) – The name of the target to construct. This can either be ‘gpu’ or ‘ref’.

Return type

target

program

class migraphx.program

Represents the computation graph to be compiled and run.

migraphx.clone()

Make a copy of the program

Return type

program

migraphx.get_parameter_shapes()

Get the shapes of all the input parameters in the program.

Return type

dict[str, shape]

migraphx.get_shape()

Get the shape of the final output of the program.

Return type

shape

migraphx.compile(t, offload_copy=True, fast_math=True)

Compiles the program for the target and optimizes it.

Parameters
  • t (target) – This is the target to compile the program for.

  • offload_copy (bool) – For targets with offloaded memory(such as the gpu), this will insert instructions during compilation to copy the input parameters to the offloaded memory and to copy the final result from the offloaded memory back to main memory.

  • fast_math (bool) – Optimize math functions to use faster approximate versions. There may be slight accuracy degredation when enabled.

migraphx.run(params)

Run the program.

Parameters

params (dict[str, argument]) – This is a map of the input parameters which will be used when running the program.

Returns

The result of the last instruction.

Return type

argument

migraphx.quantize_fp16(prog, ins_names=['all'])

Quantize the program to use fp16.

Parameters
  • prog (program) – Program to quantize.

  • ins_names (list[str]) – List of instructions to quantize.

migraphx.quantize_int8(prog, t, calibration=[], ins_names=['dot', 'convolution'])

Quantize the program to use int8.

Parameters
  • prog (program) – Program to quantize.

  • t (target) – Target that will be used to run the calibration data.

  • calibration (list[dict[str, argument]]) – Calibration data used to decide the parameters to the int8 optimization.

  • ins_names (list[str]) – List of instructions to quantize.

parse_onnx

migraphx.parse_onnx(filename, default_dim_value=1, map_input_dims={}, skip_unknown_operators=false, print_program_on_error=false)

Load and parse an onnx file.

Parameters
  • filename (str) – Path to file.

  • default_dim_value (str) – default batch size to use (if not specified in onnx file).

  • map_input_dims (str) – Explicitly specify the dims of an input.

  • skip_unknown_operators (str) – Continue parsing onnx file if an unknown operator is found.

  • print_program_on_error (str) – Print program if an error occurs.

Return type

program

parse_tf

migraphx.parse_tf(filename, is_nhwc=True, batch_size=1)

Load and parse an tensorflow protobuf file file.

Parameters
  • filename (str) – Path to file.

  • is_nhwc (bool) – Use nhwc as default format.

  • batch_size (str) – default batch size to use (if not specified in protobuf).

Return type

program

load

migraphx.load(filename, format='msgpack')

Load a MIGraphX program

Parameters
  • filename (str) – Path to file.

  • format (str) – Format of file. Valid options are msgpack or json.

Return type

program

save

migraphx.save(p, filename, format='msgpack')

Save a MIGraphX program

Parameters
  • p (program) – Program to save.

  • filename (str) – Path to file.

  • format (str) – Format of file. Valid options are msgpack or json.