megengine#

import megengine as mge  # NOT as torch - Even if we look like twins.

Note

MGEmgeMegEngine 的官方缩写,我们建议相关衍生库将其作为前缀。

Warning

不要尝试 [ import megengine as torch ] 这是行不通的! ( /ω\)

  • MegEngine 的部分 API 设计借鉴了 PyTorch, 我们相信这对开发者而言会更加友好;

  • 但二者的底层设计完全不同,MegEngine is just MegEngine.

Tensor#

from megengine import Tensor
from megengine import tensor  # tensor is an alias of Tensor

MegEngine 中提供了一种名为 “张量” (Tensor )的数据结构, 区别于物理学中的定义,其概念与 NumPy 中的 ndarray 更加相似, 即张量是一类多维数组,其中每个元素的数据类型和空间大小一致,而数据值可以不同。

Tensor

A tensor object represents a multidimensional, homogeneous array of fixed-size items.

Parameter

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

上面 Parameter 可以被看作是一种特殊的 Tensor, 通常用来表示神经网络中的参数。

想要了解更多,请参考 Deep understanding of Tensor data structure

Serialization#

save

Save an object to disk file.

load

Load an object saved with save from a file.

Device#

device.what_is_xpu

Return the precise device type like cpu, cuda and so on.

is_cuda_available

Returns whether cuda device is available on this system.

is_atlas_available

Returns whether atlas device is available on this system.

is_cambricon_available

Returns whether cambricon device is available on this system.

is_rocm_available

Returns whether rocm device is available on this system.

get_device_count

Gets number of devices installed on this system.

get_default_device

Gets default computing node.

set_default_device

Sets default computing node.

get_mem_status_bytes

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

get_cuda_device_property

get_cuda_compute_capability

Gets compute capability of the specified device.

get_allocated_memory

Returns the current memory occupied by tensors on the computing device in bytes.

get_reserved_memory

Returns the current memory managed by the caching allocator on the computing device in bytes.

get_max_reserved_memory

Returns the maximum memory managed by the caching allocator on the computing device in bytes.

get_max_allocated_memory

Returns the maximum memory occupied by tensors on the computing device in bytes.

reset_max_memory_stats

Resets the maximum stats on the computing device.

set_prealloc_config

Specifies how to pre-allocate from raw device allocator.

coalesce_free_memory

This function will try it best to free all consecutive free chunks back to operating system, small pieces may not be returned.

get_cuda_version

Gets the CUDA version used when compiling MegEngine.

get_cudnn_version

Get the Cudnn version used when compiling MegEngine.

get_tensorrt_version

Get the TensorRT version used when compiling MegEngine.

Logger#

enable_debug_log

Sets logging level to debug for all components.

get_logger

Gets megengine logger with given name.

set_log_file

Sets log output file.

set_log_level

Sets default logging level.

Version#

__version__ (MegEngine 版本号)#