MRT V3 API¶
Contents
mrt.V3.utils¶
Utility Module for MRT V3.
Collector of utility functions including YAML configuration node manipulating functions, MRT stage helper functions. Default YAML configurations for MRT Common Stage options and Command line help prompt are also included.
- mrt.V3.utils.get_model_prefix(model_dir, model_name)¶
Get the prefix of the pre-trained MRT model name.
- Parameters
model_dir (str) – Directory of the model file.
model_name (str) – Name of the MRT pre-trained model.
- Returns
model_prefix – Prefix of the pre-trained MRT model name.
- Return type
str
- mrt.V3.utils.get_logger(verbosity)¶
Get the console logger
- Parameters
verbosity (str) – verbosity level chosen from debug, info, warning, error, fatal.
- Returns
logger – Console logger.
- Return type
logging.RootLogger
- mrt.V3.utils.set_batch(input_shape, batch)¶
Get the input shape with respect to a specified batch value and an original input shape.
- Parameters
input_shape (tuple) – The input shape with batch axis unset.
batch (int) – The batch value.
- Returns
ishape – The input shape with the value of batch axis equal to batch.
- Return type
tuple
- mrt.V3.utils.load_fname(prefix, suffix=None, with_ext=False)¶
Get the model files at a given stage.
- Parameters
prefix (string) – The file path without and extension.
suffix (string) – The file suffix with respect to a given stage of MRT.
with_ext (bool) – Whether to include ext file.
- Returns
files – The loaded file names.
- Return type
tuple of string
- mrt.V3.utils.save_conf(fname, logger=<RootLogger root (WARN)>, **conf_map)¶
Save the JSON-formatted MRT configuration from configuration checkpoint file.
- Parameters
fname (str) – Path of the JSON-formatted MRT configuration checkpoint file.
logger (logging.RootLogger) – Console logger.
conf_map (dict) – Dictionary of the attribute-value pairs.
- mrt.V3.utils.load_conf(fname, logger=<RootLogger root (WARN)>)¶
Load the JSON-formatted MRT configuration from configuration checkpoint file.
- Parameters
fname (str) – Path of the JSON-formatted MRT configuration checkpoint file.
logger (logging.RootLogger) – Console logger.
- Returns
conf_map – Dictionary of the attribute-value pairs.
- Return type
dict
- mrt.V3.utils.check_file_existance(*fpaths, logger=<RootLogger root (WARN)>)¶
Check the existance of the listed file paths.
- Parameters
fpaths (list of str) – List of paths to be checked.
logger (logging.RootLogger) – Console logger.
- mrt.V3.utils.get_ctx(device_type, device_ids, dctx=cpu(0))¶
Get the context instance of mxnet
- Parameters
device_type (str) – context type string chosen from cpu or gpu.
device_ids (list) – list of context ids
dctx (mx.context.Context) – default context
- Returns
context – The created context with respect to the device_type and device_ids.
- Return type
mx.context.Context
- mrt.V3.utils.get_batch_axis(input_shape)¶
Get the batch axis entry of an input shape.
- Parameters
input_shape (tuple) – The data shape related to dataset.
- Returns
axis – The batch axis entry of an input shape.
- Return type
int
- mrt.V3.utils.get_cfg_defaults()¶
Get a yacs CfgNode object with default values for MRT.
- Returns
cfg – CfgNode represents an internal node in the configuration tree. It’s a simple dict-like container that allows for attribute-based access to keys.
- Return type
yacs.config.CfgNode
- mrt.V3.utils.merge_cfg(yaml_file)¶
Override the default YAML configuration node with the provided YAML-formatted configuration file.
- Parameters
yaml_file (str) – Path of the YAML-formatted configuration file.
- Returns
cfg – CfgNode represents an internal node in the configuration tree. It’s a simple dict-like container that allows for attribute-based access to keys.
- Return type
yacs.config.CfgNode
- mrt.V3.utils.revise_cfg(cfg, stage, attr, value)¶
Revise MRT YAML configuration node with respect to the specified stage and attribute name into the provided value.
- Parameters
cfg (yacs.config.CfgNode) – CfgNode represents an internal node in the configuration tree. It’s a simple dict-like container that allows for attribute-based access to keys.
stage (str) – Stage name chosen from common, prepare, calibrate, quantize, evaluate or compile.
attr (str) – Attribute name attribute to the provided stage.
value (int, float, str, list, tuple, bool or NoneType) – The revision value to be applied, type of value should be supported by yacs.config.CfgNode
- mrt.V3.utils.override_cfg_args(cfg, mrt_argv)¶
Override YAML configuration node with command line optional arguments for the simplicity of MRT configuration revision.
- Parameters
cfg (yacs.config.CfgNode) – CfgNode represents an internal node in the configuration tree. It’s a simple dict-like container that allows for attribute-based access to keys.
mrt_argv (list) – list of even length which can be resoluted as key value pairs, the key could be split into stage name and attribute name.
- Returns
cfg – Overridden YAML configuration node.
- Return type
yacs.config.CfgNode
mrt.V3.prepare¶
Preparation Module for MRT V3.
Prepare function definition, default YAML configurations for MRT preparation Stage options and Command line help prompt are also included.
- mrt.V3.prepare.prepare(cm_cfg, pass_cfg, logger=None)¶
YAML configuration API of MRT preparation stage.
- Parameters
cm_cfg (yacs.config.CfgNode) – CfgNode of common stage.
pass_cfg (yacs.config.CfgNode) – CfgNode of preparation stage.
logger (logging.RootLogger) – Console logger.
mrt.V3.calibrate¶
Calibration Module for MRT V3.
Calibration function definition, default YAML configurations for MRT calibration Stage options and Command line help prompt are also included.
- mrt.V3.calibrate.calibrate(cm_cfg, pass_cfg, logger=None)¶
YAML configuration API of MRT calibration stage.
- Parameters
cm_cfg (yacs.config.CfgNode) – CfgNode of common stage.
pass_cfg (yacs.config.CfgNode) – CfgNode of calibration stage.
logger (logging.RootLogger) – Console logger.
mrt.V3.quantize¶
Quantization Module for MRT V3.
Quantize function definition, default YAML configurations for MRT quantization Stage options and Command line help prompt are also included.
- mrt.V3.quantize.quantize(cm_cfg, pass_cfg, logger=None)¶
YAML configuration API of MRT quantization stage.
- Parameters
cm_cfg (yacs.config.CfgNode) – CfgNode of common stage.
pass_cfg (yacs.config.CfgNode) – CfgNode of evaluation stage.
logger (logging.RootLogger) – Console logger.
mrt.V3.evaluate¶
Evaluation Module for MRT V3.
Evaluate function definition, default YAML configurations for MRT evaluation Stage options and Command line help prompt are also included.
- mrt.V3.evaluate.forward(net, data, ctx, baxis, olen)¶
Multiple xpu run support.
- Parameters
net (mxnet.gluon.block.SymbolBlock) – Graph for inference.
data (mxnet.ndarray.ndarray.NDArray) – Input data to pass into the graph.
ctx (mx.context.Context) – Context for inference.
baxis (int) – Axis id of batch dimension.
olen (int) – Length of the output.
- Returns
outs – inference result of the graph with respect to the given input data, for multiple outputs, outs will be a list the entry type of which is mxnet.ndarray.ndarray.NDArray.
- Return type
mxnet.ndarray.ndarray.NDArray or list
- mrt.V3.evaluate.get_evaluation_info(cm_cfg, pass_cfg, logger=None)¶
YAML configuration API to get evaluation function, quantization function and dataset iteration function
- Parameters
cm_cfg (yacs.config.CfgNode) – CfgNode of common stage.
pass_cfg (yacs.config.CfgNode) – CfgNode of calibration stage.
logger (logging.RootLogger) – Console logger.
- mrt.V3.evaluate.evaluate(cm_cfg, pass_cfg, logger=None)¶
YAML configuration API of MRT evaluation stage.
- Parameters
cm_cfg (yacs.config.CfgNode) – CfgNode of common stage.
pass_cfg (yacs.config.CfgNode) – CfgNode of calibration stage.
logger (logging.RootLogger) – Console logger.
- mrt.V3.evaluate.get_ctx_eval(ctx)¶
Get the context instance for evaluation stage
- Parameters
ctx (mx.context.Context) – The input context.
- Returns
ctx – The modified context.
- Return type
mx.context.Context
- mrt.V3.evaluate.inference_original_model(symbol_file, params_file, data, batch_axis=0, device_type=None, device_ids=None)¶
MRT Inference API for original model.
- Parameters
symbol_file (str) – Path to the quantized mxnet symbol JSON file.
params_file (str) – Path to the quantized mxnet parameters file.
data (mxnet.ndarray.ndarray.NDArray) – Input data to pass into the graph.
batch_axis (int) – Axis id of batch dimension.
device_type (str) – Context type string chosen from cpu or gpu.
device_ids (list) – List of context ids.
- Returns
outs – inference result of the graph with respect to the given input data, for multiple outputs, outs will be a list the entry type of which is mxnet.ndarray.ndarray.NDArray.
- Return type
mxnet.ndarray.ndarray.NDArray or list
- mrt.V3.evaluate.inference_quantized_model(qsymbol_file, qparams_file, qext_file, data, batch_axis=0, split=False, device_type=None, device_ids=None)¶
MRT Inference API for quantized model.
- Parameters
qsymbol_file (str) – Path to the quantized mxnet symbol JSON file.
qparams_file (str) – Path to the quantized mxnet parameters file.
qext_file (str) – Path to the quantized extension file which store intermediate results.
data (mxnet.ndarray.ndarray.NDArray) – Input data to pass into the graph.
batch_axis (int) – Axis id of batch dimension.
split (bool) – Flag indicating whether the model is split before quantization.
device_type (str) – Context type string chosen from cpu or gpu.
device_ids (list) – List of context ids.
- Returns
outs – inference result of the graph with respect to the given input data, for multiple outputs, outs will be a list the entry type of which is mxnet.ndarray.ndarray.NDArray.
- Return type
mxnet.ndarray.ndarray.NDArray or list
mrt.V3.mrt_compile¶
Compilation Module for MRT V3.
Compile function definition, default YAML configurations for MRT compilation Stage options and Command line help prompt are also included.
- mrt.V3.mrt_compile.mrt_compile(cm_cfg, pass_cfg, logger=None)¶
YAML configuration API of MRT compilation stage.
- Parameters
cm_cfg (yacs.config.CfgNode) – CfgNode of common stage.
pass_cfg (yacs.config.CfgNode) – CfgNode of compilation stage.
logger (logging.RootLogger) – Console logger.
mrt.V3.execute¶
Execution Module for MRT V3.
Definition of execution functions for either MRT complete process execution or specified stages execution.
- mrt.V3.execute.yaml_main(cfg, logger=None)¶
Execution function to launch the complete MRT process.
- Parameters
cfg (yacs.config.CfgNode) – CfgNode of MRT.
logger (logging.RootLogger) – Console logger.
- mrt.V3.execute.run(cfg, logger=None)¶
Execution function to launch either the complete MRT process or a specified MRT stage.
- Parameters
cfg (yacs.config.CfgNode) – CfgNode of MRT.
logger (logging.RootLogger) – Console logger.