Python API reference#
2024-05-07
11 min read time
shape#
- class migraphx.shape(type, lens, strides=None, dyn_dims)#
Describes the shape of a tensor. This includes size, layout, and data type. Use dyn_dims for a dynamic shape.
- migraphx.dyn_dims()#
The dynamic dimensions of the shape.
- Return type:
- migraphx.standard()#
Returns true if the shape is a standard shape. That is, the shape is both packed and not transposed.
- Return type:
dynamic_dimension#
- class migraphx.dynamic_dimension(min, max, optimals)#
Constructs a dynamic_dimension from a minimum, a maximum, and optionally a set of optimals.
- migraphx.is_fixed()#
Returns true if the dynamic_dimension is fixed.
:rtype : int
argument#
- class migraphx.argument(data)#
Constructs an argument from a python buffer. This can include numpy arrays.
- migraphx.generate_argument(s, seed=0)#
Generates an argument with random data.
- migraphx.fill_argument(s, value)#
Fills argument of shape s with the given value.
- migraphx.create_argument(s, values)#
Creates an argument of shape s with a set of values.
target#
- class migraphx.target#
This represents the compilation target.
module#
- migraphx.print()#
Prints the contents of the module as list of instructions.
- migraphx.add_instruction(op, args, mod_args=[])#
Adds instruction into the module.
- Parameters:
:rtype instruction
- migraphx.add_literal(data)#
Adds constant or literal data of provided shape into the module from python buffer which includes numpy array.
- Parameters:
data (py::buffer) – Python buffer or numpy array
:rtype instruction
- migraphx.add_parameter(name, shape)#
Adds a parameter to the module with the provided name and shape.
:rtype instruction
program#
- class migraphx.program#
Represents the computation graph to be compiled and run.
- migraphx.get_parameter_names()#
Gets all the input argument’s or parameter’s names to the program as a list.
:rtype list[str]
- migraphx.get_parameter_shapes()#
Gets the shapes of all the input parameters in the program.
- migraphx.get_output_shapes()#
Gets the shapes of the final outputs of the program.
- migraphx.compile(t, offload_copy=True, fast_math=True, exhaustive_tune=False)#
Compiles the program for the target and optimizes it.
- Parameters:
t (target) – Compilation target for the program.
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.
exhaustive_tune – Flag to enable exhaustive search to find the fastest version of generated kernels for selected backend.
- migraphx.get_main_module()#
Gets main module of the program.
:rtype module
- migraphx.create_module(name)#
Creates and adds a module with the provided name into the program.
:param str name : name of the new module. :rtype module
- migraphx.run(params)#
Runs the program.
- migraphx.sort()#
Sorts the modules of the program for the instructions to appear in topologically sorted order.
- migraphx.quantize_fp16(prog, ins_names=['all'])#
Quantizes the program to use fp16.
- migraphx.quantize_int8(prog, t, calibration=[], ins_names=['dot', 'convolution'])#
Quantizes the program to use int8.
op#
parse_onnx#
- migraphx.parse_onnx(filename, default_dim_value=1, map_input_dims={}, skip_unknown_operators=false, print_program_on_error=false, max_loop_iterations=10, limit_max_iterations=65535)#
Loads and parses an ONNX file.
- Parameters:
filename (str) – Path to file.
default_dim_value (str) – default dimension to use (if not specified in onnx file).
default_dyn_dim_value (dynamic_dimension) – default dynamic_dimension value to use.
map_input_dims (str) – Explicitly specify the dims of an input.
map_dyn_input_dims (list[dynamic_dimension]) – Explicitly specify the dynamic_dimensions 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.
max_loop_iterations (int) – Maximum iteration number for the loop operator if trip count is not set.
limit_max_iterations (int) – Maximum iteration limit for the loop operator.
- Return type:
parse_tf#
- migraphx.parse_tf(filename, is_nhwc=True, batch_size=1, map_input_dims=dict(), output_names=[])#
Loads and parses a tensorflow protobuf 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).
map_input_dims (dict[str, list[int]]) – Optional arg to explictly specify dimensions of the inputs.
output_names (list[str]) – Optional argument specify names of the output nodes.
- Return type: