megengine package

megengine.device

class megengine.device.DeviceType

Bases: pybind11_builtins.pybind11_object

Members:

UNSPEC

CUDA

CPU

MULTITHREAD

MAX_DEVICE_ID

CPU = DeviceType.CPU
CUDA = DeviceType.CUDA
MAX_DEVICE_ID = DeviceType.MAX_DEVICE_ID
MULTITHREAD = DeviceType.MULTITHREAD
UNSPEC = DeviceType.UNSPEC
__eq__(self: object, arg0: object) → bool
__getstate__(self: object) → int
__hash__(self: object) → int
__init__(self: megengine.core._imperative_rt.common.DeviceType, arg0: int) → None
__int__(self: megengine.core._imperative_rt.common.DeviceType) → int
__members__ = {'CPU': DeviceType.CPU, 'CUDA': DeviceType.CUDA, 'MAX_DEVICE_ID': DeviceType.MAX_DEVICE_ID, 'MULTITHREAD': DeviceType.MULTITHREAD, 'UNSPEC': DeviceType.UNSPEC}
__ne__(self: object, arg0: object) → bool
__repr__(self: handle) → str
__setstate__(self: megengine.core._imperative_rt.common.DeviceType, arg0: int) → None
property name
megengine.device.get_default_device()[source]

Gets default computing node.

It returns the value set by set_default_device().

Return type

str

megengine.device.get_device_count(device_type)[source]

Gets number of devices installed on this system.

Parameters

device_type (str) – device type, one of ‘gpu’ or ‘cpu’

Return type

int

megengine.device.get_mem_status_bytes(device=None)[source]

Get total and free memory on the computing device in bytes.

megengine.device.is_cuda_available()[source]

Returns whether cuda device is available on this system.

Return type

bool

megengine.device.set_default_device(device='xpux')[source]

Sets default computing node.

Parameters

device (str) –

default device type. The type can be ‘cpu0’, ‘cpu1’, etc., or ‘gpu0’, ‘gpu1’, etc., to specify the particular cpu or gpu to use. ‘cpux’ and ‘gpux’ can also be used to specify any number of cpu or gpu devices.

’multithread’ device type is avaliable when inference, which implements multi-threading parallelism at the operator level. For example, ‘multithread4’ will compute with 4 threads.

The default value is ‘xpux’ to specify any device available. The priority of using gpu is higher when both gpu and cpu are available.

It can also be set by environment variable MGE_DEFAULT_DEVICE.

megengine.device.set_prealloc_config(alignment=1, min_req=33554432, max_overhead=0, growth_factor=2.0, device_type=DeviceType.CUDA)[source]

Specifies how to pre-allocate from raw device allocator.

Parameters
  • alignment (int) – specifies the alignment in bytes.

  • min_req (int) – min request size in bytes.

  • max_overhead (int) – max overhead above required size in bytes.

  • growth_factorrequest size / cur allocated

  • device_type – the device type

megengine.logger

class megengine.logger.MegBrainLogFormatter(fmt=None, datefmt=None, style='%')[source]

Bases: megengine.logger.MegEngineLogFormatter

date = '%(asctime)s[mgb] '
class megengine.logger.MegEngineLogFormatter(fmt=None, datefmt=None, style='%')[source]

Bases: logging.Formatter

date = '%(asctime)s '
date_full = '[%(asctime)s %(lineno)d@%(filename)s:%(name)s] '
format(record)[source]

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

log_fout = None
max_lines = 256
msg = '%(message)s'
megengine.logger.enable_debug_log()[source]

Sets logging level to debug for all components.

megengine.logger.get_logger(name=None, formatter=<class 'megengine.logger.MegEngineLogFormatter'>)[source]

Gets megengine logger with given name.

megengine.logger.replace_mgb_log_level(level)[source]

Replaces megbrain log level in a block and restore after exiting.

Parameters

level (int e.g. logging.INFO) – new log level

megengine.logger.set_log_file(fout, mode='a')[source]

Sets log output file.

Parameters
  • fout (str or file-like) – file-like object that supports write and flush, or string for the filename

  • mode (str) – specify the mode to open log file if fout is a string

megengine.logger.set_log_level(level, update_existing=True)[source]

Sets default logging level.

Parameters
  • level (int e.g. logging.INFO) – loggin level given by python logging module

  • update_existing – whether to update existing loggers

megengine.logger.set_mgb_log_level(level)[source]

Sets megbrain log level

Parameters

level (int e.g. logging.INFO) – new log level

Returns

original log level

megengine.serialization

class megengine.serialization.dmap(map_location)[source]

Bases: object

megengine.serialization.load(f, map_location=None, pickle_module=<module 'pickle' from '/usr/lib/python3.6/pickle.py'>)[source]

Load an object saved with save() from a file.

Parameters
  • f (text file object) – a string of file name or a text file object from which to load.

  • map_location (str, dict or a function specifying the map rules) – Default: None.

Note

map_location defines device mapping. See examples for usage.

Parameters

pickle_module – Default: pickle.

Note

If you will call mge.set_default_device(), please do it before mge.load().

Examples:

megengine.serialization.save(obj, f, pickle_module=<module 'pickle' from '/usr/lib/python3.6/pickle.py'>, pickle_protocol=4)[source]

Save an object to disk file.

Parameters
  • obj (object) – object to save. Only module or state_dict are allowed.

  • f (text file object) – a string of file name or a text file object to which obj is saved to.

  • pickle_module – Default: pickle.

  • pickle_protocol – Default: pickle.HIGHEST_PROTOCOL.

megengine.tensor

class megengine.tensor.Parameter(data, dtype=None, device=None, is_const=False, no_cache=False)[source]

Bases: megengine.tensor.Tensor

A kind of Tensor that is to be considered a module parameter.

class megengine.tensor.Tensor(data, dtype=None, device=None, is_const=False, no_cache=False)[source]

Bases: Tensor, megengine.core.tensor.array_method.ArrayMethodMixin

__getnewargs__()[source]

__getnewargs__ will be called for pickle serialization or deep copy

__getstate__()[source]

__getstate__ will be called for pickle serialization or deep copy

dmap_callback = None
grad = None
q_dict = {'mode': None, 'scale': None, 'zero_point': None}
property requires_grad
reset_zero()[source]

Deprecated since version 1.0.

use *= 0 instead

set_value(value)[source]

Deprecated since version 1.0.

no need to reuse an existing tensor since 1.0

property shape
to(device)[source]
megengine.tensor.apply()
megengine.tensor.tensor

alias of megengine.tensor.Tensor

megengine.version