Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
67013463
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
403
Star
4705
Fork
582
代码
文件
提交
分支
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看板
提交
67013463
编写于
10月 13, 2020
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
docs(mge): fix some docstring format problem
GitOrigin-RevId: cbc5ab04b368246f1ae6d9e797703c92f2e524c2
上级
5cc043f0
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
46 addition
and
46 deletion
+46
-46
imperative/python/megengine/autodiff/grad_manager.py
imperative/python/megengine/autodiff/grad_manager.py
+22
-22
imperative/python/megengine/data/dataloader.py
imperative/python/megengine/data/dataloader.py
+0
-1
imperative/python/megengine/functional/__init__.py
imperative/python/megengine/functional/__init__.py
+1
-1
imperative/python/megengine/functional/loss.py
imperative/python/megengine/functional/loss.py
+6
-4
imperative/python/megengine/functional/nn.py
imperative/python/megengine/functional/nn.py
+4
-4
imperative/python/megengine/module/adaptive_pooling.py
imperative/python/megengine/module/adaptive_pooling.py
+8
-8
imperative/python/megengine/module/module.py
imperative/python/megengine/module/module.py
+5
-6
未找到文件。
imperative/python/megengine/autodiff/grad_manager.py
浏览文件 @
67013463
...
...
@@ -20,42 +20,42 @@ class GradManager:
the forward operations start and when all resources should be released. A typical usage of
GradManager is as follows:
.. code-block::
.. code-block::
gm = GradManager()
gm.attach(model.parameters())
with gm:
# forward operations
...
# backward gradients
gm.backward(loss)
gm = GradManager()
gm.attach(model.parameters())
with gm:
# forward operations
...
# backward gradients
gm.backward(loss)
You can also use `
record()` and `release()` method instead of `with
` context:
You can also use `
`record()`` and ``release()`` method instead of ``with`
` context:
.. code-block::
.. code-block::
gm = GradManager()
gm.attach(model.parameters())
gm = GradManager()
gm.attach(model.parameters())
gm.record()
gm.record()
# forward operations
...
# backward gradients
gm.backward(loss)
# forward operations
...
# backward gradients
gm.backward(loss)
gm.release()
gm.release()
Typically, in data parallel, we would like to average the gradients across
processes. Users will finally get the averaged gradients if an "AllReduce"
callback is registered as follows:
.. code-block::
.. code-block::
import megengine.distributed as dist
import megengine.distributed as dist
gm = GradManager()
gm.attach(model.parameters(), callback=dist.make_allreduce_cb("MEAN"))
gm = GradManager()
gm.attach(model.parameters(), callback=dist.make_allreduce_cb("MEAN"))
"""
...
...
imperative/python/megengine/data/dataloader.py
浏览文件 @
67013463
...
...
@@ -50,7 +50,6 @@ class DataLoader:
:param dataset: dataset from which to load the minibatch.
:type sampler: Sampler
:param sampler: defines the strategy to sample data from the dataset.
If specified, :attr:`shuffle` must be ``False``.
:type transform: Transform
:param transform: defined the transforming strategy for a sampled batch.
Default: None
...
...
imperative/python/megengine/functional/__init__.py
浏览文件 @
67013463
...
...
@@ -17,4 +17,4 @@ from . import distributed # isort:skip
# delete namespace
# pylint: disable=undefined-variable
# del elemwise, graph, loss, math, nn, tensor
# type: ignore[name-defined]
del
elemwise
,
graph
,
loss
,
math
,
nn
,
quantized
,
tensor
,
utils
# type: ignore[name-defined]
imperative/python/megengine/functional/loss.py
浏览文件 @
67013463
...
...
@@ -127,9 +127,10 @@ def cross_entropy(
with_logits
:
bool
=
True
,
label_smooth
:
float
=
0
,
)
->
Tensor
:
r
"""Compute the multi-class cross entropy loss (using logits by default).
r
"""Compute
s
the multi-class cross entropy loss (using logits by default).
By default, prediction is assumed to be logits, whose softmax gives probabilities.
By default(``with_logitis`` is True), ``pred`` is assumed to be logits,
class probabilities are given by softmax.
It has better numerical stability compared with sequential calls to :func:`~.softmax` and :func:`~.cross_entropy`.
...
...
@@ -194,9 +195,10 @@ def cross_entropy(
def
binary_cross_entropy
(
pred
:
Tensor
,
label
:
Tensor
,
with_logits
:
bool
=
True
)
->
Tensor
:
r
"""Compute the binary cross entropy loss (using logits by default).
r
"""Compute
s
the binary cross entropy loss (using logits by default).
By default, prediction is assumed to be logits, whose sigmoid gives probabilities.
By default(``with_logitis`` is True), ``pred`` is assumed to be logits,
class probabilities are given by sigmoid.
:param pred: `(N, *)`, where `*` means any number of additional dimensions.
:param label: `(N, *)`, same shape as the input.
...
...
imperative/python/megengine/functional/nn.py
浏览文件 @
67013463
...
...
@@ -335,8 +335,8 @@ def adaptive_max_pool2d(
Refer to :class:`~.MaxAdaptivePool2d` for more information.
:param inp:
The
input tensor.
:param oshp:
(OH, OW)
size of the output shape.
:param inp: input tensor.
:param oshp:
`(OH, OW)`
size of the output shape.
:return: output tensor.
"""
assert
isinstance
(
inp
,
(
Tensor
,
megbrain_graph
.
VarNode
)),
"inp must be Tensor type"
...
...
@@ -356,8 +356,8 @@ def adaptive_avg_pool2d(
Refer to :class:`~.AvgAdaptivePool2d` for more information.
:param inp:
The
input tensor.
:param oshp:
(OH, OW)
size of the output shape.
:param inp: input tensor.
:param oshp:
`(OH, OW)`
size of the output shape.
:return: output tensor.
"""
assert
isinstance
(
inp
,
(
Tensor
,
megbrain_graph
.
VarNode
)),
"inp must be Tensor type"
...
...
imperative/python/megengine/module/adaptive_pooling.py
浏览文件 @
67013463
...
...
@@ -40,10 +40,10 @@ class AdaptiveMaxPool2d(_AdaptivePoolNd):
\text{stride[1]} \times w + n)
\end{aligned}
Kernel_size and stride
can be inferred from input shape and out shape:
padding: (0, 0)
stride: (floor(IH / OH), floor(IW / OW))
kernel_size: (IH - (OH - 1) * stride_h, IW - (OW - 1) * stride_w)
``kernel_size`` and ``stride``
can be inferred from input shape and out shape:
*
padding: (0, 0)
*
stride: (floor(IH / OH), floor(IW / OW))
*
kernel_size: (IH - (OH - 1) * stride_h, IW - (OW - 1) * stride_w)
Examples:
...
...
@@ -83,10 +83,10 @@ class AdaptiveAvgPool2d(_AdaptivePoolNd):
out(N_i, C_j, h, w) = \frac{1}{kH * kW} \sum_{m=0}^{kH-1} \sum_{n=0}^{kW-1}
input(N_i, C_j, stride[0] \times h + m, stride[1] \times w + n)
Kernel_size and stride
can be inferred from input shape and out shape:
padding: (0, 0)
stride: (floor(IH / OH), floor(IW / OW))
kernel_size: (IH - (OH - 1) * stride_h, IW - (OW - 1) * stride_w)
``kernel_size`` and ``stride``
can be inferred from input shape and out shape:
*
padding: (0, 0)
*
stride: (floor(IH / OH), floor(IW / OW))
*
kernel_size: (IH - (OH - 1) * stride_h, IW - (OW - 1) * stride_w)
Examples:
...
...
imperative/python/megengine/module/module.py
浏览文件 @
67013463
...
...
@@ -351,7 +351,7 @@ class Module(metaclass=ABCMeta):
def
replace_param
(
self
,
params
:
dict
,
start_pos
:
int
,
seen
:
Optional
[
Set
[
int
]]
=
None
):
"""Replaces module's parameters with `
params
`, used by :class:`~.ParamPack` to
"""Replaces module's parameters with `
`params`
`, used by :class:`~.ParamPack` to
speedup multimachine training.
"""
offset
=
0
...
...
@@ -411,7 +411,7 @@ class Module(metaclass=ABCMeta):
If ``strict`` is ``True``, the keys of :func:`state_dict` must exactly match the keys
returned by :func:`state_dict`.
Users can also pass a closure: `
Function[key: str, var: Tensor] -> Optional[np.ndarray]
`
Users can also pass a closure: `
`Function[key: str, var: Tensor] -> Optional[np.ndarray]`
`
as a `state_dict`, in order to handle complex situations. For example, load everything
except for the final linear classifier:
...
...
@@ -423,7 +423,7 @@ class Module(metaclass=ABCMeta):
for k, v in state_dict.items()
}, strict=False)
Here returning `
None` means skipping parameter `k
`.
Here returning `
`None`` means skipping parameter ``k`
`.
To prevent shape mismatch (e.g. load PyTorch weights), we can reshape before loading:
...
...
@@ -485,9 +485,8 @@ class Module(metaclass=ABCMeta):
)
def
_load_state_dict_with_closure
(
self
,
closure
):
"""Advance state_dict load through callable `closure` whose signature is
`closure(key: str, var: Tensor) -> Union[np.ndarry, None]`
"""Advance state_dict load through callable ``closure`` whose signature is
``closure(key: str, var: Tensor) -> Union[np.ndarry, None]``
"""
assert
callable
(
closure
),
"closure must be a function"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录