megengine¶
import megengine as mge # NOT as torch - Even if we look like twins.
Note
MGE
或 mge
是 MegEngine
的官方缩写,我们建议相关衍生库将其作为前缀。
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
更加相似,
即张量是一类多维数组,其中每个元素的数据类型和空间大小一致,而数据值可以不同。
A tensor object represents a multidimensional, homogeneous array of fixed-size items. |
|
A kind of Tensor that is to be considered a module parameter. |
上面 Parameter 可以被看作是一种特殊的 Tensor, 通常用来表示神经网络中的参数。
想要了解更多,请参考 Deep understanding of Tensor data structure 。
Serialization¶
Save an object to disk file. |
|
Load an object saved with |
Device¶
Return the precise device type like |
|
Returns whether cuda device is available on this system. |
|
Returns whether atlas device is available on this system. |
|
Returns whether cambricon device is available on this system. |
|
Returns whether rocm device is available on this system. |
|
Gets number of devices installed on this system. |
|
Gets default computing node. |
|
Sets default computing node. |
|
Get total and free memory on the computing device in bytes. |
|
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. |
|
Specifies how to pre-allocate from raw device allocator. |
|
This function will try it best to free all consecutive free chunks back to operating system, small pieces may not be returned. |
|
Gets the CUDA version used when compiling MegEngine. |
|
Get the Cudnn version used when compiling MegEngine. |
|
Get the TensorRT version used when compiling MegEngine. |
Logger¶
Sets logging level to debug for all components. |
|
Gets megengine logger with given name. |
|
Sets log output file. |
|
Sets default logging level. |
Version¶
- __version__ (MegEngine 版本号)¶