mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
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: https://github.com/pytorch/pytorch/pull/49736
Reviewed By: albanD
Differential Revision: D25710534
Pulled By: soumith
fbshipit-source-id: 61e8ff01abb433e9f78185c2d1d0cbd7c22c1619
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
|
|
|
|
|
|
|
|
|
|
from caffe2.python import schema
|
|
from caffe2.python.layers.layers import (
|
|
get_categorical_limit,
|
|
ModelLayer,
|
|
IdList
|
|
)
|
|
|
|
import numpy as np
|
|
|
|
|
|
class MergeIdLists(ModelLayer):
|
|
"""Merge multiple ID_LISTs into a single ID_LIST
|
|
|
|
Args:
|
|
model: A layer model instance
|
|
input_record: Tuple (Struct) of ID_LIST features to be
|
|
merged
|
|
|
|
Returns:
|
|
the merged ID_LIST feature
|
|
"""
|
|
def __init__(self, model, input_record, name='merged'):
|
|
super(MergeIdLists, self).__init__(model, name, input_record)
|
|
assert all(schema.equal_schemas(x, IdList) for x in input_record), \
|
|
"Inputs to MergeIdLists should all be IdLists."
|
|
|
|
assert all(record.items.metadata is not None
|
|
for record in self.input_record), \
|
|
"Features without metadata are not supported"
|
|
|
|
merge_dim = max(get_categorical_limit(record)
|
|
for record in self.input_record)
|
|
assert merge_dim is not None, "Unbounded features are not supported"
|
|
|
|
self.output_schema = schema.NewRecord(
|
|
model.net, schema.List(
|
|
schema.Scalar(
|
|
np.int64,
|
|
blob=model.net.NextBlob(name),
|
|
metadata=schema.Metadata(categorical_limit=merge_dim)
|
|
)))
|
|
|
|
def add_ops(self, net):
|
|
return net.MergeIdLists(self.input_record.field_blobs(),
|
|
self.output_schema.field_blobs())
|