Skip to content

Commit e87693b

Browse files
authored
Add defaults to the docstrings for algorithms (#662)
1 parent d98ef84 commit e87693b

File tree

20 files changed

+165
-145
lines changed

20 files changed

+165
-145
lines changed

composer/algorithms/alibi/alibi.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ def apply_alibi(
8080
necessary for evaluating on sequence lengths longer than the model was
8181
initialized to accommodate. Takes positional arguments ``module`` and
8282
``max_sequence_length``. For example,
83-
``composer.algorithms.alibi._gpt2_alibi.enlarge_mask``. Default = ``None``,
83+
``composer.algorithms.alibi._gpt2_alibi.enlarge_mask``. Default: ``None``,
8484
which means no modification of the model's default attention mask.
8585
optimizers (Optimizers, optional): Existing optimizers bound to ``model.parameters()``.
8686
All optimizers that have already been constructed with
8787
``model.parameters()`` must be specified here so they will optimize
88-
the correct parameters.
88+
the correct parameters. Default: ``None``.
8989
9090
If the optimizer(s) are constructed *after* calling this function,
9191
then it is safe to omit this parameter. These optimizers will see the correct
@@ -182,12 +182,12 @@ class Alibi(Algorithm):
182182
max_sequence_length (int): Maximum sequence length that the
183183
model will be able to accept. This is sometimes necessary for evaluating
184184
on sequence lengths longer than the model was initialized to
185-
accommodate.
185+
accommodate. Default: ``8192``.
186186
train_sequence_length_scaling (float, optional): Amount by which to scale
187187
training sequence length. One batch of training data will be
188188
reshaped from shape :math:`(sequence\\_length, batch)` to
189189
:math:`(sequence\\_length \\times train\\_sequence\\_length\\_scaling,
190-
\\frac{batch}{train\\_sequence\\_length\\_scaling})`. Default = ``0.25``.
190+
\\frac{batch}{train\\_sequence\\_length\\_scaling})`. Default: ``0.25``.
191191
"""
192192

193193
def __init__(self,

composer/algorithms/augmix/augmix.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def augmix_image(img: ImgT,
3232
augmentation_set: List = augmentation_sets["all"]) -> ImgT:
3333
"""Applies AugMix (`Hendrycks et al, 2020 <http://arxiv.org/abs/1912.02781>`_) data
3434
augmentation to a single image or batch of images. See
35-
:class:`~composer.algorithms.augmix.augmix.AugMix` and the
35+
:class:`.AugMix` and the
3636
:doc:`Method Card </method_cards/augmix>` for details. This function only acts on a
3737
single image (or batch) per call and is unlikely to be used in a training loop. Use
3838
:class:`~composer.algorithms.augmix.augmix.AugmentAndMixTransform` to use AugMix as
@@ -56,12 +56,12 @@ def augmix_image(img: ImgT,
5656
5757
Args:
5858
img (PIL.Image): Image or batch of images to be AugMix'd.
59-
severity (int, optional): See :class:`~composer.algorithms.augmix.augmix.AugMix`.
60-
depth (int, optional): See :class:`~composer.algorithms.augmix.augmix.AugMix`.
61-
width (int, optional): See :class:`~composer.algorithms.augmix.augmix.AugMix`.
62-
alpha (float, optional): See :class:`~composer.algorithms.augmix.augmix.AugMix`.
59+
severity (int, optional): See :class:`.AugMix`.
60+
depth (int, optional): See :class:`.AugMix`.
61+
width (int, optional): See :class:`.AugMix`.
62+
alpha (float, optional): See :class:`.AugMix`.
6363
augmentation_set (str, optional): See
64-
:class:`~composer.algorithms.augmix.augmix.AugMix`.
64+
:class:`.AugMix`.
6565
6666
Returns:
6767
PIL.Image: AugMix'd image.
@@ -102,7 +102,7 @@ def _augmix_pil_image(img_pil: PillowImage, severity: int, depth: int, width: in
102102
class AugmentAndMixTransform(torch.nn.Module):
103103
"""Wrapper module for :func:`~composer.algorithms.augmix.augmix.augmix_image` that can
104104
be passed to :class:`torchvision.transforms.Compose`. See
105-
:class:`~composer.algorithms.augmix.augmix.AugMix` and the :doc:`Method Card
105+
:class:`.AugMix` and the :doc:`Method Card
106106
</method_cards/augmix>` for details.
107107
108108
Example:
@@ -123,12 +123,12 @@ class AugmentAndMixTransform(torch.nn.Module):
123123
transformed_image = composed(image)
124124
125125
Args:
126-
severity (int, optional): See :class:`~composer.algorithms.augmix.augmix.AugMix`.
127-
depth (int, optional): See :class:`~composer.algorithms.augmix.augmix.AugMix`.
128-
width (int, optional): See :class:`~composer.algorithms.augmix.augmix.AugMix`.
129-
alpha (float, optional): See :class:`~composer.algorithms.augmix.augmix.AugMix`.
126+
severity (int, optional): See :class:`.AugMix`.
127+
depth (int, optional): See :class:`.AugMix`.
128+
width (int, optional): See :class:`.AugMix`.
129+
alpha (float, optional): See :class:`.AugMix`.
130130
augmentation_set (str, optional): See
131-
:class:`~composer.algorithms.augmix.augmix.AugMix`.
131+
:class:`.AugMix`.
132132
"""
133133

134134
def __init__(self,
@@ -167,8 +167,8 @@ class AugMix(Algorithm):
167167
``Dirichlet(alpha, alpha, ...)`` distribution. The coefficient for mixing the combined augmented image and the
168168
original image is drawn from a ``Beta(alpha, alpha)`` distribution, using the same ``alpha``.
169169
170-
This algorithm runs on on :attr:`~composer.core.event.Event.FIT_START` to insert a dataset transformation. It is a no-op if this algorithm already
171-
applied itself on the :attr:`State.train_dataloader.dataset`.
170+
This algorithm runs on on :attr:`~composer.core.event.Event.FIT_START` to insert a dataset transformation.
171+
It is a no-op if this algorithm already applied itself on the :attr:`State.train_dataloader.dataset`.
172172
173173
See the :doc:`Method Card </method_cards/augmix>` for more details.
174174
@@ -196,14 +196,14 @@ class AugMix(Algorithm):
196196
197197
Args:
198198
severity (int, optional): Severity of augmentations; ranges from 0
199-
(no augmentation) to 10 (most severe). Default = ``3``.
199+
(no augmentation) to 10 (most severe). Default: ``3``.
200200
depth (int, optional): Number of augmentations per sequence. -1 enables stochastic
201-
depth sampled uniformly from [1, 3]. Default = ``-1``.
202-
width (int, optional): Number of augmentation sequences. Default = ``3``.
201+
depth sampled uniformly from [1, 3]. Default: ``-1``.
202+
width (int, optional): Number of augmentation sequences. Default: ``3``.
203203
alpha (float, optional): Pseudocount for Beta and Dirichlet distributions. Must be
204204
> 0. Higher values yield mixing coefficients closer to uniform weighting. As
205205
the value approaches 0, the mixing coefficients approach using only one
206-
version of each image. Default = ``1.0``.
206+
version of each image. Default: ``1.0``.
207207
augmentation_set (str, optional): Must be one of the following options:
208208
209209
* ``"augmentations_all"``
@@ -225,7 +225,7 @@ class AugMix(Algorithm):
225225
"sharpness", and "brightness" that account for diverging effects around 0
226226
(or 1).
227227
228-
Default = ``"all"``.
228+
Default: ``"all"``.
229229
"""
230230

231231
# TODO document each value of augmentation_set in more detail; i.e.,

composer/algorithms/blurpool/blurpool.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ def apply_blurpool(model: torch.nn.Module,
3131
Args:
3232
model (torch.nn.Module): the model to modify in-place
3333
replace_convs (bool, optional): replace strided :class:`torch.nn.Conv2d` modules with
34-
:class:`.BlurConv2d` modules
34+
:class:`.BlurConv2d` modules. Default: ``True``.
3535
replace_maxpools (bool, optional): replace eligible :class:`torch.nn.MaxPool2d` modules
36-
with :class:`.BlurMaxPool2d` modules.
36+
with :class:`.BlurMaxPool2d` modules. Default: ``True``.
3737
blur_first (bool, optional): for ``replace_convs``, blur input before the associated
3838
convolution. When set to ``False``, the convolution is applied with
3939
a stride of 1 before the blurring, resulting in significant
4040
overhead (though more closely matching
4141
`the paper <http://proceedings.mlr.press/v97/zhang19a.html>`_).
42-
See :class:`.BlurConv2d` for further discussion.
42+
See :class:`.BlurConv2d` for further discussion. Default: ``True``.
4343
optimizers (Optimizers, optional): Existing optimizers bound to
4444
``model.parameters()``. All optimizers that have already been
4545
constructed with ``model.parameters()`` must be specified here so
@@ -82,14 +82,14 @@ class BlurPool(Algorithm):
8282
8383
Args:
8484
replace_convs (bool): replace strided :class:`torch.nn.Conv2d` modules with
85-
:class:`.BlurConv2d` modules
85+
:class:`.BlurConv2d` modules. Default: ``True``.
8686
replace_maxpools (bool): replace eligible :class:`torch.nn.MaxPool2d` modules
87-
with :class:`.BlurMaxPool2d` modules.
87+
with :class:`.BlurMaxPool2d` modules. Default: ``True``.
8888
blur_first (bool): when ``replace_convs`` is ``True``, blur input before the
8989
associated convolution. When set to ``False``, the convolution is
9090
applied with a stride of 1 before the blurring, resulting in
9191
significant overhead (though more closely matching the paper).
92-
See :class:`.BlurConv2d` for further discussion.
92+
See :class:`.BlurConv2d` for further discussion. Default: ``True``.
9393
"""
9494

9595
def __init__(self, replace_convs: bool, replace_maxpools: bool, blur_first: bool) -> None:

composer/algorithms/colout/colout.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def colout_batch(X: ImgT, p_row: float = 0.15, p_col: float = 0.15) -> ImgT:
4545
X: :class:`PIL.Image.Image` or :class:`torch.Tensor` of image data. In
4646
the latter case, must be a single image of shape ``CHW`` or a batch
4747
of images of shape ``NCHW``.
48-
p_row: Fraction of rows to drop (drop along H).
49-
p_col: Fraction of columns to drop (drop along W).
48+
p_row: Fraction of rows to drop (drop along H). Default: ``0.15``.
49+
p_col: Fraction of columns to drop (drop along W). Default: ``0.15``.
5050
5151
Returns:
5252
torch.Tensor: Input batch tensor with randomly dropped columns and rows.
@@ -94,8 +94,8 @@ class ColOutTransform:
9494
transforms = transforms.Compose([colout_transform, transforms.ToTensor()])
9595
9696
Args:
97-
p_row (float): Fraction of rows to drop (drop along H).
98-
p_col (float): Fraction of columns to drop (drop along W).
97+
p_row (float): Fraction of rows to drop (drop along H). Default: ``0.15``.
98+
p_col (float): Fraction of columns to drop (drop along W). Default: ``0.15``.
9999
"""
100100

101101
def __init__(self, p_row: float = 0.15, p_col: float = 0.15):
@@ -142,9 +142,9 @@ class ColOut(Algorithm):
142142
)
143143
144144
Args:
145-
p_row (float): Fraction of rows to drop (drop along H).
146-
p_col (float): Fraction of columns to drop (drop along W).
147-
batch (bool): Run ColOut at the batch level.
145+
p_row (float): Fraction of rows to drop (drop along H). Default: ``0.15``.
146+
p_col (float): Fraction of columns to drop (drop along W). Default: ``0.15``.
147+
batch (bool): Run ColOut at the batch level. Default: ``True``.
148148
"""
149149

150150
def __init__(self, p_row: float = 0.15, p_col: float = 0.15, batch: bool = True):

composer/algorithms/cutmix/cutmix.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ def cutmix_batch(X: Tensor,
5151
)
5252
5353
Args:
54-
X: input tensor of shape (B, d1, d2, ..., dn), B is batch size, d1-dn
54+
X (Tensor): input tensor of shape (B, d1, d2, ..., dn), B is batch size, d1-dn
5555
are feature dimensions.
56-
y: target tensor of shape (B, f1, f2, ..., fm), B is batch size, f1-fn
56+
y (Tensor): target tensor of shape (B, f1, f2, ..., fm), B is batch size, f1-fn
5757
are possible target dimensions.
58-
n_classes: total number of classes.
59-
alpha: parameter for the beta distribution of the cutmix region size.
60-
cutmix_lambda: optional, fixed size of cutmix region.
61-
bbox: optional, predetermined (rx1, ry1, rx2, ry2) coords of the bounding box.
62-
indices: Permutation of the batch indices `1..B`. Used
63-
for permuting without randomness.
58+
n_classes (int): total number of classes.
59+
alpha (float, optional): parameter for the beta distribution of the cutmix region size. Default: ``1``.
60+
cutmix_lambda (float, optional): fixed size of cutmix region. Default: ``None``.
61+
bbox (tuple, optional): predetermined (rx1, ry1, rx2, ry2) coords of the bounding box. Default: ``None``.
62+
indices (Tensor, optional): Permutation of the batch indices `1..B`. Used
63+
for permuting without randomness. Default: ``None``.
6464
6565
Returns:
6666
X_cutmix: batch of inputs after cutmix has been applied.
@@ -132,11 +132,11 @@ class CutMix(Algorithm):
132132
133133
Args:
134134
num_classes (int): the number of classes in the task labels.
135-
alpha (float): the psuedocount for the Beta distribution used to sample
135+
alpha (float, optional): the psuedocount for the Beta distribution used to sample
136136
area parameters. As ``alpha`` grows, the two samples
137137
in each pair tend to be weighted more equally. As ``alpha``
138138
approaches 0 from above, the combination approaches only using
139-
one element of the pair.
139+
one element of the pair. Default: ``1``.
140140
"""
141141

142142
def __init__(self, num_classes: int, alpha: float = 1.):

composer/algorithms/cutout/cutout.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ def cutout_batch(X: ImgT, n_holes: int = 1, length: Union[int, float] = 0.5) ->
3838
X: :class:`PIL.Image.Image` or :class:`torch.Tensor` of image data. In
3939
the latter case, must be a single image of shape ``CHW`` or a batch
4040
of images of shape ``NCHW``.
41-
n_holes: Integer number of holes to cut out
41+
n_holes: Integer number of holes to cut out. Default: ``1``.
4242
length: Side length of the square holes to cut out. Must be greater than
4343
0. If ``0 < length < 1``, ``length`` is interpreted as a fraction
4444
of ``min(H, W)`` and converted to ``int(length * min(H, W))``.
4545
If ``length >= 1``, ``length`` is used as an integer size directly.
46+
Default: ``0.5``.
4647
4748
Returns:
4849
X_cutout: Batch of images with ``n_holes`` holes of dimension
@@ -91,11 +92,12 @@ class CutOut(Algorithm):
9192
9293
Args:
9394
X (Tensor): Batch Tensor image of size (B, C, H, W).
94-
n_holes: Integer number of holes to cut out
95+
n_holes: Integer number of holes to cut out. Default: ``1``.
9596
length: Side length of the square holes to cut out. Must be greater than
9697
0. If ``0 < length < 1``, ``length`` is interpreted as a fraction
9798
of ``min(H, W)`` and converted to ``int(length * min(H, W))``.
9899
If ``length >= 1``, ``length`` is used as an integer size directly.
100+
Default: ``0.5``.
99101
"""
100102

101103
def __init__(self, n_holes: int = 1, length: Union[int, float] = 0.5):

composer/algorithms/factorize/factorize.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,29 @@ def apply_factorization(model: torch.nn.Module,
3838
Args:
3939
model (torch.nn.Module): the model to modify in-place
4040
factorize_convs (bool, optional): whether to try factorizing :class:`~torch.nn.Conv2d` modules.
41+
Default: ``True``.
4142
factorize_linears (bool, optional): whether to try factorizing :class:`~torch.nn.Linear` modules.
43+
Default: ``True``.
4244
min_channels (int, optional): if a :class:`~torch.nn.Conv2d` module does not have at least
4345
this many input and output channels, it will be ignored. Modules with
4446
few channels are unlikely to be accelerated by factorization due
45-
to poor hardware utilization.
47+
to poor hardware utilization. Default: ``512``.
4648
latent_channels (int or float, optional): number of latent channels to use in factorized
4749
convolutions. Can be specified as either an integer > 1 or as
4850
float within [0, 1). In the latter case, the value is
4951
interpreted as a fraction of ``min(in_channels, out_channels)``
5052
for each :class:`~torch.nn.Conv2d` module, and is converted to
51-
the equivalent integer value, with a minimum of 1.
53+
the equivalent integer value, with a minimum of 1. Default: ``0.25``.
5254
min_features (int, optional): if a :class:`~torch.nn.Linear` module does not have at least
5355
this many input and output features, it will be ignored. Modules with
5456
few features are unlikely to be accelerated by factorization due
55-
to poor hardware utilization.
57+
to poor hardware utilization. Default: ``512``.
5658
latent_features (int or float, optional): size of the latent space for factorized linear modules.
5759
Can be specified as either an integer > 1 or as a float within [0, 0.5).
5860
In the latter case, the value is interpreted as a fraction of
5961
``min(in_features, out_features)`` for each :class:`~torch.nn.Linear`
6062
module, and is converted to the equivalent integer value, with a
61-
minimum of 1.
63+
minimum of 1. Default: ``0.25``.
6264
optimizers (Optimizers, optional): Existing optimizers bound to
6365
``model.parameters()``. All optimizers that have already been
6466
constructed with ``model.parameters()`` must be specified here so
@@ -123,27 +125,29 @@ class Factorize(Algorithm):
123125
124126
Args:
125127
factorize_convs (bool): whether to try factorizing :class:`~torch.nn.Conv2d` modules.
128+
Default: ``True``.
126129
factorize_linears (bool): whether to try factorizing :class:`~torch.nn.Linear` modules.
130+
Default: ``True``.
127131
min_channels (int): if a :class:`~torch.nn.Conv2d` module does not have at least
128132
this many input and output channels, it will be ignored. Modules with
129133
few channels are unlikely to be accelerated by factorization due
130-
to poor hardware utilization.
134+
to poor hardware utilization. Default: ``256``.
131135
latent_channels (int, float): number of latent channels to use in factorized
132136
convolutions. Can be specified as either an integer > 1 or as
133137
float within [0, 1). In the latter case, the value is
134138
interpreted as a fraction of ``min(in_channels, out_channels)``
135139
for each :class:`~torch.nn.Conv2d` module, and is converted to
136-
the equivalent integer value, with a minimum of 1.
140+
the equivalent integer value, with a minimum of 1. Default: ``0.25``.
137141
min_features (int): if a :class:`~torch.nn.Linear` module does not have at least
138142
this many input and output features, it will be ignored. Modules with
139143
few features are unlikely to be accelerated by factorization due
140-
to poor hardware utilization.
144+
to poor hardware utilization. Default: ``256``.
141145
latent_features (int, float): size of the latent space for factorized linear modules.
142146
Can be specified as either an integer > 1 or as a float within [0, 0.5).
143147
In the latter case, the value is interpreted as a fraction of
144148
``min(in_features, out_features)`` for each :class:`~torch.nn.Linear`
145149
module, and is converted to the equivalent integer value, with a
146-
minimum of 1.
150+
minimum of 1. Default: ``128``.
147151
"""
148152

149153
def __init__(self,

0 commit comments

Comments
 (0)