Skip to content

Commit e6779d4

Browse files
SamuelMarksfacebook-github-bot
authored andcommitted
[*.py] Rename "Arguments:" to "Args:" (pytorch#49736)
Summary: I've written custom parsers and emitters for everything from docstrings to classes and functions. However, I recently came across an issue when I was parsing/generating from the TensorFlow codebase: inconsistent use of `Args:` and `Arguments:` in its docstrings. ```sh (pytorch#c348fae)$ for name in 'Args:' 'Arguments:'; do printf '%-10s %04d\n' "$name" "$(rg -IFtpy --count-matches "$name" | paste -s -d+ -- | bc)"; done Args: 1095 Arguments: 0336 ``` It is easy enough to extend my parsers to support both variants, however it looks like `Arguments:` is wrong anyway, as per: - https://google.github.io/styleguide/pyguide.html#doc-function-args @ [`ddccc0f`](https://github.com/google/styleguide/blob/ddccc0f/pyguide.md) - https://chromium.googlesource.com/chromiumos/docs/+/master/styleguide/python.md#describing-arguments-in-docstrings @ [`9fc0fc0`](https://chromium.googlesource.com/chromiumos/docs/+/9fc0fc0/styleguide/python.md) - https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html @ [`c0ae8e3`](https://github.com/sphinx-contrib/napoleon/blob/c0ae8e3/docs/source/example_google.rst) Therefore, only `Args:` is valid. This PR replaces them throughout the codebase. PS: For related PRs, see tensorflow/tensorflow/pull/45420 PPS: The trackbacks automatically appearing below are sending the same changes to other repositories in the [PyTorch](https://github.com/pytorch) organisation. Pull Request resolved: pytorch#49736 Reviewed By: albanD Differential Revision: D25710534 Pulled By: soumith fbshipit-source-id: 61e8ff01abb433e9f78185c2d1d0cbd7c22c1619
1 parent 9c64b9f commit e6779d4

File tree

102 files changed

+311
-311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+311
-311
lines changed

benchmarks/functional_autograd_benchmark/torchvision_models.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class IntermediateLayerGetter(nn.ModuleDict):
247247
Additionally, it is only able to query submodules that are directly
248248
assigned to the model. So if `model` is passed, `model.feature1` can
249249
be returned, but not `model.feature1.layer2`.
250-
Arguments:
250+
Args:
251251
model (nn.Module): model on which we will extract the features
252252
return_layers (Dict[name, new_name]): a dict containing the names
253253
of the modules for which the activations will be returned as
@@ -324,7 +324,7 @@ def forward(self, x):
324324
class FCN(_SimpleSegmentationModel):
325325
"""
326326
Implements a Fully-Convolutional Network for semantic segmentation.
327-
Arguments:
327+
Args:
328328
backbone (nn.Module): the network used to compute the features for the model.
329329
The backbone should return an OrderedDict[Tensor], with the key being
330330
"out" for the last feature map used, and "aux" if an auxiliary classifier
@@ -509,7 +509,7 @@ def box_area(boxes):
509509
"""
510510
Computes the area of a set of bounding boxes, which are specified by its
511511
(x1, y1, x2, y2) coordinates.
512-
Arguments:
512+
Args:
513513
boxes (Tensor[N, 4]): boxes for which the area will be computed. They
514514
are expected to be in (x1, y1, x2, y2) format
515515
Returns:

caffe2/python/data_parallel_model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ def sumN(*dev_indices):
10561056
"""Create a Sum op for 2 or more blobs on different devices.
10571057
Saves the result on the first device.
10581058
1059-
Arguments:
1059+
Args:
10601060
dev_indices -- a list of device indices, which can be translated into
10611061
CUDA identifiers with model._devices
10621062
"""

caffe2/python/layers/merge_id_lists.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class MergeIdLists(ModelLayer):
1717
"""Merge multiple ID_LISTs into a single ID_LIST
1818
19-
Arguments:
19+
Args:
2020
model: A layer model instance
2121
input_record: Tuple (Struct) of ID_LIST features to be
2222
merged

caffe2/python/net_builder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class NetBuilder(context.Managed):
1414
"""
1515
Scope-driven mechanism for building nets, loops and conditional blocks.
16-
Arguments:
16+
Args:
1717
name: NetBuilder's name
1818
initial_scope: list of blobs that are available for reading/writing
1919
Example:

docs/source/onnx.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ but intuitively the interface they provide looks like this::
755755
ONNX outputs whose values correspond to the original PyTorch return values
756756
of the autograd Function (or None if an output is not supported by ONNX).
757757

758-
Arguments:
758+
Args:
759759
g (Graph): graph to write the ONNX representation into
760760
inputs (Value...): list of values representing the variables which contain
761761
the inputs for this function
@@ -782,7 +782,7 @@ but intuitively the interface they provide looks like this::
782782
The set of operators and the inputs/attributes they take
783783
is documented at https://github.com/onnx/onnx/blob/master/docs/Operators.md
784784

785-
Arguments:
785+
Args:
786786
opname (string): The ONNX operator name, e.g., `Abs` or `Add`.
787787
args (Value...): The inputs to the operator; usually provided
788788
as arguments to the `symbolic` definition.

test/onnx/pytorch_helper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def PyTorchModule(helper, model, sample_arguments, caffe2_inputs, prefix_name=No
2323
"""
2424
Embed an ONNX-exportable PyTorch Model into a Caffe2 model being built.
2525
26-
Arguments:
26+
Args:
2727
helper (caffe2.python.core.ModelHelder): the model helper where
2828
this imported network should be inserted
2929
model (torch.nn.Module): the model to be exported

test/onnx/verify.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def verify(model, args, backend, verbose=False, training=torch.onnx.TrainingMode
246246
For reproducibility, we recommend explicitly setting PyTorch's seed before
247247
invoking this function.
248248
249-
Arguments:
249+
Args:
250250
model (torch.nn.Module): the model to be exported and verified
251251
args (tuple of arguments): the inputs to
252252
the model, e.g., such that ``model(*args)`` is a valid

test/run_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ def find_test_index(test, selected_tests, find_last_index=False):
617617
If :attr:`test`='torch' and :attr:`find_last_index`=False, result should be **2**.
618618
If :attr:`test`='torch' and :attr:`find_last_index`=True, result should be **4**.
619619
620-
Arguments:
620+
Args:
621621
test (str): Name of test to lookup
622622
selected_tests (list): List of tests
623623
find_last_index (bool, optional): should we lookup the index of first or last

tools/setup_helpers/cmake.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def _mkdir_p(d):
3232
def convert_cmake_value_to_python_value(cmake_value, cmake_type):
3333
r"""Convert a CMake value in a string form to a Python value.
3434
35-
Arguments:
35+
Args:
3636
cmake_value (string): The CMake value in a string form (e.g., "ON", "OFF", "1").
3737
cmake_type (string): The CMake type of :attr:`cmake_value`.
3838
@@ -56,7 +56,7 @@ def convert_cmake_value_to_python_value(cmake_value, cmake_type):
5656
def get_cmake_cache_variables_from_file(cmake_cache_file):
5757
r"""Gets values in CMakeCache.txt into a dictionary.
5858
59-
Arguments:
59+
Args:
6060
cmake_cache_file: A CMakeCache.txt file object.
6161
Returns:
6262
dict: A ``dict`` containing the value of cached CMake variables.

tools/setup_helpers/env.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class BuildType(object):
4343
is ``None``, then the build type will be inferred from ``CMakeCache.txt``. If ``CMakeCache.txt`` does not exist,
4444
os.environ['CMAKE_BUILD_TYPE'] will be used.
4545
46-
Arguments:
46+
Args:
4747
cmake_build_type_env (str): The value of os.environ['CMAKE_BUILD_TYPE']. If None, the actual build type will be
4848
inferred.
4949

torch/_classes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def load_library(self, path):
4040
``torch.classes.loaded_libraries`` attribute, a set that may be inspected
4141
for the paths of all libraries loaded using this function.
4242
43-
Arguments:
43+
Args:
4444
path (str): A path to a shared library to load.
4545
"""
4646
torch.ops.load_library(path)

torch/_jit_internal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def get_type_hint_captures(fn):
254254
for the literal annotations on 'fn'. These are not considered to be closed-over by fn
255255
and must be obtained separately (e.g. using this function).
256256
257-
Arguments:
257+
Args:
258258
fn: A callable.
259259
Returns:
260260
A Dict[str, Any] containing a mapping from the literal annotations used on

torch/_lobpcg.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def _polynomial_value(poly, x, zero_power, transition):
7676
"""
7777
A generic method for computing poly(x) using the Horner's rule.
7878
79-
Arguments:
79+
Args:
8080
poly (Tensor): the (possibly batched) 1D Tensor representing
8181
polynomial coefficients such that
8282
poly[..., i] = (a_{i_0}, ..., a{i_n} (==1)), and
@@ -384,7 +384,7 @@ def lobpcg(A: Tensor,
384384
we do the following symmetrization map: `A -> (A + A.t()) / 2`.
385385
The map is performed only when the `A` requires gradients.
386386
387-
Arguments:
387+
Args:
388388
389389
A (Tensor): the input tensor of size :math:`(*, m, m)`
390390
@@ -925,7 +925,7 @@ def _get_rayleigh_ritz_transform(self, S):
925925
matrix product `D M` with element-wise product `M *
926926
d`. Also, creating the diagonal matrix `D` is avoided.
927927
928-
Arguments:
928+
Args:
929929
S (Tensor): the matrix basis for the search subspace, size is
930930
:math:`(m, n)`.
931931
@@ -957,7 +957,7 @@ def _get_svqb(self,
957957
modification of the corresponding algorithm
958958
introduced in [StathopolousWu2002].
959959
960-
Arguments:
960+
Args:
961961
962962
U (Tensor) : initial approximation, size is (m, n)
963963
drop (bool) : when True, drop columns that
@@ -1023,7 +1023,7 @@ def _get_ortho(self, U, V):
10231023
.. note:: If all U columns are B-collinear to V then the
10241024
returned tensor U will be empty.
10251025
1026-
Arguments:
1026+
Args:
10271027
10281028
U (Tensor) : initial approximation, size is (m, n)
10291029
V (Tensor) : B-orthogonal external basis, size is (m, k)

torch/_lowrank.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def get_approximate_basis(A, # type: Tensor
3737
.. note:: To obtain repeatable results, reset the seed for the
3838
pseudorandom number generator
3939
40-
Arguments::
40+
Args::
4141
A (Tensor): the input tensor of size :math:`(*, m, n)`
4242
4343
q (int): the dimension of subspace spanned by :math:`Q`
@@ -103,7 +103,7 @@ def svd_lowrank(A, q=6, niter=2, M=None):
103103
will be useful for huge sparse matrices that
104104
``torch.svd`` cannot handle.
105105
106-
Arguments::
106+
Args::
107107
A (Tensor): the input tensor of size :math:`(*, m, n)`
108108
109109
q (int, optional): a slightly overestimated rank of A.
@@ -211,7 +211,7 @@ def pca_lowrank(A, q=None, center=True, niter=2):
211211
.. note:: To obtain repeatable results, reset the seed for the
212212
pseudorandom number generator
213213
214-
Arguments:
214+
Args:
215215
216216
A (Tensor): the input tensor of size :math:`(*, m, n)`
217217

torch/_ops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def load_library(self, path):
9494
``torch.ops.loaded_libraries`` attribute, a set that may be inspected
9595
for the paths of all libraries loaded using this function.
9696
97-
Arguments:
97+
Args:
9898
path (str): A path to a shared library to load.
9999
"""
100100
path = torch._utils_internal.resolve_library_path(path)

torch/_torch_docs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3738,7 +3738,7 @@ def merge_dicts(*dicts):
37383738
Complex values are infinite when their real or imaginary part is
37393739
infinite.
37403740
3741-
Arguments:
3741+
Args:
37423742
{input}
37433743
37443744
Returns:
@@ -3823,7 +3823,7 @@ def merge_dicts(*dicts):
38233823
Real values are finite when they are not NaN, negative infinity, or infinity.
38243824
Complex values are finite when both their real and imaginary parts are finite.
38253825
3826-
Arguments:
3826+
Args:
38273827
{input}
38283828
38293829
Returns:

torch/_utils.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def _flatten_dense_tensors(tensors):
248248
buffer. Element-wise operation on this buffer will be equivalent to
249249
operating individually.
250250
251-
Arguments:
251+
Args:
252252
tensors (Iterable[Tensor]): dense tensors to flatten.
253253
254254
Returns:
@@ -264,7 +264,7 @@ def _flatten_sparse_tensors(tensors):
264264
"""Flatten sparse tensors into two contiguous 1D buffers, one of indices and
265265
one of values. Assume tensors are of same sparse type.
266266
267-
Arguments:
267+
Args:
268268
tensors (Iterable[Tensor]): sparse tensors to flatten.
269269
270270
Returns:
@@ -280,7 +280,7 @@ def _unflatten_dense_tensors(flat, tensors):
280280
"""View a flat buffer using the sizes of tensors. Assume that tensors are of
281281
same dense type, and that flat is given by _flatten_dense_tensors.
282282
283-
Arguments:
283+
Args:
284284
flat (Tensor): flattened dense tensors to unflatten.
285285
tensors (Iterable[Tensor]): dense tensors whose sizes will be used to
286286
unflatten flat.
@@ -303,7 +303,7 @@ def _unflatten_sparse_tensors(flat, tensors):
303303
tensors. Assume that tensors are of same sparse type, and that flat is given
304304
by _flatten_sparse_tensors.
305305
306-
Arguments:
306+
Args:
307307
flat (tuple(Tensor, Tensor)): flattened indices and values of sparse
308308
tensors to unflatten.
309309
tensors (Iterable[Tensor]): sparse tensors whose sizes will be used to
@@ -327,7 +327,7 @@ def _reorder_tensors_as(tensors, ordered_tensors):
327327
types, e.g., from _take_tensors. Reorder them to be of same order as
328328
ordered_tensors.
329329
330-
Arguments:
330+
Args:
331331
tensors (Iterable[Tensor]): tensors to be reordered. They should be of
332332
the same order as ordered_tensors within their own types.
333333
ordered_tensors (Iterable[Tensor]): tensors whose order will be the

torch/autograd/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def backward(
102102
in a user-specified CUDA stream context, see
103103
:ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
104104
105-
Arguments:
105+
Args:
106106
tensors (sequence of Tensor): Tensors of which the derivative will be
107107
computed.
108108
grad_tensors (sequence of (Tensor or None)): The "vector" in the Jacobian-vector
@@ -174,7 +174,7 @@ def grad(
174174
in a user-specified CUDA stream context, see
175175
:ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
176176
177-
Arguments:
177+
Args:
178178
outputs (sequence of Tensor): outputs of the differentiated function.
179179
inputs (sequence of Tensor): Inputs w.r.t. which the gradient will be
180180
returned (and not accumulated into ``.grad``).

torch/autograd/anomaly_mode.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class set_detect_anomaly(object):
8989
9090
See ``detect_anomaly`` above for details of the anomaly detection behaviour.
9191
92-
Arguments:
92+
Args:
9393
mode (bool): Flag whether to enable anomaly detection (``True``),
9494
or disable (``False``).
9595

torch/autograd/grad_mode.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class set_grad_enabled(object):
172172
This context manager is thread local; it will not affect computation
173173
in other threads.
174174
175-
Arguments:
175+
Args:
176176
mode (bool): Flag whether to enable grad (``True``), or disable
177177
(``False``). This can be used to conditionally enable
178178
gradients.

torch/autograd/profiler.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def self_cpu_time_total(self):
172172
def table(self, sort_by=None, row_limit=100, max_src_column_width=75, header=None, top_level_events_only=False):
173173
"""Prints an EventList as a nicely formatted table.
174174
175-
Arguments:
175+
Args:
176176
sort_by (str, optional): Attribute used to sort entries. By default
177177
they are printed in the same order as they were registered.
178178
Valid keys include: ``cpu_time``, ``cuda_time``, ``cpu_time_total``,
@@ -203,7 +203,7 @@ def export_chrome_trace(self, path):
203203
204204
The checkpoint can be later loaded and inspected under ``chrome://tracing`` URL.
205205
206-
Arguments:
206+
Args:
207207
path (str): Path where the trace will be written.
208208
"""
209209
import os
@@ -288,7 +288,7 @@ def export_stacks(self, path: str, metric: str):
288288
def key_averages(self, group_by_input_shapes=False, group_by_stack_n=0):
289289
"""Averages all function events over their keys.
290290
291-
Arguments:
291+
Args:
292292
group_by_input_shapes: group entries by
293293
(event name, input shapes) rather than just event name.
294294
This is useful to see which input shapes contribute to the runtime
@@ -345,7 +345,7 @@ class profile(object):
345345
only report runtime of PyTorch functions.
346346
Note: profiler is thread local and is automatically propagated into the async tasks
347347
348-
Arguments:
348+
Args:
349349
enabled (bool, optional): Setting this to False makes this context manager a no-op.
350350
Default: ``True``.
351351
@@ -574,7 +574,7 @@ class record_function(ContextDecorator):
574574
Python code (or function) when running autograd profiler. It is
575575
useful when tracing the code profile.
576576
577-
Arguments:
577+
Args:
578578
name (str): Label assigned to the block of code.
579579
node_id (int): ID of node, for distributed profiling. Unset in
580580
non-distributed cases.
@@ -628,7 +628,7 @@ def _call_end_callbacks_on_future(self, fut: Future[Any]) -> Future[Any]:
628628
once to attach the callback onto the future, and will throw if called multiple
629629
times.
630630
631-
Arguments:
631+
Args:
632632
fut: (torch._C.Future): future for which to schedule
633633
callback for.
634634
@@ -666,7 +666,7 @@ class emit_nvtx(object):
666666
This context manager should not be called recursively, i.e. at most one
667667
instance should be enabled at any given time.
668668
669-
Arguments:
669+
Args:
670670
enabled (bool, optional, default=True): Setting ``enabled=False`` makes this context manager a no-op.
671671
Default: ``True``.
672672
record_shapes (bool, optional, default=False): If ``record_shapes=True``, the nvtx range wrapping
@@ -761,7 +761,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
761761
def load_nvprof(path):
762762
"""Opens an nvprof trace file and parses autograd annotations.
763763
764-
Arguments:
764+
Args:
765765
path (str): path to nvprof trace
766766
"""
767767
return EventList(parse_nvprof_trace(path))

0 commit comments

Comments
 (0)