megengine¶
import megengine as mge # NOT as torch - Even if we look like twins.
注解
MGE
或 mge
是 MegEngine
的官方缩写,我们建议相关衍生库将其作为前缀。
警告
不要尝试 [ 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
更加相似,
即张量是一类多维数组,其中每个元素的数据类型和空间大小一致,而数据值可以不同。
一个张量对象表示固定大小元素的多维同构数组。 |
|
一类表示模块参数的张量。 |
上面 Parameter 可以被看作是一种特殊的 Tensor, 通常用来表示神经网络中的参数。
想要了解更多,请参考 深入理解 Tensor 数据结构 。
Device¶
cuda设备是否在当前机器可用。 |
|
获取当前系统中的设备数量。 |
|
查询默认的计算结点。 |
|
设置默认的计算节点。 |
|
以字节为单位获取计算设备上的总内存和可用内存。 |
|
Gets compute capability of the specified device. |
|
Returns the current memory occupied by tensors on the computing device in bytes. |
|
Returns the current memory managed by the caching allocator on the computing device in bytes. |
|
Returns the maximum memory managed by the caching allocator on the computing device in bytes. |
|
Returns the maximum memory occupied by tensors on the computing device in bytes. |
|
Resets the maximum stats on the computing device. |
|
对原始设备的内存分配器指定预先分配的方案。 |
|
这个函数会尽量将所有连续的空闲块释放回操作系统,小块可能不会被返回。 |
Logger¶
设置日志记录级别(logging level)以调试所有组件。 |
|
按照给定名称获取megengine日志。 |
|
设置日志的输出文件。 |
|
设置默认的日志记录级别。 |