提交 9d439ae6 编写于 作者: M Megvii Engine Team

docs(misc): correct docstring format broadly

GitOrigin-RevId: 45234ca07ed66408d77741de307cc44c59b9f3da
上级 651c4e9a
...@@ -28,6 +28,7 @@ def set_priority_to_id(dest_vars): ...@@ -28,6 +28,7 @@ def set_priority_to_id(dest_vars):
""" """
For all oprs in the subgraph constructed by dest_vars, For all oprs in the subgraph constructed by dest_vars,
sets its priority to id if its original priority is zero. sets its priority to id if its original priority is zero.
:param dest_vars: target vars representing the graph. :param dest_vars: target vars representing the graph.
""" """
dest_vec = [] dest_vec = []
......
...@@ -40,7 +40,7 @@ class Collator: ...@@ -40,7 +40,7 @@ class Collator:
def apply(self, inputs): def apply(self, inputs):
""" """
:param input: sequence_N(tuple(CHW, C, CK)). :param inputs: sequence_N(tuple(CHW, C, CK)).
:return: tuple(NCHW, NC, NCK). :return: tuple(NCHW, NC, NCK).
""" """
elem = inputs[0] elem = inputs[0]
......
...@@ -43,52 +43,43 @@ def raise_timeout_error(): ...@@ -43,52 +43,43 @@ def raise_timeout_error():
class DataLoader: class DataLoader:
r""" r"""Provides a convenient way to iterate on a given dataset.
Provides a convenient way to iterate on a given dataset.
"""
__initialized = False
def __init__( DataLoader combines a dataset with
self, :class:`~.Sampler`, :class:`~.Transform` and :class:`~.Collator`,
dataset: Dataset,
sampler: Sampler = None,
transform: Transform = None,
collator: Collator = None,
num_workers: int = 0,
timeout: int = 0,
timeout_event: Callable = raise_timeout_error,
divide: bool = False,
):
r"""
`DataLoader` combines a dataset with `sampler`, `transform` and `collator`,
make it flexible to get minibatch continually from a dataset. make it flexible to get minibatch continually from a dataset.
:type dataset: Dataset
:param dataset: dataset from which to load the minibatch. :param dataset: dataset from which to load the minibatch.
:type sampler: Sampler
:param sampler: defines the strategy to sample data from the dataset. :param sampler: defines the strategy to sample data from the dataset.
:type transform: Transform
:param transform: defined the transforming strategy for a sampled batch. :param transform: defined the transforming strategy for a sampled batch.
Default: None Default: None
:type collator: Collator
:param collator: defined the merging strategy for a transformed batch. :param collator: defined the merging strategy for a transformed batch.
Default: None Default: None
:type num_workers: int
:param num_workers: the number of sub-process to load, transform and collate :param num_workers: the number of sub-process to load, transform and collate
the batch. ``0`` means using single-process. Default: 0 the batch. ``0`` means using single-process. Default: 0
:type timeout: int
:param timeout: if positive, means the timeout value(second) for collecting a :param timeout: if positive, means the timeout value(second) for collecting a
batch from workers. Default: 0 batch from workers. Default: 0
:type timeout_event: Callable
:param timeout_event: callback function triggered by timeout, default to raise :param timeout_event: callback function triggered by timeout, default to raise
runtime error. runtime error.
:type divide: bool
:param divide: define the paralleling strategy in multi-processing mode. :param divide: define the paralleling strategy in multi-processing mode.
``True`` means one batch is divided into :attr:`num_workers` pieces, and ``True`` means one batch is divided into :attr:`num_workers` pieces, and
the workers will process these pieces parallelly. ``False`` means the workers will process these pieces parallelly. ``False`` means
different sub-process will process different batch. Default: False different sub-process will process different batch. Default: False
""" """
__initialized = False
def __init__(
self,
dataset: Dataset,
sampler: Sampler = None,
transform: Transform = None,
collator: Collator = None,
num_workers: int = 0,
timeout: int = 0,
timeout_event: Callable = raise_timeout_error,
divide: bool = False,
):
if num_workers < 0: if num_workers < 0:
raise ValueError("num_workers should not be negative") raise ValueError("num_workers should not be negative")
......
...@@ -30,22 +30,15 @@ class MapSampler(Sampler): ...@@ -30,22 +30,15 @@ class MapSampler(Sampler):
r""" r"""
Sampler for map dataset. Sampler for map dataset.
:type dataset: `dataset`
:param dataset: dataset to sample from. :param dataset: dataset to sample from.
:type batch_size: positive integer
:param batch_size: batch size for batch method. :param batch_size: batch size for batch method.
:type drop_last: bool
:param drop_last: set ``True`` to drop the last incomplete batch, :param drop_last: set ``True`` to drop the last incomplete batch,
if the dataset size is not divisible by the batch size. If ``False`` and if the dataset size is not divisible by the batch size. If ``False`` and
the size of dataset is not divisible by the batch_size, then the last batch will the size of dataset is not divisible by the batch_size, then the last batch will
be smaller. Default: False be smaller. Default: False
:type num_samples: positive integer
:param num_samples: number of samples assigned to one rank. :param num_samples: number of samples assigned to one rank.
:type world_size: positive integer
:param world_size: number of ranks. :param world_size: number of ranks.
:type rank: non-negative integer within 0 and world_size
:param rank: rank id, non-negative interger within 0 and ``world_size``. :param rank: rank id, non-negative interger within 0 and ``world_size``.
:type seed: non-negative integer
:param seed: seed for random operators. :param seed: seed for random operators.
""" """
...@@ -166,7 +159,7 @@ class StreamSampler(Sampler): ...@@ -166,7 +159,7 @@ class StreamSampler(Sampler):
different data. But this class cannot do it yet, please build your own different data. But this class cannot do it yet, please build your own
dataset and sampler to achieve this goal. dataset and sampler to achieve this goal.
Usually, meth::`~.StreamDataset.__iter__` can return different iterator by Usually, :meth:`~.StreamDataset.__iter__` can return different iterator by
``rank = dist.get_rank()``. So that they will get different data. ``rank = dist.get_rank()``. So that they will get different data.
""" """
...@@ -184,6 +177,16 @@ class StreamSampler(Sampler): ...@@ -184,6 +177,16 @@ class StreamSampler(Sampler):
class SequentialSampler(MapSampler): class SequentialSampler(MapSampler):
r""" r"""
Sample elements sequentially. Sample elements sequentially.
:param dataset: dataset to sample from.
:param batch_size: batch size for batch method.
:param drop_last: set ``True`` to drop the last incomplete batch,
if the dataset size is not divisible by the batch size. If ``False`` and
the size of dataset is not divisible by the batch_size, then the last batch will
be smaller. Default: False
:param indices: indice of samples.
:param world_size: number of ranks.
:param rank: rank id, non-negative interger within 0 and ``world_size``.
""" """
def __init__( def __init__(
...@@ -216,6 +219,17 @@ class SequentialSampler(MapSampler): ...@@ -216,6 +219,17 @@ class SequentialSampler(MapSampler):
class RandomSampler(MapSampler): class RandomSampler(MapSampler):
r""" r"""
Sample elements randomly without replacement. Sample elements randomly without replacement.
:param dataset: dataset to sample from.
:param batch_size: batch size for batch method.
:param drop_last: set ``True`` to drop the last incomplete batch,
if the dataset size is not divisible by the batch size. If ``False`` and
the size of dataset is not divisible by the batch_size, then the last batch will
be smaller. Default: False
:param indices: indice of samples.
:param world_size: number of ranks.
:param rank: rank id, non-negative interger within 0 and ``world_size``.
:param seed: seed for random operators.
""" """
def __init__( def __init__(
...@@ -247,8 +261,17 @@ class ReplacementSampler(MapSampler): ...@@ -247,8 +261,17 @@ class ReplacementSampler(MapSampler):
r""" r"""
Sample elements randomly with replacement. Sample elements randomly with replacement.
:type weights: List :param dataset: dataset to sample from.
:param batch_size: batch size for batch method.
:param drop_last: set ``True`` to drop the last incomplete batch,
if the dataset size is not divisible by the batch size. If ``False`` and
the size of dataset is not divisible by the batch_size, then the last batch will
be smaller. Default: False
:param num_samples: number of samples assigned to one rank.
:param weights: weights for sampling indices, it could be unnormalized weights. :param weights: weights for sampling indices, it could be unnormalized weights.
:param world_size: number of ranks.
:param rank: rank id, non-negative interger within 0 and ``world_size``.
:param seed: seed for random operators.
""" """
def __init__( def __init__(
......
...@@ -224,7 +224,7 @@ def nms( ...@@ -224,7 +224,7 @@ def nms(
:param scores: tensor of shape `(N,)`, the score of boxes. :param scores: tensor of shape `(N,)`, the score of boxes.
:param max_output: the maximum number of boxes to keep; it is optional if this operator is not traced :param max_output: the maximum number of boxes to keep; it is optional if this operator is not traced
otherwise it required to be specified; if it is not specified, all boxes are kept. otherwise it required to be specified; if it is not specified, all boxes are kept.
:return: indices of the elements that have been kept by NMS. :return: indices of the elements that have been kept by NMS, sorted by scores.
Examples: Examples:
......
...@@ -409,7 +409,7 @@ class Conv3d(_ConvNd): ...@@ -409,7 +409,7 @@ class Conv3d(_ConvNd):
For instance, given an input of the size :math:`(N, C_{\text{in}}, T, H, W)`, For instance, given an input of the size :math:`(N, C_{\text{in}}, T, H, W)`,
this layer generates an output of the size this layer generates an output of the size
:math:`(N, C_{\text{out}}, T_{\text{out}}}, H_{\text{out}}}, W_{\text{out}}})` through the :math:`(N, C_{\text{out}}, T_{\text{out}}, H_{\text{out}}, W_{\text{out}})` through the
process described as below: process described as below:
.. math:: .. math::
......
...@@ -174,7 +174,7 @@ class Tensor(_Tensor, ArrayMethodMixin): ...@@ -174,7 +174,7 @@ class Tensor(_Tensor, ArrayMethodMixin):
def set_value(self, value): def set_value(self, value):
self._reset(value) self._reset(value)
@deprecated(version="1.0", reason="use *= 0 instead") @deprecated(version="1.0", reason="use ``*= 0`` instead")
def reset_zero(self): def reset_zero(self):
self *= 0 self *= 0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册