Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
f71251fd
MegEngine
项目概览
MegEngine 天元
/
MegEngine
接近 2 年 前同步成功
通知
414
Star
4708
Fork
583
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MegEngine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
f71251fd
编写于
4月 21, 2020
作者:
M
Megvii Engine Team
提交者:
Xinran Xu
5月 06, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
docs(mge/functional): refine the docstring of several apis
GitOrigin-RevId: 55f61be2a8e215cb1bb9c0f3938408c4e189aa52
上级
0ba52ad7
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
42 addition
and
33 deletion
+42
-33
python_module/megengine/functional/graph.py
python_module/megengine/functional/graph.py
+9
-7
python_module/megengine/functional/math.py
python_module/megengine/functional/math.py
+5
-5
python_module/megengine/functional/nn.py
python_module/megengine/functional/nn.py
+21
-13
python_module/megengine/functional/tensor.py
python_module/megengine/functional/tensor.py
+3
-4
python_module/megengine/functional/utils.py
python_module/megengine/functional/utils.py
+4
-4
未找到文件。
python_module/megengine/functional/graph.py
浏览文件 @
f71251fd
...
@@ -24,17 +24,19 @@ def grad(
...
@@ -24,17 +24,19 @@ def grad(
use_virtual_grad
:
bool
=
None
,
use_virtual_grad
:
bool
=
None
,
return_zero_for_nodep
:
bool
=
True
,
return_zero_for_nodep
:
bool
=
True
,
)
->
Union
[
Tensor
,
Iterable
[
Optional
[
Tensor
]],
None
]:
)
->
Union
[
Tensor
,
Iterable
[
Optional
[
Tensor
]],
None
]:
r
"""
compute symbolic grad
r
"""
Compute the symbolic gradient of ``target`` with repect to ``wrt``.
:param target: grad target var
``wrt`` can either be a single tensor or a sequence of tensors.
:param wrt: with respect to which to compute the grad
:param target: ``grad`` target tensor
:param wrt: with respect to which to compute the gradient
:param warn_mid_wrt: whether to give warning if ``wrt`` is not endpoint
:param warn_mid_wrt: whether to give warning if ``wrt`` is not endpoint
:param use_virtual_grad: whether to use virtual
grad
opr, so fwd graph can
:param use_virtual_grad: whether to use virtual
``grad``
opr, so fwd graph can
be optimized before applying
grad
; if ``None`` is given, then virtual
be optimized before applying
``grad``
; if ``None`` is given, then virtual
grad
would be used if ``graph_opt_level >= 2``
``grad``
would be used if ``graph_opt_level >= 2``
:param return_zero_for_nodep: if ``target`` does not depend on ``wrt``, set to True to return
:param return_zero_for_nodep: if ``target`` does not depend on ``wrt``, set to True to return
a zero-valued :class:`~.Tensor` rather than ``None``; can't be set to False when using
a zero-valued :class:`~.Tensor` rather than ``None``; can't be set to False when using
virtual
grad
opr.
virtual
``grad``
opr.
:return: :math:`\partial\text{target} / \partial\text{wrt}`
:return: :math:`\partial\text{target} / \partial\text{wrt}`
"""
"""
if
not
isinstance
(
wrt
,
mgb
.
SymbolVar
):
if
not
isinstance
(
wrt
,
mgb
.
SymbolVar
):
...
...
python_module/megengine/functional/math.py
浏览文件 @
f71251fd
...
@@ -48,12 +48,12 @@ def sum(inp: Tensor, axis: Optional[int] = None, keepdims: bool = False) -> Tens
...
@@ -48,12 +48,12 @@ def sum(inp: Tensor, axis: Optional[int] = None, keepdims: bool = False) -> Tens
@
wrap_io_tensor
@
wrap_io_tensor
def
prod
(
inp
:
Tensor
,
axis
:
Optional
[
int
]
=
None
,
keepdims
=
False
)
->
Tensor
:
def
prod
(
inp
:
Tensor
,
axis
:
Optional
[
int
]
=
None
,
keepdims
=
False
)
->
Tensor
:
r
"""
r
"""
Returns
prod
of input tensor along given *axis*.
Returns
the element product
of input tensor along given *axis*.
:param inp: The input tensor
:param inp: The input tensor
:param axis: The dimension to reduce. If None, all the dimensions will be reduced. Default: ``None``
:param axis: The dimension to reduce. If None, all the dimensions will be reduced. Default: ``None``
:param keepdims: Whether the output tensor has *axis* retained or not. Default: ``False``
:param keepdims: Whether the output tensor has *axis* retained or not. Default: ``False``
:return: The output tensor
:return: The output tensor
Examples:
Examples:
...
...
python_module/megengine/functional/nn.py
浏览文件 @
f71251fd
...
@@ -27,6 +27,11 @@ def linear(inp: Tensor, weight: Tensor, bias: Optional[Tensor] = None) -> Tensor
...
@@ -27,6 +27,11 @@ def linear(inp: Tensor, weight: Tensor, bias: Optional[Tensor] = None) -> Tensor
"""Applies a linear transformation to the input.
"""Applies a linear transformation to the input.
Refer to :class:`~.Linear` for more information.
Refer to :class:`~.Linear` for more information.
:param inp: the input tensor with shape `(N, in_features)`.
:param weight: the weight with shape `(out_features, in_features)`.
:param bias: the bias with shape `(out_features,)`.
Default: ``None``
"""
"""
orig_shape
=
inp
.
shape
orig_shape
=
inp
.
shape
inp
=
inp
.
reshape
(
-
1
,
orig_shape
[
-
1
])
inp
=
inp
.
reshape
(
-
1
,
orig_shape
[
-
1
])
...
@@ -51,6 +56,8 @@ def conv2d(
...
@@ -51,6 +56,8 @@ def conv2d(
)
->
Tensor
:
)
->
Tensor
:
"""2D convolution operation.
"""2D convolution operation.
Refer to :class:`~.Conv2d` for more information.
:param inp: The feature map of the convolution operation
:param inp: The feature map of the convolution operation
:param weight: The convolution kernel
:param weight: The convolution kernel
:param bias: The bias added to the result of convolution (if given)
:param bias: The bias added to the result of convolution (if given)
...
@@ -73,7 +80,6 @@ def conv2d(
...
@@ -73,7 +80,6 @@ def conv2d(
Float32 would be used for accumulator and intermediate result, but only
Float32 would be used for accumulator and intermediate result, but only
effective when input and output are of Float16 dtype.
effective when input and output are of Float16 dtype.
Refer to :class:`~.Conv2d` for more information.
"""
"""
ph
,
pw
=
_pair
(
padding
)
ph
,
pw
=
_pair
(
padding
)
sh
,
sw
=
_pair_nonzero
(
stride
)
sh
,
sw
=
_pair_nonzero
(
stride
)
...
@@ -114,6 +120,8 @@ def conv_transpose2d(
...
@@ -114,6 +120,8 @@ def conv_transpose2d(
)
->
Tensor
:
)
->
Tensor
:
"""2D transposed convolution operation.
"""2D transposed convolution operation.
Refer to :class:`~.ConvTranspose2d` for more information.
:param inp: The feature map of the convolution operation
:param inp: The feature map of the convolution operation
:param weight: The convolution kernel
:param weight: The convolution kernel
:param bias: The bias added to the result of convolution (if given)
:param bias: The bias added to the result of convolution (if given)
...
@@ -136,7 +144,6 @@ def conv_transpose2d(
...
@@ -136,7 +144,6 @@ def conv_transpose2d(
Float32 would be used for accumulator and intermediate result, but only
Float32 would be used for accumulator and intermediate result, but only
effective when input and output are of Float16 dtype.
effective when input and output are of Float16 dtype.
Refer to :class:`~.ConvTranspose2d` for more information.
"""
"""
ph
,
pw
=
_pair
(
padding
)
ph
,
pw
=
_pair
(
padding
)
sh
,
sw
=
_pair_nonzero
(
stride
)
sh
,
sw
=
_pair_nonzero
(
stride
)
...
@@ -172,13 +179,14 @@ def max_pool2d(
...
@@ -172,13 +179,14 @@ def max_pool2d(
)
->
Tensor
:
)
->
Tensor
:
"""Applies a 2D max pooling over an input.
"""Applies a 2D max pooling over an input.
Refer to :class:`~.MaxPool2d` for more information.
:param inp: The input tensor.
:param inp: The input tensor.
:param kernel_size: The size of the window.
:param kernel_size: The size of the window.
:param stride: The stride of the window. If not provided, its value is set to ``kernel_size``.
:param stride: The stride of the window. If not provided, its value is set to ``kernel_size``.
Default: None
Default: None
:param padding: Implicit zero padding to be added on both sides. Default: 0
:param padding: Implicit zero padding to be added on both sides. Default: 0
Refer to :class:`~.MaxPool2d` for more information.
"""
"""
kh
,
kw
=
_pair_nonzero
(
kernel_size
)
kh
,
kw
=
_pair_nonzero
(
kernel_size
)
...
@@ -207,13 +215,14 @@ def avg_pool2d(
...
@@ -207,13 +215,14 @@ def avg_pool2d(
)
->
Tensor
:
)
->
Tensor
:
""" Applies a 2D average pooling over an input.
""" Applies a 2D average pooling over an input.
Refer to :class:`~.AvgPool2d` for more information.
:param inp: The input tensor.
:param inp: The input tensor.
:param kernel_size: The size of the window.
:param kernel_size: The size of the window.
:param stride: The stride of the window. If not provided, its value is set to ``kernel_size``.
:param stride: The stride of the window. If not provided, its value is set to ``kernel_size``.
Default: None
Default: None
:param padding: Implicit zero padding to be added on both sides. Default: 0
:param padding: Implicit zero padding to be added on both sides. Default: 0
Refer to :class:`~.AvgPool2d` for more information.
"""
"""
kh
,
kw
=
_pair_nonzero
(
kernel_size
)
kh
,
kw
=
_pair_nonzero
(
kernel_size
)
sh
,
sw
=
_pair_nonzero
(
stride
or
kernel_size
)
sh
,
sw
=
_pair_nonzero
(
stride
or
kernel_size
)
...
@@ -343,6 +352,8 @@ def batch_norm2d(
...
@@ -343,6 +352,8 @@ def batch_norm2d(
)
->
Tensor
:
)
->
Tensor
:
"""Applies batch normalization to the input.
"""Applies batch normalization to the input.
Refer to :class:`~.BatchNorm2d` and :class:`~.BatchNorm1d` for more information.
:param inp: input tensor.
:param inp: input tensor.
:param running_mean: tensor to store running mean.
:param running_mean: tensor to store running mean.
:param running_var: tensor to store running variance.
:param running_var: tensor to store running variance.
...
@@ -358,7 +369,6 @@ def batch_norm2d(
...
@@ -358,7 +369,6 @@ def batch_norm2d(
:param eps: a value added to the denominator for numerical stability.
:param eps: a value added to the denominator for numerical stability.
Default: 1e-5.
Default: 1e-5.
Refer to :class:`~.BatchNorm2d` and :class:`~.BatchNorm1d` for more information.
"""
"""
inp
=
mgb
.
opr
.
mark_no_broadcast_elemwise
(
inp
)
inp
=
mgb
.
opr
.
mark_no_broadcast_elemwise
(
inp
)
...
@@ -539,10 +549,10 @@ def eye(
...
@@ -539,10 +549,10 @@ def eye(
Fills the 2-dimensional input :class:`SymbolVar` with the identity matrix.
Fills the 2-dimensional input :class:`SymbolVar` with the identity matrix.
:param n: The number of rows
:param n: The number of rows
:param m: The number of columns
, default to
None
:param m: The number of columns
. Default:
None
:param dtype: The data type
, default to
None
:param dtype: The data type
. Default:
None
:param device: Compute node of the matrix
, defaults to
None
:param device: Compute node of the matrix
. Default:
None
:param comp_graph: Compute graph of the matrix
, defaults to
None
:param comp_graph: Compute graph of the matrix
. Default:
None
:return: The eye matrix
:return: The eye matrix
Examples:
Examples:
...
@@ -669,9 +679,7 @@ def interpolate(
...
@@ -669,9 +679,7 @@ def interpolate(
:param size: size of the output tensor. Default: ``None``
:param size: size of the output tensor. Default: ``None``
:param scale_factor: scaling factor of the output tensor. Default: ``None``
:param scale_factor: scaling factor of the output tensor. Default: ``None``
:param mode: interpolation methods, acceptable values are:
:param mode: interpolation methods, acceptable values are:
'bilinear'(default), 'linear', 'nearest' (todo), 'cubic' (todo), 'area' (todo)
'BILINEAR', 'LINEAR'. Default: ``BILINEAR``
Examples:
Examples:
...
@@ -701,7 +709,7 @@ def interpolate(
...
@@ -701,7 +709,7 @@ def interpolate(
"""
"""
mode
=
mode
.
upper
()
mode
=
mode
.
upper
()
if
mode
not
in
[
"BILINEAR"
,
"LINEAR"
]:
if
mode
not
in
[
"BILINEAR"
,
"LINEAR"
]:
raise
ValueError
(
"interpolate only support bilinear mode"
)
raise
ValueError
(
"interpolate only support
linear or
bilinear mode"
)
if
mode
not
in
[
"BILINEAR"
,
"LINEAR"
]:
if
mode
not
in
[
"BILINEAR"
,
"LINEAR"
]:
if
align_corners
is
not
None
:
if
align_corners
is
not
None
:
raise
ValueError
(
raise
ValueError
(
...
...
python_module/megengine/functional/tensor.py
浏览文件 @
f71251fd
...
@@ -179,10 +179,9 @@ def concat(
...
@@ -179,10 +179,9 @@ def concat(
Concat some tensors
Concat some tensors
:param inps: Input tensors to concat
:param inps: Input tensors to concat
:param axis: the dimension over which the tensors are concatenated,
:param axis: the dimension over which the tensors are concatenated. Default: 0
default to 0
:param device: The comp node output on. Default: None
:param device: The comp node output on, default to None
:param comp_graph: The graph in which output is. Default: None
:param comp_graph: The graph in which output is, default to None
:return: The output tensor
:return: The output tensor
Examples:
Examples:
...
...
python_module/megengine/functional/utils.py
浏览文件 @
f71251fd
...
@@ -23,10 +23,10 @@ def _decide_comp_node_and_comp_graph(*args: mgb.SymbolVar):
...
@@ -23,10 +23,10 @@ def _decide_comp_node_and_comp_graph(*args: mgb.SymbolVar):
return
_use_default_if_none
(
None
,
None
)
return
_use_default_if_none
(
None
,
None
)
def
accuracy
(
logits
:
Tensor
,
target
:
Tensor
,
topk
:
Union
[
int
,
Iterable
[
int
]]
=
1
):
def
accuracy
(
r
"""
logits
:
Tensor
,
target
:
Tensor
,
topk
:
Union
[
int
,
Iterable
[
int
]]
=
1
Classification accuracy given model predictions and ground-truth labels,
)
->
Union
[
Tensor
,
Iterable
[
Tensor
]]:
r
esult between 0. to 1
.
r
"""Calculate the classification accuracy given predicted logits and ground-truth labels
.
:param logits: Model predictions of shape [batch_size, num_classes],
:param logits: Model predictions of shape [batch_size, num_classes],
representing the probability (likelyhood) of each class.
representing the probability (likelyhood) of each class.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录