megengine

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

注解

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

警告

不要尝试 [ 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

一个张量对象表示固定大小元素的多维同构数组。

Parameter

一类表示模块参数的张量。

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

想要了解更多,请参考 深入理解 Tensor 数据结构

Serialization

save

把对象保存成磁盘文件。

load

Load an object saved with :func:~.megengine.save` from a file.

Device

is_cuda_available

cuda设备是否在当前机器可用。

get_device_count

获取当前系统中的设备数量。

get_default_device

查询默认的计算结点。

set_default_device

设置默认的计算节点。

get_mem_status_bytes

以字节为单位获取计算设备上的总内存和可用内存。

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

对原始设备的内存分配器指定预先分配的方案。

coalesce_free_memory

这个函数会尽量将所有连续的空闲块释放回操作系统,小块可能不会被返回。

Logger

enable_debug_log

设置日志记录级别(logging level)以调试所有组件。

get_logger

按照给定名称获取megengine日志。

set_log_file

设置日志的输出文件。

set_log_level

设置默认的日志记录级别。

Version

__version__ (MegEngine 版本号)